# 识别条形码数字,并进行闪灯import sensor, image, time, math, pyb
sensor.reset()
sensor.set_pixformat(sensor.GRAYSCALE)
sensor.set_framesize(sensor.VGA)# High Res!
sensor.set_windowing((640,80))# V Res of 80 == less work (40 for 2X the speed).
sensor.skip_frames(30)
sensor.set_auto_gain(False)# must turn this off to prevent image washout...
sensor.set_auto_whitebal(False)# must turn this off to prevent image washout...
clock = time.clock()
num =0
led = pyb.LED(2)
flag =Truewhile(flag):
clock.tick()
img = sensor.snapshot()
codes = img.find_barcodes()#得到识别的数字for code in codes:
img.draw_rectangle(code.rect())#print_args = (barcode_name(code), code.payload(), (180 * code.rotation()) / math.pi, code.quality(), clock.fps())
print_args =("CODE128", code.payload(),(180* code.rotation())/ math.pi, code.quality(), clock.fps())print("Barcode %s, Payload \"%s\", rotation %f (degrees), quality %d, FPS %f"% print_args)
num =int(code.payload())
flag =Falseifnot codes:print("FPS %f"% clock.fps())#LED灯控制#import time, pyb#将绿灯赋值给变量led
num ="%04d"% num
num =int(num)
num1 =int(num*0.001)
num2 =(int(num*0.01))%10
num3 =(int(num*0.1))%10
num4 =int(num%10)print(num1,num2,num3,num4)
led = pyb.LED(2)# Switch to using the green LED.#usb = pyb.USB_VCP() # This is a serial port object that allows you to# 第一个数字
flag =Truewhile(flag):if(num1 ==0):
flag =Falsebreakelse:
led.on()
time.sleep(0.5)
led.off()
time.sleep(0.5)
num1 -=1
time.sleep(3)#第二个数字
flag =Truewhile(flag):if(num2 ==0):
flag =Falsebreakelse:
led.on()
time.sleep(0.5)
led
2021电赛openmv代码前视OpenMV,识别条形码并进行亮灯功能。# 识别条形码数字,并进行闪灯import sensor, image, time, math, pybsensor.reset()sensor.set_pixformat(sensor.GRAYSCALE)sensor.set_framesize(sensor.VGA) # High Res!sensor.set_windowing((640, 80)) # V Res of 80 == less work (4