错误:OpenCV 3.4.0 CUDA ORB功能检测

时间:2019-01-10 12:25:36

标签: c++ opencv computer-vision

我正在使用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)转换该图像,但仍然无法处理,并抛出错误OpenCV Error: Bad flag (parameter or structure field) (Unrecognized or unsupported array type) in cvGetMat

1 个答案:

答案 0 :(得分:0)

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

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

在将数据上传到GPU之前。

相关问题