Python,使用Open CV进行对象检测

问题描述

我目前正在编写一些python代码,以使用单眼相机检测物体。使用orb = ORB_Create(),然后使用kp,des = orb.detectAndCompute找到关键点。我看到有人建议使用如下所示的方法来使用函数获取模板坐标,尽管由于我无法将关键点转换为整数而无法使用。我得到的第一个错误是; “列表”对象没有属性“ pt”

如果我尝试只做int(kp1 [0]),就会收到错误消息 int()参数必须是字符串,类似字节的对象或数字,而不是'cv2.KeyPoint'

任何人都可以提供帮助,或者就如何解决这个问题提出任何好的建议。任何帮助表示赞赏!

谢谢

def _get_template_coord(img,keypoint,scale=1):
    """ Returns the corners of the template,relative to original image.
    Params:
        rbnd: Max row value of original image.
        cbnd: Max col value of original image.
        keypoint: keypoint used to get point,and size.
        scale: scale multiplier used to scale template.
    Returns:
        r0,r1,c0,c1: Corner values of template.
    """

    # Helper function
    
    global r0,c1
    
    rbnd,cbnd = img.shape[:2]
    
    pair2int = lambda pt: (int(pt[0]),int(pt[1]))
    
    c,r = pair2int((keypoint.pt))
    
    size = int((keypoint.size * 1.2 / 9 * 20) * scale // 2)
    r0 = np.max([0,r - size])
    r1 = np.min([rbnd,r + size])
    c0 = np.max([0,c - size])
    c1 = np.min([cbnd,c + size])
    return (r0,c1)

解决方法

暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!

如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。

小编邮箱:dio#foxmail.com (将#修改为@)