python opencv 过程问题记录

使用 cv FlannBasedMatcher 出现bug

    FLANN_INDEX_KDTREE = 0
    index_params = dict(algorithm=FLANN_INDEX_KDTREE, trees=5)
    search_params = dict(checks=50)
    # 使用FlannBasedMatcher 寻找最近邻近似匹配
    flann = cv2.FlannBasedMatcher(index_params, search_params)
    # 使用knnMatch匹配处理,并返回匹配matches
    matches = flann.knnMatch(des1, des2, k=2)

错误如下

  File "D:\chengzhang\code\图像匹配\do_match.py", line 55, in match2frames
    matches = flann.knnMatch(des1, des2, k=2)
cv2.error: OpenCV(3.4.2) C:\projects\opencv-python\opencv\modules\flann\src\miniflann.cpp:315: error: (-210:Unsupported format or combination of formats) in function 'cv::flann::buildIndex_'
> type=0
> 

解决办法

将matches = flann.knnMatch(des1, des2, k=2)修改为
# matches = flann.knnMatch(des1, des2, k=2)
matches = flann.knnMatch(np.asarray(des1, np.float32), np.asarray(des2, np.float32), k=2)

参考来源1

参考来源2


‘cv2.cv2‘ has no attribute ‘xfeatures2d‘

algorithms_all = {
    "SIFT": cv2.xfeatures2d.SIFT_create(),
    "SURF": cv2.xfeatures2d.SURF_create(8000),
    "ORB": cv2.ORB_create()
}

错误如下

(-210:Unsupported format or combination of formats) in function 'cv::flann::
‘cv2.cv2‘ has no attribute ‘xfeatures2d‘

解决办法:

# python version 3.7
pip install opencv_python==3.4.2.16 
pip install opencv-contrib-python==3.4.2.16

https://blog.csdn.net/qq_43474959/article/details/107777145

你可能感兴趣的:(日常,bug,深度学习)