first青年危机 2023-06-12 18:33 采纳率: 0%
浏览 23

openmv遇到的特征点检测

先进行颜色检测然后再进行特征点检测,但是颜色识别后无法进行特征点检测。

import sensor, image, time
from pyb import UART
import ustruct
sensor.reset()
sensor.set_pixformat(sensor.RGB565)
sensor.set_framesize(sensor.QQVGA)
sensor.skip_frames(10)
sensor.set_auto_whitebal(False)

clock = time.clock()
green_threshold   = (32, 91, -51, -19, 26, 60)
size_threshold = 2000
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
def sending_data(cx,cy):
    global uart;
    data = ustruct.pack("<bbhhb",
                   0x2C,
                   0x12,
                   int(cx),
                   int(ck),
                   0x5B)
    uart.write(data);
uart = UART(3,115200)
uart.init(115200,bits=8,parity=None,stop=1)
Flag = 0
while(True):
    if Flag == 0:
        clock.tick()
        img = sensor.snapshot()
        blobs = img.find_blobs([green_threshold])
        if blobs:
            max_blob = find_max(blobs)
            img.draw_rectangle(max_blob[0:4])
            img.draw_cross(max_blob[5], max_blob[6])
            cx = max_blob[5]
            ck = 1
            FH = bytearray([0x2C,0x12,cx,ck,0x5B])
            uart.write(FH)
            Flag = 1
        else:
            ck =0
            cx=138
            FH =bytearray([0x2C,0x12,cx,ck,0x5B])
            uart.write(FH)
    elif(Flag == 1):
        clock.tick()
        kpts1 = image.load_descriptor("/desc.orb")#引入待测物体特征带点
        img = sensor.snapshot()
        img = img.to_grayscale()
        kpts2 = img.find_keypoints(max_keypoints=150, threshold=10, normalized=True)
        if(kpts2):
            #匹配当前找到的特征和最初的目标特征的相似度
            match = image.match_descriptor(kpts1, kpts2, threshold=85)
            #image.match_descriptor(descritor0, descriptor1, threshold=70, filter_outliers=False)。本函数返回kptmatch对象。
            #threshold阈值设置匹配的准确度,用来过滤掉有歧义的匹配。这个值越小,准确度越高。阈值范围0100,默认70
            #filter_outliers默认关闭。

            #match.count()是kpt1和kpt2的匹配的近似特征点数目。
            #如果大于10,证明两个特征相似,匹配成功。
            if (match.count()>10):
                # If we have at least n "good matches"
                # Draw bounding rectangle and cross.
                #在匹配到的目标特征中心画十字和矩形框。
                img.draw_rectangle(match.rect())
                img.draw_cross(match.cx(), match.cy(), size=10)
                Flag = 0
            print(kpts2, "matched:%d dt:%d"%(match.count(), match.theta()))
  • 写回答

1条回答 默认 最新

报告相同问题?

问题事件

  • 创建了问题 6月12日

悬赏问题

  • ¥15 思科模拟器Router c3600 NM-4E
  • ¥15 岛津txt格式文件转nirs格式
  • ¥15 石墨烯磁表面等离子体
  • ¥15 angular 项目无法启动
  • ¥15 安装wampserver,图标绿色,但是无法进入软件
  • ¥15 C++ MFC 标准库 加密解密解惑
  • ¥15 两条数据合并成一条数据
  • ¥15 Ubuntu虚拟机设置
  • ¥15 comsol三维模型中磁场为什么没有“速度(洛伦兹项)”这一选项
  • ¥15 electron 如何实现自定义安装界面