简体   繁体   English

覆盆子pi picamera-图像比较

[英]raspberry pi picamera - image comparison

Im trying to detect movement in between 2 pictures taken from the raspberry pi picamera. 我试图检测从覆盆子pi picamera拍摄的2张照片之间的运动。 i'm doing this by comparing de raw pixeldata with eachother. 我正在通过比较彼此的原始像素数据来做到这一点。 Below is a simple script which i'm using to test the comparison. 下面是一个我用来测试比较的简单脚本。

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))

In the script i start the camera, take the first picture, wait a few seconds, take the second picture and calculate the difference. 在脚本中,我启动相机,拍摄第一张照片,等待几秒钟,拍摄第二张照片并计算差异。 However evertime i run this script, the "val1" variable is always 0.0. 但是,每当我运行此脚本时,“ val1”变量始终为0.0。 Any help would be appreciated. 任何帮助,将不胜感激。

So with a 2x2 "image", your color value addition 因此,对于2x2的“图像”,您的颜色值会增加

import numpy as np

newImage = np.array([[[0,0,0], [1,0,0]], [[0,1,0], [0,1,1]]])

x = 0
y = 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]
        print(val1)
        y +=1
    x += 1
    y = 0

produces 产生

0
1
1
2

as I would expect. 正如我所期望的。

What result do you expect? 您期望得到什么结果? Is your data OK (provide sample data)? 您的数据可以吗(提供样本数据)?

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM