你好,我在进行颜色识别的过程中发现openmv会不时卡住,请问这是什么原因呢?自己猜想,是不是跟自己在同个图像中进行了两次分区域识别有关,希望有知道的大佬指点一下,另外,在卡住之后图像会直接与摄像头断开连接,这个问题非常致命!
import sensor, image, time,math
from pyb import UART
import json
sensor.reset() # Initialize the camera sensor.
sensor.set_pixformat(sensor.RGB565) # use RGB565.
sensor.set_framesize(sensor.QQVGA) # use QVGA for quailtiy ,use QQVGA for speed.
sensor.skip_frames(10) # Let new settings take affect.
#sensor.set_auto_gain(False) # must be turned off for color tracking
sensor.set_auto_whitebal(False)
sensor.set_vflip(True)
clock = time.clock() # Tracks FPS.
#初始化
uart = UART(3, 115200)
color_threshold1 = (0, 255, -40, -20, 10, 35)
color_threshold2 = (0, 255, -40, -20, 10, 35)
date1=0
date2=100
while(True):
flag1=1
flag2=0
clock.tick() # Track elapsed milliseconds between snapshots().
img = sensor.snapshot() # Take a picture and return the image.
#查看是否检测到了绿色基座
blobs = img.find_blobs([color_threshold1],roi=[40,60,80,60], area_threshold=300)
if blobs: #如果找到了目标颜色
for blob in blobs: #迭代找到的目标颜色区域
is_rect = 0
rect_s=0
max_s = -1
for c in img.find_rects():
is_rect = 1
rect_s=c.y()*c.h()
if rect_s > max_s:
max_s = rect_s
max_rect = c
if is_rect:
flag2=1
img.draw_rectangle(blob.rect()) # rect # 如果有对应颜色的矩形 标记外框
img.draw_cross(blob[5], blob[6]) # cx, cy 画出十字
date1=int(blob.cx()-80)
#查看是否检测到了水稻
blobs=img.find_blobs([color_threshold2],roi=[40,0,80,60],x_stride=10,y_stride=10,area_threshold=500,merge=True,pixels_threshold=50)
if blobs:
flag1=0
max_blob=-1
mblob=0
for blob in blobs:
if blob.area()>max_blob:
mblob=blob
img.draw_rectangle(mblob.rect()) # rect
if (flag1 and flag2):
date=bytearray([0xDD,date1,0XDF])
print(date1)
#uart.write(date)
flag1=1
flag2=0
else:
date=bytearray([0xDD,date2,0XDF])
print(date2)
#uart.write(date)
flag1=1
flag2=0
#print(clock.fps()) # Note: Your OpenMV Cam runs about half as fast while我使用了OpenMV3和OpenMV4测试了你的代码,都没有发现卡住的现象。

@kidswong999 我直接运行在IDE中的脚本,时不时的会断开连接,好像和楼主的情况是一样的,先是亮红灯,接着就断开了
@kidswong999 感谢解惑,有没有可能是频繁链接或断开IDE所导致的呢?
使用原装的数据线,电脑的USB口不要松。