使用numpy像素数组进行目标检测

时间:2019-02-22 15:59:42

标签: python numpy image-processing raspberry-pi

伙计们,所以对于python项目,我使用pi相机在传送带正下方运行时有物体进来的同时连续拍照。我正在尝试编写一个程序来检测整个通过为每个帧/图像运行一个循环将对象位于相机下方,该循环将顶部像素行与底部像素行进行比较,以查看是否存在差异。如果存在,则输入特定于案例的for循环,以查看现在像素的顶行和底行是否相同。如果它们是,那么我们就知道物体已经完全进入了相机的框架(我们假设物体永远不会大于图片的框架)

所以我的问题是,是否有一种更准确的方式来进行像素检测。我是否应该考虑获取顶行和底行的平均像素值,然后应用某种可接受的差异范围,因为整个图像的照明可能不一致?例如:if(topRowAvg <1.1 * bottomRowAvg和topRowAvg> .9 * bottomRowAvg):?

我敞开心.。下面的代码

def objectDetection()
    objectDetected = false
    # allow the camera to warmup
    time.sleep(0.1)
    # capture frames from the camera
    for frame in camera.capture_continuous(rawCapture, format="bgr", use_video_port=True):
    image = frame.array
     if(objectDetected == true):
        for x in range(width)
            if(np.all(image[x,0]) == np.all(image[x,height])):
                    #unimportant  line of code to resolve
                    return

        for x in range((width-1)):
            if(np.all(image[x,0]) > np.all(image[x,height])):
            objectDetected = true

0 个答案:

没有答案