Another newbie question here. I’m running object recognition on an android phone. This code came from a tutorial:
extern "C" void Detect(Circle * outFaces, int maxOutFacesCount, int& outDetectedFacesCount)
{
Mat frame;
_capture >> frame;
if (frame.empty())
return;
std::vector<Rect> faces;
Mat grayscaleFrame;
cvtColor(frame, grayscaleFrame, COLOR_BGR2GRAY);
Mat resizedGray;
resize(grayscaleFrame, resizedGray, Size(frame.cols / _scale, frame.rows / _scale));
equalizeHist(resizedGray, resizedGray);
_faceCascade.detectMultiScale(resizedGray, faces);
for (size_t i = 0; i < faces.size(); i++)
{
Point center(_scale * (faces[i].x + faces[i].width / 2), _scale * (faces[i].y + faces[i].height / 2));
ellipse(frame, center, Size(_scale * faces[i].width / 2, _scale * faces[i].height / 2), 0, 0, 360, Scalar(0, 0, 255), 4, 8, 0);
outFaces[i] = Circle(faces[i].x, faces[i].y, faces[i].width / 2);
outDetectedFacesCount++;
if (outDetectedFacesCount == maxOutFacesCount)
break;
}
imshow(_windowName, frame);
}
Googling has shown me that it’s stopping at cvtColor. My logcat shows this:
44-22270/? E/cv::error(): OpenCV(4.5.3-pre) Error: Unspecified error (> Invalid number of channels in input image:
> 'VScn::contains(scn)'
> where
> 'scn' is 1
) in cv::impl::(anonymous namespace)::CvtHelper<cv::impl::(anonymous namespace)::Set<3, 4, -1>, cv::impl::(anonymous namespace)::Set<1, -1, -1>, cv::impl::(anonymous namespace)::Set<0, 2, 5>, cv::impl::(anonymous namespace)::NONE>::CvtHelper(cv::InputArray, cv::OutputArray, int) [VScn = cv::impl::(anonymous namespace)::Set<3, 4, -1>, VDcn = cv::impl::(anonymous namespace)::Set<1, -1, -1>, VDepth = cv::impl::(anonymous namespace)::Set<0, 2, 5>, sizePolicy = cv::impl::(anonymous namespace)::NONE], file C:\Users\mjpg7\nxxxx-pxxxxx\OpenCV\opencv-master\modules\imgproc\src/color.simd_helpers.hpp, line 92
2021-06-14 14:03:10.692 22244-22270/? E/CRASH: signal 6 (SIGABRT), code -1 (?), fault addr --------
(that’s the beginning and hopefully the important part)
Is there something wrong with that call to cvtColor as it stands for the current version of OpenCV? All it’s doing is reading my phone camera (and freezing no matter what), the front one.