繁体   English   中英

错误:OpenCV 3.4.0 CUDA ORB功能检测

[英]Error: OpenCV 3.4.0 CUDA ORB feature detection

我正在使用ORB检测器检测视频帧的关键点,但是它给了我以下错误:

OpenCV Error: Assertion failed (img.type() == (((0) & ((1 << 3) - 1)) + (((1)-1) << 3))) in detectAsync

ORB检测器的CPU功能正常运行。 但是对于GPU,它无法检测到图像的关键点。 我也尝试过使用CUDA的FastFeatureDetector ,但它也失败了。

我在下面附上我的代码:

int main()
{
   cv::VideoCapture input("/home/admin/Pictures/cars.mp4");

   // Create image matrix
   cv::Mat img,desc;
   cv::cuda::GpuMat obj1;

   // create vector keypoints
   std::vector<cv::KeyPoint>keypoints;

   // create keypoint detector
   cv::Ptr<cv::cuda::ORB> detector = cv::cuda::ORB::create();

   for(;;)
   {
       if(!input.read(img))
           break;
       obj1.upload(img);
       detector->detect(obj1,keypoints, cv::cuda::GpuMat());
       obj1.download(desc);
       //Create cricle at keypoints
       for(size_t i=0; i<keypoints.size(); i++)
          cv::circle(desc, keypoints[i].pt, 2,cv::Scalar(0,0,255),1);

       // Display Image
       cv::imshow("img", desc);
       char c = cv::waitKey();

       // NOTE: Press any key to run the next frame
       // Wait for a key to press
       if(c == 27) // 27 is ESC key code
           break;
    }
}

主要问题是检测器将CV_8UC1作为Mat的输入格式。 但是我的图像格式是CV_8UC3。 我尝试使用img.convertTo(img1, CV_8UC1)转换该图像img.convertTo(img1, CV_8UC1)但仍无法处理,并向我抛出错误OpenCV Error: Bad flag (parameter or structure field) (Unrecognized or unsupported array type) in cvGetMat img.convertTo(img1, CV_8UC1)的错误OpenCV Error: Bad flag (parameter or structure field) (Unrecognized or unsupported array type) in cvGetMat

您必须将图像从CV_8UC3-3通道图像转换为CV_8UC1-单通道(灰度)图像。 为此,只需致电

cv::cvtColor(img, img, cv::BGR2GRAY);

在将数据上传到GPU之前。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM