OpenEdv-开源电子网

 找回密码
 立即注册
正点原子全套STM32/Linux/FPGA开发资料,上千讲STM32视频教程免费下载...
查看: 7352|回复: 4

有无openmv和stm32f4串口通信(可以传输openmv处理完坐标的那种)

[复制链接]

1

主题

3

帖子

0

精华

初级会员

Rank: 2

积分
88
金钱
88
注册时间
2021-6-15
在线时间
29 小时
发表于 2021-7-14 12:40:50 | 显示全部楼层 |阅读模式
10金钱
openmv 程序
import sensor, image, time, math
from pyb import UART
import json
import ustruct

sensor.reset()
sensor.set_pixformat(sensor.RGB565) # grayscale is faster
sensor.set_framesize(sensor.QQVGA)
sensor.skip_frames(time = 2000)
clock = time.clock()

uart = UART(3,115200)   #定义串口3变量
uart.init(115200, bits=8, parity=None, stop=1) # init with given parameters

def find_max(circles):    #定义寻找球面积最大的函数
    max_size=0
    for circle in circles:
        if circle.magnitude() > max_size:
            max_circle=circle
            max_size = circle.magnitude()
    return max_circle

def sending_data(cx,cy):    #发送函数
    global uart;
    #frame=[0x2C,18,cx%0xff,int(cx/0xff),cy%0xff,int(cy/0xff),0x5B];
    #data = bytearray(frame)
    data = ustruct.pack("<bbhhb",              
                   0x2C,                       
                   0x12,                       
                   int(cx),                    
                   int(cy),                    
                   0x5B)
    uart.write(data);   

def recive_data():   #接收函数
    global uart
    if uart.any():
        tmp_data = uart.readline();
        print(tmp_data)

while(True):
    clock.tick()
    img = sensor.snapshot()

    circles = img.find_circles(threshold = 2500, x_margin = 10, y_margin = 10, r_margin = 10,
            r_min = 2, r_max = 100, r_step = 2);
    cx=0;cy=0;
    if circles:
        #如果找到了目标球
        max_c = find_max(circles);
        #在圆周围画一个圆
        #img.draw_circle(circle.x(), circle.y(), circle.r(), color = (255, 0, 0))
        #用圆标记出目标颜色区域
        img.draw_cross(max_c[0], max_c[1]) # cx, cy
        img.draw_cross(160, 120) # 在中心点画标记
        #在目标颜色区域的中心画十字形标记
        cx=max_c[0];
        cy=max_c[1];
        img.draw_line((80,60,cx,cy), color=(127));
        #img.draw_string(160,120, "(%d, %d)"%(160,120), color=(127));
        img.draw_string(cx, cy, "(%d, %d)"%(cx,cy), color=(127));

        sending_data(cx,cy); #发送点位坐标
        recive_data();


正点原子逻辑分析仪DL16劲爆上市
回复

使用道具 举报

1

主题

3

帖子

0

精华

初级会员

Rank: 2

积分
88
金钱
88
注册时间
2021-6-15
在线时间
29 小时
 楼主| 发表于 2021-7-14 12:40:51 | 显示全部楼层
回复

使用道具 举报

6

主题

890

帖子

0

精华

金牌会员

Rank: 6Rank: 6

积分
1477
金钱
1477
注册时间
2020-8-19
在线时间
335 小时
发表于 2021-7-14 18:50:27 | 显示全部楼层
帮顶  
回复

使用道具 举报

0

主题

7

帖子

0

精华

新手上路

积分
27
金钱
27
注册时间
2021-7-23
在线时间
8 小时
发表于 2021-8-2 15:17:44 | 显示全部楼层

可以发一下工程文件吗,谢谢
回复

使用道具 举报

0

主题

9

帖子

0

精华

新手入门

积分
9
金钱
9
注册时间
2023-5-5
在线时间
4 小时
发表于 2023-5-17 17:28:19 | 显示全部楼层
哥,求程序
回复

使用道具 举报

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

本版积分规则



关闭

原子哥极力推荐上一条 /2 下一条

正点原子公众号

QQ|手机版|OpenEdv-开源电子网 ( 粤ICP备12000418号-1 )

GMT+8, 2025-2-24 14:35

Powered by OpenEdv-开源电子网

© 2001-2030 OpenEdv-开源电子网

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