logo

为什么串口助手接收不到这个代码的数据?

2023-07-11 16:57
2
w23d

我的串口和波特率都没有选错

# 利用特征点检测特定物体例程。
# 向相机显示一个对象,然后运行该脚本。 一组关键点将被提取一次,然后
# 在以下帧中进行跟踪。 如果您想要一组新的关键点,请重新运行该脚本。
# 注意:请参阅文档以调整find_keypoints和match_keypoints。
import sensor, time, image, math 
from pyb import UART
from struct import pack, unpack
import json
# Reset sensor
sensor.reset()
uart = UART(3, 115200)

# Sensor settings
sensor.set_contrast(3)
sensor.set_gainceiling(16)
sensor.set_framesize(sensor.VGA)
sensor.set_windowing((320, 240))
sensor.set_pixformat(sensor.GRAYSCALE)

sensor.skip_frames(time = 2000)
sensor.set_auto_gain(False, value=100)

#画出特征点
def draw_keypoints(img, kpts):
    if kpts:
        print(kpts)
        img.draw_keypoints(kpts)
        img = sensor.snapshot()
        time.sleep_ms(1000)

kpts1 = None
#kpts1保存目标物体的特征,可以从文件导入特征,但是不建议这么做。
#kpts1 = image.load_descriptor("/desc.orb")
#img = sensor.snapshot()
#draw_keypoints(img, kpts1)

clock = time.clock()

while (True):
    clock.tick()
    img = sensor.snapshot()
    if (kpts1 == None):
        kpts1 = img.find_keypoints(max_keypoints=150, threshold=10, scale_factor=1.2)
        draw_keypoints(img, kpts1)
    else:
        kpts2 = img.find_keypoints(max_keypoints=150, threshold=10, normalized=True)
        if (kpts2):
            match = image.match_descriptor(kpts1, kpts2, threshold=85)
            if (match.count()>10):
                img.draw_rectangle(match.rect())
                img.draw_cross(match.cx(), match.cy(), size=10)
                bx_x=match.cx()-160
                by_y=120-match.cy()
                x=int(math.fabs(bx_x))
                y=int(math.fabs(by_y))
            #print(kpts2, "matched:%d dt:%d"%(match.count(), match.theta()))
                data = bytearray([x,y])
                uart.write(data)
                print(data)
    img.draw_string(0, 0, "FPS:%.2f"%(clock.fps()))
2023-07-11 19:19
I
网红小智智 星瞳科技

先单独测试发送串口的例子。https://singtown.com/learn/50235/

2023-07-11 22:30
2
w23d

@kidswong999 历程可以跑

b0856d26-1b27-446c-ad49-2f90b2e1bd8e.png
2023-07-12 19:13
I
网红小智智 星瞳科技

要么是你的代码有问题,没发送。

要么是显示的问题,要选择hex显示,而不是utf8。