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
cvtColor
instead ofconvertTo
, keep in mind that because convertingCV_8UC4
toCV_8UC3
is 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 handlesrc
as both the source and the destination. Because of this,cvtColor
should be called with two distinct handlessrc
andtemp
, and then after the operation thetemp
handle 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.)