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 发布的帖子
-
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()
-
RE: 可以用openmv给6-7.4v的舵机供电吗?就是只把舵机的通信线接上拓展版上,然后把剩下两个孔接上电源
我就是没有单独查到openmv上啊,就是有三个孔,舵机正负极就单独插电源
-
可以用openmv给6-7.4v的舵机供电吗?就是只把舵机的通信线接上拓展版上,然后把剩下两个孔接上电源
openmv驱动舵机,舵机单独供给电源可以吗?6-7.4v的,如何操作呢
-
代码正确,运行不报错,但是为什么openmv一直亮白灯
# 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 # 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. # 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 = (75, 96, -43, -0, -1, 55) size_threshold = 2000 blue_led = pyb.LED(3) green_led = pyb.LED(2) red_led = pyb.LED(1) 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 def find_max1(blobs): max_size=0 for blob in blobs: if blob[2]*blob[3] > max_size: max_blob=blob max_size = blob[2]*blob[3] max_blob1=blob[4] return max_blob1返回像素点大小 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]) if blobs: max_blob = find_max(blobs) max_blob1=find_max1(blobs) xiangshu = max_blob1 img.draw_rectangle(max_blob[0:4]) # rect img.draw_cross(max_blob[5], max_blob[6]) # cx, cy if xiangshu > size_threshold: red_led.on() else: blue_led.on() else: green_led.on()
-
RE: 用像素点大小作为led灯亮的颜色种类,怎么不行
# 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 # 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. # 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 = (76, 96, -110, -30, 8, 66) size_threshold = 2000 blue_led = pyb.LED(3) green_led = pyb.LED(2) red_led = pyb.LED(1) 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]) if blobs: max_blob = find_max(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 red_led.on() else: blue_led.on() else: green_led.on()
我单独运行颜色检测也可以,单独运行led灯也行,合在一起就是不行了
-
RE: 手动更改了openmv里的main文件后就不能运行控制舵机了
@hmxd 就是这个main.py 的原文件。我删了换成驱动舵机的代码了,就不行了,所以求一下原代码。
-
openmv h7 plus 实例里面的代码 驱动舵机是出现问题
买了舵机拓展板,没有焊接就是直接插上去。
这是main中编的代码Servo Shield Example.
This example demonstrates the servo shield. Please follow these steps:
1. Connect a servo to any PWM output.
2. Connect a 3.7v battery (or 5V source) to VIN and GND.
3. Copy pca9685.py and servo.py to OpenMV and reset it.
4. Connect and run this script in the IDE.
import time
from servo import Servos
from machine import I2C, Pini2c = I2C(sda=Pin('P5'), scl=Pin('P4'))
servo = Servos(i2c, address=0x40, freq=50, min_us=500, max_us=2500, degrees=180)while True:
servo.position(0, 0)
time.sleep_ms(500)
servo.position(0, 180)
time.sleep_ms(500) -
openmv连接电脑直接说未检测到我的openmv cam 然后闪灯绿白红,这是怎么回事
openmv连接电脑直接说未检测到我的openmv cam 然后闪灯绿白红,这是怎么回事