当前位置:首页 » 《随便一记》 » 正文

error: OpenCV(4.7.0) :-1: error: (-5:Bad argument) in function ‘knnMatch‘> Overload resolution fail

29 人参与  2023年05月03日 18:25  分类 : 《随便一记》  评论

点击全文阅读


 各位大佬,我正在用Sobel、SIFT feature extraction、Color histogram去做图像分类检索。想输入一张图片去检索相类似的图像,出现了以下错误,请问该怎么解决呢?万分感谢

# Define a function to find similar images
def find_similar_images(image_path, k=5):
    # Load input image and compute descriptors
    img = cv2.imread(image_path, cv2.IMREAD_GRAYSCALE)
    img = cv2.resize(img, (img_size, img_size))
    keypoints, descriptors = sift.detectAndCompute(img, None)

    # If no keypoints are found, return an empty list
    if descriptors is None:
        return []

    # Convert descriptors to np.float32 data type
    descriptors = descriptors.astype(np.float32)
    
    # Compute distances between input image descriptors and dataset descriptors
    matcher = cv2.FlannBasedMatcher()
    matches = matcher.knnMatch(descriptors, data, k=2)
    distances = [m[0].distance for m in matches]
    
    # Find indices of the most similar images
    indices = np.argsort(distances)[:k]
    similar_images = []
    for index in indices:
        category = labels[index]
        folder_path = os.path.join(path, category)
        img_names = os.listdir(folder_path)
        img_path = os.path.join(folder_path, img_names[index])
        similar_images.append(cv2.imread(img_path))
    
    return similar_images

# Input an image and get similar images
input_image_path = "bridge.jpg"
similar_images = find_similar_images(input_image_path)

# Display similar images
for image in similar_images:
    cv2.imshow("Similar Image", image)
    cv2.waitKey(1000)
    
cv2.destroyAllWindows()

error: OpenCV(4.7.0) :-1: error: (-5:Bad argument) in function 'knnMatch'> Overload resolution failed:>  - trainDescriptors data type = 17 is not supported>  - Expected Ptr<cv::UMat> for argument 'trainDescriptors'>  - argument for DescriptorMatcher.knnMatch() given by name ('k') and position (2)>  - argument for DescriptorMatcher.knnMatch() given by name ('k') and position (2)

点击全文阅读


本文链接:http://m.zhangshiyu.com/post/60542.html

<< 上一篇 下一篇 >>

  • 评论(0)
  • 赞助本站

◎欢迎参与讨论,请在这里发表您的看法、交流您的观点。

最新文章

  • 家宴过后,我捉奸了庶妹和我老公后续+番外_庶妹老公侍卫读者推荐_小说后续在线阅读_无删减免费完结_
  • 首富老公为三姐妹点天灯挥金如土,我换嫁贺总轰动全国强推_胥淮岁岁过敏最新阅读_小说后续在线阅读_无删减免费完结_
  • 未婚夫和同事孕期领证,我转身嫁入豪门推荐_沈泽光安南拿泽光小编推荐_小说后续在线阅读_无删减免费完结_
  • 重回奥运种子选手陷害我的这天番茄热门_林子李梦冷笑在线看_小说后续在线阅读_无删减免费完结_
  • 知微向海完结全文_陆知衍纪瑶奶奶最新阅读_小说后续在线阅读_无删减免费完结_
  • 被污蔑送错外卖后,我杀疯了阅读_小徐胡闹阅读_小说后续在线阅读_无删减免费完结_
  • 我坐上评委席后,把我踢出乐队的男友悔疯了快手热门_乔枝姐阿媛程戬常读_小说后续在线阅读_无删减免费完结_
  • 当风吹落了雨TOP10_老公陈角鹰薇薇大反击_小说后续在线阅读_无删减免费完结_
  • 未婚夫逼我放弃继承权后,全家悔疯了一口气完结_沈雨雨柔养老校园甜文_小说后续在线阅读_无删减免费完结_
  • 手撕无耻老婆一家宝藏文_小姨子钟琳老公人气小说_小说后续在线阅读_无删减免费完结_
  • 愿得一人心常读_萧城蒋雪柔华冉优质全文_小说后续在线阅读_无删减免费完结_
  • 女士的玩具推文_杜小灵白月光杜雪必读文_小说后续在线阅读_无删减免费完结_

    关于我们 | 我要投稿 | 免责申明

    Copyright © 2020-2022 ZhangShiYu.com Rights Reserved.豫ICP备2022013469号-1