标题: 基于图像识别的云台追小球(增量式PID)源程序 [打印本页] 作者: 涂益豪 时间: 2021-3-3 09:54 标题: 基于图像识别的云台追小球(增量式PID)源程序 一、核心的思路
通过openmv识别小球与stm32进行串口通行,stm32通过增量式PID算法控制云台的精准移动 二、openmv程序
import sensor, image, time
from pyb import UART
import json
yellow_threshold = (50, 75,20, 60, 35, 70)
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.
sensor.set_contrast(3)
clock = time.clock() # Tracks FPS.
uart = UART(3, 115200)
uart.init(115200, bits=8, parity=None, stop=1) #8位数据位,无校验位,1位停止位
# Only blobs that with more pixels than "pixel_threshold" and more area than "area_threshold" are
# returned by "find_blobs" below. Change "pixels_threshold" and "area_threshold" if you change the
# camera resolution. "merge=True" merges all overlapping blobs in the image.
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.