logo

如何通过ROI判断是否有车辆经过

2018-11-26 14:50
Z
zgbh

我使用ROI算法将一个指定的像素框的数据给打印了出来

数据为

100,0,0

100,0,0

0,0,0

0,0,0

0,0,0

我想写一串代码,来判断是否有车辆经过

原理:当有车辆经过像素块的时候,数据的数值应为100,0,0,但是roi这个函数一下子就会打印出很多个来,如何判断多个100,0,0为同一次事件发生所导致的结果呢

I
网红小智智 星瞳科技

什么数据?指定的像素框的数据?

Z
zgbh

@kidswong999 是的

I
网红小智智 星瞳科技

指定的像素框的数据是什么数据?

Z
zgbh

@kidswong999

import sensor, image, time

sensor.reset() # 初始化摄像头
sensor.set_pixformat(sensor.RGB565) # 格式为 RGB565.
sensor.set_framesize(sensor.QVGA)
sensor.skip_frames(10) # 跳过10帧,使新设置生效
sensor.set_auto_whitebal(False)               # Create a clock object to track the FPS.
low_threshold = (0, 50)
high_threshold = (205, 255)
ROI=(200,180,90,30)
ROI1=(111,181,41,34)
colar_l=0
member=0
img = sensor.snapshot()         # Take a picture and return the image.
while(True):

    for i in range(100):
           img = sensor.snapshot()
           img.binary([low_threshold])
           #image.binary(thresholds, invert=False)此函数将在thresholds内的
           #图像部分的全部像素变为1白,将在阈值外的部分全部像素变为0黑。invert将图像
           #的0 1(黑 白)进行反转,默认为false不反转。
           statistics=img.get_statistics(roi=ROI)
           statistics1=img.get_statistics(roi=ROI1)
           color_l=statistics.l_mode()
           color_a=statistics.a_mode()
           color_b=statistics.b_mode()
           color_l1=statistics1.l_mode()
           color_a1=statistics1.a_mode()
           color_b1=statistics1.b_mode()
           print("ROI:",color_l,color_a,color_b)
           print("ROI1:",color_l1,color_a1,color_b1)
           img.draw_rectangle(ROI)
           img.draw_rectangle(ROI1)
           img.draw_line((8,197,312,196), color=(255,255,255))
           if color_l == 100:
                member=member+1

我画了一条检测线,如果有车辆经过的时候,图像会覆盖检测线,这个时候像素是有变化(输出100,0,0)的,我想知道如何判断导致这个变化的是同一个人

I
网红小智智 星瞳科技

OpenMV无法知道