Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/python/282.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Python,使用Open CV进行对象检测_Python_Opencv_Keypoint - Fatal编程技术网

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

Python,使用Open CV进行对象检测,python,opencv,keypoint,Python,Opencv,Keypoint,我目前正在编写一些python代码来使用单目相机检测对象。使用orb=orb_Create()找到关键点,然后使用kp、des=orb.detectAndCompute。我看到有人建议使用一个函数来获取模板坐标,使用下面所示的方法,尽管它不起作用,因为我无法将关键点转换为整数。我得到的第一个错误是; “列表”对象没有属性“pt” 如果我尝试只做int(kp1[0]),我会得到错误 int()参数必须是字符串、类似字节的对象或数字,而不是“cv2.KeyPoint” 有没有人能帮忙,或者给出一些好

我目前正在编写一些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, r1, c0, 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, r1, c0, c1)