用户在使用OpenMV4 H7 Plus连接Arduino时遇到了图像静止的问题。具体表现为当连接OpenMV与Arduino中定义的引脚时,图像会静止,即使重新定义引脚后问题依然存在。
故障代码:
import sensor,image,time,pyb,json,math,ujson
from pyb import Pin
from pyb import UART
from pyb import LED
LDE1=pyb.LED(1)
LDE2=pyb.LED(2)
LDE3=pyb.LED(3)
LDE1.on()
LDE2.on()
LDE3.on()
red_threshold = (41, 56, 46, 96, 0, 62)
blue_threshold = (21, 58, -2, 24, -68, -18)
green_threshold = (43, 71, -55, -23, -4, 52);
global left,middle,right,VAL,flag_color,code,R,G,B
global color
global flag_color
flag_color = 0
left=0
middle=0
right=0
obj = [[12,0],[10.12],[22,10],[99,11]]
objthresholds = [(41, 56, 46, 96, 0, 62), #红
(43, 71, -55, -23, -4, 52), #绿
(21, 58, -2, 24, -68, -18)] #蓝
graythreshold=[(100,255)]
threshold_index = 2
red_color_code = 1
green_color_code = 2
blue_color_code = 4
black_color_code = 8
def compareBlob(blob1, blob2):
tmp = blob1.pixels() - blob2.pixels()
if tmp == 0:
return 0
elif tmp > 0:
return 1
else :
return -1
p5 = Pin('P5', Pin.OUT_PP)
p6 = Pin('P6', Pin.OUT_PP)
p7 = Pin('P7', Pin.IN)
p8 = Pin('P8', Pin.IN)
p9 = Pin('P0', Pin.IN)
sensor.reset()
sensor.set_pixformat(sensor.RGB565)
sensor.set_framesize(sensor.QVGA)
sensor.skip_frames(10)
sensor.set_auto_whitebal(False)
obj = [[12,0],[10.12],[22,10],[99,11]]
uart = UART(3,115200)
while(flag_color == 0):
if p8.value() == 1 and p7.value() == 0 and p9.value() == 1: #扫码
img = sensor.snapshot()
img.lens_corr(1.8)
for code in img.find_qrcodes():
Data = code.payload()
if Data == ("123+123"):
uart.write("1")
if Data == ("123+132"):
uart.write("2")
if Data == ("123+213"):
uart.write("3")
if Data == ("123+231"):
uart.write("4")
if Data == ("123+312"):
uart.write("5")
if Data == ("123+321"):
uart.write("6")
if Data == ("132+123"):
uart.write("7")
if Data == ("132+132"):
uart.write("8")
if Data == ("132+213"):
uart.write("9")
if Data == ("132+231"):
uart.write("10")
if Data == ("132+312"):
uart.write("11")
if Data == ("132+321"):
uart.write("12")
if Data == ("213+123"):
uart.write("13")
if Data == ("213+132"):
uart.write("14")
if Data == ("213+213"):
uart.write("15")
if Data == ("213+231"):
uart.write("16")
if Data == ("213+312"):
uart.write("17")
if Data == ("213+321"):
uart.write("18")
if Data == ("231+123"):
uart.write("19")
if Data == ("231+132"):
uart.write("20")
if Data == ("231+213"):
uart.write("21")
if Data == ("231+231"):
uart.write("22")
if Data == ("231+312"):
uart.write("23")
if Data == ("231+321"):
uart.write("24")
if Data == ("312+123"):
uart.write("25")
if Data == ("312+132"):
uart.write("26")
if Data == ("312+213"):
uart.write("27")
if Data == ("312+231"):
uart.write("28")
if Data == ("312+312"):
uart.write("29")
if Data == ("312+321"):
uart.write("30")
if Data == ("321+123"):
uart.write("31")
if Data == ("321+132"):
uart.write("32")
if Data == ("321+213"):
uart.write("33")
if Data == ("321+231"):
uart.write("34")
if Data == ("321+312"):
uart.write("35")
if Data == ("321+321"):
uart.write("36")
if Data == ("同色装配"):
uart.write("37")
if Data == ("异色错配"):
uart.write("38")
print(Data)
