【问题标题】:Feature extraction and Matching with Cuda/Opencv/Python使用 Cuda/Opencv/Python 进行特征提取和匹配
【发布时间】:2022-10-14 05:23:57
【问题描述】:

我分享了一个使用 ORB 进行特征提取和匹配的工作代码,我的问题是我需要让它与两个以上的图像一起工作,有人可以帮助我吗? ()

from distutils.command.upload import upload
import cv2
import numpy as np

GOOD_MATCH_PERCENT = 0.15
max_features = 9000
orb = cv2.cuda_ORB.create(max_features)
matcherGPU = cv2.cuda.DescriptorMatcher_createBFMatcher(cv2.NORM_HAMMING)
# Read the images as normal
npMat1 = cv2.imread("C:\Users\Geddy\Desktop\0.png")
npMat2 = cv2.imread("C:\Users\Geddy\Desktop\1.png")#cv2.imread("path_to_reference_image")

# Load the images onto the GPU
cuMat1 = cv2.cuda_GpuMat()
cuMat2 = cv2.cuda_GpuMat()
cuMat1.upload(npMat1)
cuMat2.upload(npMat2)

# Convert the color on the GPU
cuMat1 = cv2.cuda.cvtColor(cuMat1, cv2.COLOR_BGR2GRAY)
cuMat2 = cv2.cuda.cvtColor(cuMat2, cv2.COLOR_BGR2GRAY)
 
# Create the CUDA ORB detector and detect keypoints/descriptors
kps1, descs1 = orb.detectAndComputeAsync(cuMat1, None) # Both are returned as GPU Mats
kps2, descs2 = orb.detectAndComputeAsync(cuMat2, None)
matches = matcherGPU.match(descs1, descs2)
matches2=sorted(matches,key=lambda x: x.distance, reverse=False)
numGoodMatches = int(len(matches2) * GOOD_MATCH_PERCENT)
matches2 = matches2[:numGoodMatches]  
kps1c = orb.convert(kps1)
kps2c = orb.convert(kps2)
imMatches = cv2.drawMatches(npMat1, kps1c, npMat2, kps2c, matches2, None)
cv2.imwrite("gpu_matches.jpg", imMatches)  

【问题讨论】:

  • 你有什么问题?

标签: python opencv cuda


【解决方案1】:

您是否正在尝试制作视觉里程计算法?我有同样的疑问 1 个月,我不知道如何使用 CUDA 制作视觉里程计算法,它在 CPU 上完美运行,但是当我使用 CUDAI 时得到这个

cv2.error: OpenCV(4.5.2) :-1: error: (-5:Bad argument) in function 'GpuMat'

重载解析失败:

  • 参数“分配器”的预期 Ptr<cv::cuda::GpuMat::Allocator>
  • GpuMat() 缺少必需的参数“cols”(位置 2)
  • GpuMat() 缺少必需的参数“类型”(位置 2)
  • GpuMat() 缺少必需的参数“cols”(位置 2)
  • GpuMat() 缺少必需的参数“类型”(位置 2)
  • 参数“m”的预期 Ptr<cv::cuda::GpuMat>
  • GpuMat() 缺少必需的参数“rowRange”(位置 2)
  • GpuMat() 缺少必需的参数“roi”(位置 2)
  • arr 不是 numpy 数组,也不是标量
  • 参数 'arr' 的预期 Ptr<cv::cuda::GpuMat>
  • 参数“arr”的预期 Ptr<cv::UMat>

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2014-04-04
    • 2013-07-31
    • 1970-01-01
    • 2018-04-27
    • 1970-01-01
    • 2012-07-22
    • 2014-03-16
    • 1970-01-01
    相关资源
    最近更新 更多