如何解决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 举报,一经查实,本站将立刻删除。