Hi,
For this colour detection program I’m writing, I essentially convert an image to HSV and mask it to detect yellow (so white where yellow is, black otherwise) & then simply see if a given pixel is white or not.
const cv::Mat roiImage = // read in image ... ;
cv::Mat tmpMask ;
cv::cvtColor(roiImage, tmpMask, cv::COLOR_BGR2HSV) ;
cv::inRange(tmpMask, cv::Scalar(20, 100, 100), cv::Scalar(30, 255, 255), tmpMask) ;
Problem is, to see if a given pixel is white in value, I try to convert it back to BGR, but opencv keeps throwing an error regarding the fact HSV has one channel, BGR has 3.
cv::Mat yellowMask ; cv::cvtColor(tmpMask, yellowMask, cv::COLOR_HSV2BGR) ;
// ^ error here
terminate called after throwing an instance of 'cv::Exception'
what(): OpenCV(4.2.0) ../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>; VDcn = cv::impl::{anonymous}::Set<3, 4>; VDepth = cv::impl::{anonymous}::Set<0, 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
The only work around I’ve found is to write the HSV mask externally (ie save it as an image) and then read it in, and presto that works, but is horribly inefficient.
How can I find a workaround for this issue? Thanks for your time