logo

小车中央时停止

2018-08-10 16:11
S
openmv萌新

各位大佬大家好,我有一个非常严肃的问题想问大家,我想让小车缓缓经过物料(物料为长方体,有固定颜色),在物料处于小车中央的摄像头中央时停止,请问我应该怎么设计程序呢?我几天一直在查,发现有以下几种方法:1.利用ROI,把ROI变得适当的小,然后当ROI区域内检测到相应颜色,即if blobs时候,小车停止。

2.我打算利用色块的坐标,即img.draw_string(100,100,'x='+str(blob.cx()), color=(0,0,0))

img.draw_string(100,100,'y=+'str(blob.cy()), color=(0,0,0)),当相应颜色的坐标处于屏幕中央的时候小车停止。

我刚刚入门,只能想出这两种办法,希望好心人能帮我分析下可行性,或者提出更好的建议,谢谢了!!!救救孩子:folded_hands: :folded_hands_light_skin_tone: :folded_hands_medium-light_skin_tone: :folded_hands_medium_skin_tone: :folded_hands_medium-dark_skin_tone: :folded_hands_dark_skin_tone:

2018-08-10 19:57
I
网红小智智 星瞳科技

if blob.cx()==img.width()/2:

小车停

当色块的中心左边等于图像的一半宽度的时候。

当然你也可以加一个范围。

2018-08-14 10:35
S
openmv萌新

@kidswong999 您好,我已经对我的程序进行了相应的修改,我把小车停止模拟成了小灯亮,但是无法实现啊,请问是不是我的程序有错误啊?而且运行起来的时候一卡一卡的,是不是我有什么地方写错了啊

# Single Color RGB565 Blob Tracking Example
#
# This example shows off single color RGB565 tracking using the OpenMV Cam.

import sensor, image, time,pyb

threshold_index = 0 # 0 for red, 1 for green, 2 for blue

# Color Tracking Thresholds (L Min, L Max, A Min, A Max, B Min, B Max)
# The below thresholds track in general red/green/blue things. You may wish to tune them...
#将蓝灯赋值给变量led
led = pyb.LED(3) # Red LED = 1, Green LED = 2, Blue LED = 3, IR LEDs = 4.
usb = pyb.USB_VCP() # This is a serial port object that allows you to
# communciate with your computer. While it is not open the code below runs.

thresholds = [(30, 100, 15, 127, 15, 127), # generic_red_thresholds
              (30, 100, -64, -8, -32, 32), # generic_green_thresholds
              (0, 30, 0, 64, -128, 0)] # generic_blue_thresholds

sensor.reset()
sensor.set_pixformat(sensor.RGB565)
sensor.set_framesize(sensor.QVGA)
sensor.skip_frames(time = 2000)
sensor.set_auto_gain(False) # must be turned off for color tracking
sensor.set_auto_whitebal(False) # must be turned off for color tracking
clock = time.clock()




#ROI=(80,30,15,15)#左上方




# Only blobs that with more pixels than "pixel_threshold" and more area than "area_threshold" are
# returned by "find_blobs" below. Change "pixels_threshold" and "area_threshold" if you change the
# camera resolution. "merge=True" merges all overlapping blobs in the image.

while(True):
    clock.tick()
    img = sensor.snapshot()
    for blob in img.find_blobs([thresholds[threshold_index]], pixels_threshold=200, area_threshold=200, merge=True):
        img.draw_rectangle(blob.rect())
        img.draw_cross(blob.cx(), blob.cy())
        led.on()
      
        time.sleep(600)
   #此处为lcd输出XY坐标img.draw_string(100,100,'x='+str(blob.cx()), color=(0,0,0))
  #img.draw_string(100,100,'y=+'str(blob.cy()), color=(0,0,0))
 # thresholds[0]为色域的第一个,即为红色,见视频颜色16min
 
if blob.cx()==img.width()/2:
    led.on()
    time.sleep(600)


print(blob)  #rotation为旋转的弧度,通过这个来确认垂直时候停止
print(blob.code())   #打印出来相应颜色的代码,可以通过这个进行串口通信 

#通过90度,小RIO,代码确定为红色,从而进行相应的定位
2018-08-14 15:47
S
openmv萌新

不好意思,已经弄懂了,只要把语句对齐就好了

2018-08-15 14:18
Y
sagp

@openmv萌新 哥我问一下如果相应的颜色位于中央小车停的程序怎么写啊

2018-08-20 01:18
S
openmv萌新

@sagp 我的亲弟弟,你是不是没看见二楼那个大神发的if blob.cx()==img.width()/2:啊,这个程序好用的都不能再好用了!