Convert CV_8UC4 to CV_8UC3,in openCV4Android?
Here src is an instance of Mat and it's type is CV_8UC4.I want to use src as first parameter of watershed:
public static void watershed(Mat image, Mat markers)
In about first parameter of watershed,Docs say:
Parameters:
image - Input 8-bit 3-channel image.
So I have to convert src from CV_8UC4 to CV_8UC3.I used this to convert src type:
src.convertTo(src, CvType.CV_8UC3);
But after that,when I debug code,type of src is CV_8UC4 yet and no CV_8UC3.Did I do any thing wrong?And how I can convert it's type?
Aside from using
cvtColorinstead ofconvertTo, keep in mind that because convertingCV_8UC4toCV_8UC3is a shape-changing operation (the total number of elements will change, and hence a memory reallocation may have taken place), that it is probably bad idea to use the same handlesrcas both the source and the destination. Because of this,cvtColorshould be called with two distinct handlessrcandtemp, and then after the operation thetemphandle can be assigned back tosrc. (My use of the word "handle" refers to Handle-Body Idiom, which is applicable to smart-pointers and Java references.)