Invalid number of channels in input image: 'VScn::contains(scn)' 'scn' is 1 [closed]

asked 2019-11-02 22:35:03 -0500

HelloWorld gravatar image

updated 2019-11-04 21:36:22 -0500

supra56 gravatar image

This is error:

terminate called after throwing an instance of 'cv::Exception' what(): OpenCV(4.1.2-dev) /home/ztftrue/Downloads/opencv/modules/imgproc/src/color.simd_helpers.hpp:92: error: (-2:Unspecified error) in function 'cv::impl::{anonymous}::CvtHelper<vscn, vdcn,="" vdepth,="" sizepolicy="">::CvtHelper(cv::InputArray, cv::OutputArray, int) [with VScn = cv::impl::{anonymous}::Set<3, 4>; VDcn = cv::impl::{anonymous}::Set<1>; VDepth = cv::impl::{anonymous}::Set<0, 2, 5>; cv::impl::{anonymous}::SizePolicy sizePolicy = cv::impl::<unnamed>::NONE; cv::InputArray = const cv::_InputArray&; cv::OutputArray = const cv::_OutputArray&]'

Invalid number of channels in input image:

'VScn::contains(scn)'

where

'scn' is 1

Code :

> cv::Ptr<cv::FeatureDetector> detector = ORB::create();

> cv::Ptr<cv::DescriptorExtractor> extractor = ORB::create();

> cv::Ptr<cv::DescriptorMatcher> matcher = cv::DescriptorMatcher::create("BruteForce");

> cv::BOWImgDescriptorExtractor bowide(extractor, matcher);

> bowide.setVocabulary(vocabulary);

> bowide.compute(inputImage, keypoints, descriptors);

The vocabulary.type()==5

I try change inputImage channels 1(GARY) and 3(BGR) , but this error can't disappearance.

I have a very bad question. In addition to svm, can pytorch still use the key points of opencv? I learn by this https://www.learnopencv.com/mask-r-cn..., I don't know how to use the key points of opencv.

--------------update---------

cvtColor() Code :

> cv::Ptr<cv::FeatureDetector> detector = ORB::create();

> cv::Ptr<cv::DescriptorExtractor> extractor = ORB::create();

> cv::Ptr<cv::DescriptorMatcher> matcher = cv::DescriptorMatcher::create("BruteForce");

> cv::BOWImgDescriptorExtractor bowide(extractor, matcher);

> bowide.setVocabulary(vocabulary);


> cv::Mat descriptors;

> Mat inputImage(it);


> // cvtColor(it, it1, COLOR_BGR2GRAY);

> cvtColor(it, inputImage, COLOR_GRAY2BGR);

> cout << inputImage.channels() << endl;

> cout << inputImage.type() << endl;

> bowide.compute(inputImage, keypoints, descriptors);

Error:

terminate called after throwing an instance of 'cv::Exception' what(): OpenCV(4.1.2-dev) /home/ztftrue/Downloads/opencv/modules/imgproc/src/color.simd_helpers.hpp:92: error: (-2:Unspecified error) in function 'cv::impl::{anonymous}::CvtHelper<vscn, vdcn,="" vdepth,="" sizepolicy="">::CvtHelper(cv::InputArray, cv::OutputArray, int) [with VScn = cv::impl::{anonymous}::Set<1>; VDcn = cv::impl::{anonymous}::Set<3, 4>; VDepth = cv::impl::{anonymous}::Set<0, 2, 5>; cv::impl::{anonymous}::SizePolicy sizePolicy = cv::impl::<unnamed>::NONE; cv::InputArray = const cv::_InputArray&; cv::OutputArray = const cv::_OutputArray&]' Invalid number of channels in input image: 'VScn::contains(scn)' where 'scn' is 3

edit retag flag offensive reopen merge delete

Closed for the following reason the question is answered, right answer was accepted by berak
close date 2019-11-11 00:53:19.987865

Comments

unfortunately your code is incomplete and does not show any call to cvtColor() , but your error is from there (it complains, your image already has 1 channel only)

berak gravatar imageberak ( 2019-11-03 01:43:47 -0500 )edit

@break I update it, thank you.

HelloWorld gravatar imageHelloWorld ( 2019-11-03 03:19:35 -0500 )edit

why the cvtColor() at all ? just remove it

berak gravatar imageberak ( 2019-11-03 04:09:15 -0500 )edit

I use cv::imread("test.jpg",IMREAD_GRAYSCALE); . I try remove cvtColor() , but it can't not work . ```

Invalid number of channels in input image: 'VScn::contains(scn)' where 'scn' is 1 ```

HelloWorld gravatar imageHelloWorld ( 2019-11-03 09:37:58 -0500 )edit

i shoud use cv::imread( "test.jpg", IMREAD_COLOR);

HelloWorld gravatar imageHelloWorld ( 2019-11-10 04:43:36 -0500 )edit

please check, if your image was loaded AT ALL (is it None ?)

berak gravatar imageberak ( 2019-11-10 04:45:17 -0500 )edit
1

My images are all loaded. Now it has no errors. I should close this question .

HelloWorld gravatar imageHelloWorld ( 2019-11-10 20:15:20 -0500 )edit