我的程序运行一半,突然崩了,是咋回事,代码如下:
#小车扫码测试3
#拍一张图先找圆,将其中某个区域复制出来,识别二维码
# 2021-1-25 -AGV小车测试扫码
#识别圆和二维码--2.3MM镜头,先识别圆的位置,截取小块图像,再找二维码,解决二维码在图像边缘无法识别问题
#发送数据格式:2byte帧头,1byte帧序号,1byte帧耗时,4byte码值,2byte左右偏移,2byte上下偏移,2byte角度,1byte校验和,共15byte
import sensor, image, time, math
from pyb import UART
uart = UART(3, 19200)
uart.init(19200, bits=8, parity=None, stop=1)
sensor.reset()
sensor.set_pixformat(sensor.GRAYSCALE)
sensor.set_framesize(sensor.QVGA) # can be QVGA on M7...
sensor.skip_frames(30)
sensor.set_auto_gain(False) # must turn this off to prevent image washout...
clock = time.clock()
while(True):
#sensor.set_windowing((0,0,320, 240))
#sensor.skip_frames(time=1)
img = sensor.snapshot()
clock.tick() #必须放在img = sensor.snapshot()下面
for c in img.find_circles(threshold = 8000, x_margin = 10, y_margin = 10, r_margin = 10,
r_min = 37, r_max = 41, r_step = 1):
img.draw_circle(c.x(), c.y(), c.r(), color = (200))#找到的圆画出来
print(c)
img.draw_cross(160, 120, color = (250), size = 160, thickness = 1)#中心画个十字架
img2 = img.copy((c.x()-c.r(),c.y()-c.r(),2*c.r(),2*c.r()),1,1,copy_to_fb=False)
matrices = img2.find_datamatrices(effort = 500)
print(matrices)
for code in matrices:
data=bytearray([0xaa,0x4d,0,0,#帧头
int(code.payload()),int(code.payload())>>8,int(code.payload())>>16,int(code.payload())>>24,#]) #格式正确
int(c.x()-160),int(c.x()-160)>>8,int(c.y()-120),int(c.y()-120)>>8,#])#, #xy偏移量,可以发送
#int(100*(int(180*code.rotation())/math.pi-180)%36000),int(100*(int(180*code.rotation())/math.pi-180)%36000)>>8])# #角度,可发送
int(100*((int(180*code.rotation())/math.pi-180)%360)),int(100*((int(180*code.rotation())/math.pi-180)%360))>>8])#
num=bytearray([ data[(0)]+data[(1)]+data[(2)]+data[(3)]+data[(4)]+data[(5)]+data[(6)]+data[(7)]+data[(8)]+data[(9)]
+data[(10)]+data[(11)]+data[(12)]+data[(13)] ])#data校验和
uart.write(data)
uart.write(num)
#if not matrices:
print("FPS %f" % clock.fps())报错如下:Traceback (most recent call last):
File "<stdin>", line 35, in <module>
ValueError: invalid syntax for integer with base 10
MicroPython v1.12-omv-r1 OpenMV v3.6.9 2020-10-12; OPENMV4P-STM32H743
Type "help()" for more information.
>>>
code.payload()不是数字的字符串,所以报错了。
意思是我识别的的码值不是数字,不能强制转换成数字是吧
对,:grinning_face_with_smiling_eyes: