OpenCV4Android: Extracting a MatOfPoint from a Canny image for input into convexHull
Hi,
I am trying to teach myself Eclipse (ADT), Java, Android and OpenCV all at the same time (!) and need a way in Java to extract a MatOfPoint from a Canny image for inputting into convexHull. Can anyone advise?
Thanks
bear with me for not knowing anything about android, but you can't get the convexHull from a Canny image directly. you need to findContours() from a binary image first ( and better try threshold() instead of canny ) , then you get a list of countours and can get the hull for one ore more of the contours.
Why is threshold() better than Canny()? Reading the documentation, it appears Canny() can be used on a colour image whereas threshold() works on a grayscale image. If I'm starting with a colour image why is it better to convert it to grayscale and use threshold()?
Thanks
Decided to go with the suggestion of using threshold() rather than Canny(). However when I try to convert the RGBA Mat to gray in preparation using "Imgproc.cvtColor(inRgbaMat, outGrayMat, Imgproc.COLOR_RGBA2GRAY);" all I get is a crash: OpenCV Error: Assertion failed (scn == 3 || scn == 4) in void cv::cvtColor(cv::InputArray, cv::OutputArray, int, int), file /home/reports/ci/slave/50-SDK/opencv/modules/imgproc/src/color.cpp, line 3326
Any advice?
inRgbaMat needs to be rgb or rgba. check if it's valid at all
How would I check that? inRgbaMat.size() returns 480x480 and inRgbaMat.type() returns 0. Does that help and, if so, what does it mean?
at least, a valid image(type()==0 <-> uchar). channels() ? maybe it is already grayscale
The original image (origMat) is created using CvCameraViewFrame.rgba() and inRgbaMat is then created using origMat.submat(), so I would expect it to be RGBA.