找回密碼
 立即注冊

QQ登錄

只需一步,快速開始

搜索
查看: 3987|回復: 0
打印 上一主題 下一主題
收起左側(cè)

python openmv色塊跟隨源程序

[復制鏈接]
跳轉(zhuǎn)到指定樓層
樓主
ID:255401 發(fā)表于 2019-8-5 19:55 | 只看該作者 回帖獎勵 |倒序瀏覽 |閱讀模式
openmv色塊跟隨,串口打印出色塊區(qū)域的中點坐標
利用openmv實現(xiàn)色塊追隨,在程序中調(diào)整閾值即可實現(xiàn)任意顏色的跟隨
,想要提升幀率可以把圖像格式改為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, 下載次數(shù): 25)


分享到:  QQ好友和群QQ好友和群 QQ空間QQ空間 騰訊微博騰訊微博 騰訊朋友騰訊朋友
收藏收藏1 分享淘帖 頂 踩
回復

使用道具 舉報

您需要登錄后才可以回帖 登錄 | 立即注冊

本版積分規(guī)則

手機版|小黑屋|51黑電子論壇 |51黑電子論壇6群 QQ 管理員QQ:125739409;技術(shù)交流QQ群281945664

Powered by 單片機教程網(wǎng)

快速回復 返回頂部 返回列表