我试图在两张从树莓皮picamera拍摄的照片之间检测运动。我是通过比较原始像素数据来实现的。 下面是我用来测试比较的一个简单脚本。在
import picamera
import datetime
from fractions import Fraction
import time
import numpy as np
oldImage = np.empty((48, 64, 3))
newImage = np.empty((48, 64, 3))
color_offset = 25
with picamera.PiCamera() as camera:
camera.resolution = (64,48)
camera.start_preview()
time.sleep(2)
camera.capture(oldImage, "rgb")
time.sleep(5)
camera.capture(newImage, "rgb")
x = 0
y = 0
diff = 0
while(x < np.size(newImage, 0)):
while(y < np.size(newImage, 1)):
val1 = newImage[x, y, 0] + newImage[x, y, 1] + newImage[x, y, 2]
val2 = oldImage[x, y, 0] + oldImage[x, y, 1] + oldImage[x, y, 2]
print(val1)
print(val2)
pd = abs(val2 - val1)
print(pd)
if(pd > color_offset):
diff += 1
y +=1
x += 1
y=0
print(str(diff))
在脚本中,我启动相机,拍摄第一张照片,等待几秒钟,拍摄第二张照片并计算差值。但是每次我运行这个脚本时,“val1”变量总是0.0。 任何帮助都将不胜感激。在
所以用一个2x2“图像”,你的颜色价值增加
生产
^{pr2}$正如我所料。在
你期待什么结果?你的数据可以吗(提供样本数据)?在
相关问题 更多 >
编程相关推荐