Invalid number of channels in input image: 'VScn::contains(scn)' 'scn' is 1 [closed]
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
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)@break I update it, thank you.
why the cvtColor() at all ? just remove it
I use
cv::imread("test.jpg",IMREAD_GRAYSCALE);
. I try remove cvtColor() , but it can't not work . ```i shoud use cv::imread( "test.jpg", IMREAD_COLOR);
please check, if your image was loaded AT ALL (is it None ?)
My images are all loaded. Now it has no errors. I should close this question .