from pyb import LED,Timer
import sensor, image, time, math, struct
import Message
class yuan(object):
flag = 0
r = 0
x = 0
y = 0
yuan=yuan()
circles=[]
def find_max_circle(circles):
max_r=0
for c in circles:
if c.r()>max_r:
max_circle=c
max_r=c.r()
return max_circle
while(True):
#def CircleCheck():
img = sensor.snapshot().lens_corr(1.8)
circles.clear()
all_circles=img.find_circles(x_stride=1,y_stride=1,threshold = 2000,
x_margin = 10, y_margin = 10, r_margin = 10,
r_min = 2, r_max = 100)
for c in all_circles:
if c.r()<22:
circles.append(c)
if circles:
max_circle = find_max_circle(circles)
img.draw_circle(max_circle.x(),max_circle.y(),max_circle.r())
img.draw_cross(max_circle.x(), max_circle.y())
yuan.x = max_circle.x()-80
yuan.y = max_circle.y()-60
yuan.flag = 1
LED(3).toggle()
LED(2).toggle()
else:
yuan.flag = 0
LED(2).off()
LED(3).off()
Message.UartSendData(Message.DotDataPack(yuan.flag,yuan.x,yuan.y,max_circle.x(), max_circle.y()))就这个错误
Traceback (most recent call last):
File "<stdin>", line 25, in <module>
OSError: Invalid ROI dimensions!
MicroPython v1.9.4-4553-gb4eccdfe3 on 2019-05-02; OPENMV4 with STM32H743
Type "help()" for more information.
>>>
你的代码不全啊, sensor初始化呢?
其实还有代码的,这是主函数,sensor初始化在主函数里,我在主函数里,还是一样的错误
import sensor, image, time, math, struct
import json
from pyb import LED,Timer
from struct import pack, unpack
import Message,LineFollowing,DotFollowing,find_circle
#初始化镜头
sensor.reset()
sensor.set_pixformat(sensor.RGB565)#设置相机模块的像素模式
sensor.set_framesize(sensor.QQVGA)#设置相机分辨率160*120
sensor.skip_frames(time=3000)#时钟
sensor.set_auto_whitebal(False)#若想追踪颜色则关闭白平衡
clock = time.clock()#初始化时钟
#主循环
while(True):
clock.tick()#时钟初始化
#接收串口数据
Message.UartReadBuffer()
if Message.Ctr.WorkMode==1:#点检测
DotFollowing.DotCheck()
elif (Message.Ctr.WorkMode==2):#线检测
LineFollowing.LineCheck()
elif (Message.Ctr.WorkMode==3):#圆检测
find_circle.CircleCheck()
elif(Message.Ctr.WorkMode==4):#Led检测
#用户数据发送
#Message.UartSendData(Message.UserDataPack(127,127,32767,32767,65536,65536,65536,65536,65536,65536))
#计算程序运行频率
if Message.Ctr.IsDebug == 1:
fps=int(clock.fps())
Message.Ctr.T_ms = (int)(1000/fps)
print('fps',fps,'T_ms',Message.Ctr.T_ms)
#************************************ (C) COPYRIGHT 2019 ANO ***********************************#你能不能给我能够测试的代码。
如果涉及代码,需要报错提示与全部代码文本,请注意不要贴代码图片