stm32与openmv进行串口通讯_openmv与stm32串口
目录
1.openmv端配置:
1.1 openmv代码:
1.2 openmv鱼眼镜头画面异常修正
2.STM32F103C8T6端配置
1.openmv端配置:
1.1 openmv代码:
我使用的是将被识别的目标中心点坐标通过串口通讯发送给STM32,中心值感觉不是很准,后面还需要调整,但是基本的收发已经完成。
# Untitled - By: zzy - 周五 11月 25 2022import sensor, image, timefrom pyb import UARTimport json#output_str_green=\"[0,0]\"output_str_white=\"[0,0]\"#green_threshold = ( 0, 80, -70, -10, -0, 30)#使用的白色测试阈值white_threshold = (53, 100, -128, 127, -128, 127)sensor.reset()sensor.set_pixformat(sensor.RGB565)sensor.set_framesize(sensor.QVGA)sensor.set_windowing((0,20,320,200))#QVGA find Region Of Interest#sensor.set_windowing((5,10,160,95))#QQVGA find Region Of Interestsensor.skip_frames(10)sensor.set_auto_whitebal(False)#白平衡增益关闭clock = time.clock()uart = UART(3, 115200)def find_max(blobs): max_size=0 for blob in blobs: if blob.pixels() > max_size: max_blob=blob max_size = blob.pixels() return max_blobdef detect(max_blob):#输入的是寻找到色块中的最大色块 #print(max_blob.solidity()) shape=0 if max_blob.solidity()>0.90 or max_blob.density()>0.84: img.draw_rectangle(max_blob.rect(),color=(255,255,255)) shape=1 elif max_blob.density()>0.6: img.draw_circle((max_blob.cx(), max_blob.cy(),int((max_blob.w()+max_blob.h())/4))) shape=2 elif max_blob.density()>0.4: img.draw_rectangle(max_blob.rect(),color=(0,0,0)) shape=3 return shapewhile(True): #clock.tick() img = sensor.snapshot() # Take a picture and return the image. blobs_white = img.find_blobs([white_threshold]) if blobs_white: max_blob_white=find_max(blobs_white) shape_white=detect(max_blob_white) #img.draw_rectangle(max_blob_blue.rect(),color=(0,0,255)) img.draw_cross(max_blob_white.cx(), max_blob_white.cy(),color=(0,0,255)) output_str_white=\"[%d,%d]\" % (max_blob_white.cx()-160,max_blob_white.cy()-100) #方式1 img_data=bytearray([0x2C,7,4,max_blob_white.cx()-160,max_blob_white.cy()-100,1,0X5B]) # 数据倒数