我目前正致力于图像检测项目,并且某段代码需要捕获视频输出的最后一帧。为了获得最佳结果,我们必须创建一个直方图,绘制所有像素的分配(我已经完成)并将它们平均以获得环境光水平。目前我的代码如下所示:
from PIL import Image
import os
from pylab import *
from PIL import ImageFont
from PIL import ImageDraw
#read image
image1 = array(Image.open("EE_Design_Chimys.jpg").convert('L'))
#plot image
imshow(image1)
#create a new figure
figure()
#dont use colors
gray()
#show contours with origin upper left corner
contour(image1, origin='image')
axis('equal')
axis('off')
figure()
a = hist(image1.flatten(),128)
#attempt to average out histogram
average(a)
show(a)
当我运行此代码时,它会输出如下错误消息:
Traceback (most recent call last):
File "/Users/Perez/Desktop/Python Stuff/mod_amb_light.py", line 25, in <module>
average(a)
File "/Library/Frameworks/Python.framework/Versions/3.5/lib/python3.5/site-packages/numpy/lib/function_base.py", line 935, in average
avg = a.mean(axis)
File "/Library/Frameworks/Python.framework/Versions/3.5/lib/python3.5/site-packages/numpy/core/_methods.py", line 65, in _mean
ret = umr_sum(arr, axis, dtype, out, keepdims)
ValueError: operands could not be broadcast together with shapes (128,) (129,)
我不确定这究竟意味着如何开始解决它。如果有人有任何有用的提示或想法,请分享您的知识!谢谢。
此致 Jaime Perez Jr。