找回密码
 立即注册

QQ登录

只需一步,快速开始

搜索
查看: 3118|回复: 0
收起左侧

python openmv色块跟随源程序

[复制链接]
ID:255401 发表于 2019-8-5 19:55 | 显示全部楼层 |阅读模式
openmv色块跟随,串口打印出色块区域的中点坐标
利用openmv实现色块追随,在程序中调整阈值即可实现任意颜色的跟随
,想要提升帧率可以把图像格式改为QQVGA

源程序如下:
  1. # Blob Detection and uart transport
  2. import sensor, image, time
  3. from pyb import UART
  4. import json
  5. # For color tracking to work really well you should ideally be in a very, very,
  6. # very, controlled enviroment where the lighting is constant...
  7. yellow_threshold   = (31, 88, 40, 127, -25, 122)
  8. # You may need to tweak the above settings for tracking green things...
  9. # Select an area in the Framebuffer to copy the color settings.

  10. sensor.reset() # Initialize the camera sensor.
  11. sensor.set_pixformat(sensor.RGB565) # use RGB565.
  12. sensor.set_framesize(sensor.QVGA) # use QQVGA for speed.
  13. sensor.skip_frames(10) # Let new settings take affect.
  14. sensor.set_auto_whitebal(False) # turn this off.
  15. clock = time.clock() # Tracks FPS.

  16. uart = UART(3, 115200)
  17. def find_max(blobs):
  18.     max_size=0
  19.     for blob in blobs:
  20.         if blob.pixels() > max_size:
  21.             max_blob=blob
  22.             max_size = blob.pixels()
  23.     return max_blob

  24. while(True):
  25.     img = sensor.snapshot() # Take a picture and return the image.

  26.     blobs = img.find_blobs([yellow_threshold])
  27.     if blobs:
  28.         max_blob=find_max(blobs)
  29.         print('sum :', len(blobs))
  30.         img.draw_rectangle(max_blob.rect())
  31.         img.draw_cross(max_blob.cx(), max_blob.cy())

  32.         output_str="%.3d,%.3d" % (max_blob.cx(),max_blob.cy()) #方式1
  33.         #output_str=json.dumps([max_blob.cx(),max_blob.cy()]) #方式2
  34.         print('you send:',output_str)
  35.         uart.write(output_str+'\r\n')
  36.     else:
  37.         print('not found!')
复制代码

以上资料51hei提供下载:
uart_red.zip (1.16 KB, 下载次数: 24)
回复

使用道具 举报

您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

手机版|小黑屋|51黑电子论坛 |51黑电子论坛6群 QQ 管理员QQ:125739409;技术交流QQ群281945664

Powered by 单片机教程网

快速回复 返回顶部 返回列表