import sensor, image, time, math
from pyb import UART
import lcd
sensor.reset()
sensor.set_pixformat(sensor.RGB565)
sensor.set_framesize(sensor.QQVGA2) # High Res!
sensor.set_windowing((640, 200)) # V Res of 80 == less work (40 for 2X the speed).
sensor.skip_frames(time = 2000)
sensor.set_auto_gain(False) # 必须关闭此功能,以防止图像冲洗…
sensor.set_auto_whitebal(False) # 必须关闭此功能,以防止图像冲洗…
clock = time.clock()
uart = UART(3, 9600)
# 条形码检测可以在OpenMV Cam的OV7725相机模块的640x480分辨率下运行。
# 条码检测也将在RGB565模式下工作,但分辨率较低。 也就是说,
# 条形码检测需要更高的分辨率才能正常工作,因此应始终以640x480的灰度运行。
lcd.init()
def barcode_name(code):
if(code.type() == image.EAN2):
return "EAN2"
if(code.type() == image.EAN5):
return "EAN5"
if(code.type() == image.EAN8):
return "EAN8"
if(code.type() == image.UPCE):
return "UPCE"
if(code.type() == image.ISBN10):
return "ISBN10"
if(code.type() == image.UPCA):
return "UPCA"
if(code.type() == image.EAN13):
return "EAN13"
if(code.type() == image.ISBN13):
return "ISBN13"
if(code.type() == image.I25):
return "I25"
if(code.type() == image.DATABAR):
return "DATABAR"
if(code.type() == image.DATABAR_EXP):
return "DATABAR_EXP"
if(code.type() == image.CODABAR):
return "CODABAR"
if(code.type() == image.CODE39):
return "CODE39"
if(code.type() == image.PDF417):
return "PDF417"
if(code.type() == image.CODE93):
return "CODE93"
if(code.type() == image.CODE128):
return "CODE128"
while(True):
clock.tick()
img = sensor.snapshot()
codes = img.find_barcodes()
for code in codes:
img.draw_rectangle(code[0:4])
#img.draw_cross(code[5], code[6]) # cx, cy
x=code[5]
print(x)
print_args = (barcode_name(code), 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)
tiaoxinma=code.payload()
print(tiaoxinma)
#FZ = bytearray([0x31,0x31])
#uart.write(FZ)
#date = bytearray([tiaoxinma])
#uart.write(date)
lcd.display(sensor.snapshot())
img.draw_string(100,100,str(tiaoxinma),color=(0,0,0))
if not codes:
print("FPS %f" % clock.fps())
H
hmxd
@hmxd
0
声望
21
楼层
995
资料浏览
0
粉丝
0
关注
hmxd 发布的帖子
-
LCD屏用简单初始化没问题可以运行,但是一加到条形码里面就一直白屏了
-
在pytorch上面训练好的神经分类模型可以直接在openmv上面跑吗?
在pytorch上面训练好神经网络模型可以在openmv上面运行吗?效果是否和在网站上面搭建的模型一样
-
如何在openmv里面实现十进制转化为十六进制,再进行高低位操作,然后通过串口发出数据!
在openmv里面把10进制数字转换成16进制数字再取高低位然后通过串口发出去,例如2000的十六进制为7d0然后 取高低位 高位在后,低位在前。0xd0,0x07.这样格式发出去如何实现。
-
openmv的帧率太低了几乎是2帧每秒,如何提高帧率!
# Blob Detection Example # # This example shows off how to use the find_blobs function to find color # blobs in the image. This example in particular looks for dark green objects. import sensor, image, time, pyb from pyb import UART # You may need to tweak the above settings for tracking green things... # Select an area in the Framebuffer to copy the color settings. sensor.reset() # Initialize the camera sensor. sensor.set_pixformat(sensor.RGB565) # use RGB565. sensor.set_framesize(sensor.QQVGA) # use QQVGA for speed. sensor.skip_frames(10) # Let new settings take affect. sensor.set_auto_whitebal(False) # turn this off. clock = time.clock() # Tracks FPS. #sensor.set_windowing((100, 100)) # For color tracking to work really well you should ideally be in a very, very, # very, controlled enviroment where the lighting is constant... green_threshold = (54, 95, -4, 30, 22, 70) size_threshold = 1500 blue_led = pyb.LED(3) green_led = pyb.LED(2) red_led = pyb.LED(1) uart = UART(3, 9600) sensor.set_auto_exposure(True, exposure_us=5000) # make smaller to go faster def find_max(blobs): max_size=0 for blob in blobs: if blob[2]*blob[3] > max_size: max_blob=blob max_size = blob[2]*blob[3] return max_blob while(True): clock.tick() # Track elapsed milliseconds between snapshots(). img = sensor.snapshot() # Take a picture and return the image. blobs = img.find_blobs([green_threshold]) #FZ = bytearray([0x55,0x55,0x12,0x03,0x03,0xd0,0x07,0x01,0xa1,0x02,0x02,0x04,0x05,0x03,0x6c,0x06]) #FZ1 = bytearray([0x55,0x55,0x14,0x03,0x05,0xd0,0x07,0x01,0x05,0x09,0x02,0x4c,0x05,0x03,0xe9,0x02,0x04,0xc1,0x07,0x05,0x24,0x02]) #FZ1 = bytearray([0x55,0x55,0x08,0x03,0x01,0xd0,0x07,0x01,0x05,0x09]) #uart.write(FZ1) #FZ2 = bytearray([0x55,0x55,0x08,0x03,0x02,0xd0,0x07,0x02,0x4c,0x05]) #uart.write(FZ2) #time.sleep_ms(1000) #FZ3 = bytearray([0x55,0x55,0x08,0x03,0x03,0xd0,0x07,0x03,0xe9,0x02]) #uart.write(FZ3) #time.sleep_ms(1000) #FZ4 = bytearray([0x55,0x55,0x08,0x03,0x04,0xd0,0x07,0x04,0xc1,0x07]) #uart.write(FZ) time.sleep_ms(1000) xiangshu=0 if blobs: max_blob = find_max(blobs) max_blob1=find_max1(blobs) xiangshu = max_blob.blob[4] img.draw_rectangle(max_blob[0:4]) # rect img.draw_cross(max_blob[5], max_blob[6]) # cx, cy if xiangshu > size_threshold: #FZ = bytearray([0x55,0x55,0x05,0x06,0x64,0x01,0x00]) #art.write(FZ) red_led.on() time.sleep_ms(150)#延时150ms red_led.off() else: blue_led.on() time.sleep_ms(150) #延时150ms blue_led.off() else: green_led.on() time.sleep_ms(150) #延时150ms green_led.off()