Ask Your Question

Revision history [back]

click to hide/show revision 1
initial version

Android java convertTo

Hi!

I'm trying to use watershed in android. To do so I need a mask of 32f. I have an image with the zones that I want for the watershed, but it is in RGB. I have tried convertTo but it doesn't work. I have done the following test to try the conversion:

Mat maskColor = new Mat( mBitmapPintar.getHeight(), mBitmapPintar.getWidth(), CvType.CV_8UC3);
Mat maskgris = new Mat( maskColor.rows(), maskColor.cols(), CvType.CV_8U );
Mat mask = new Mat( maskColor.rows(), maskColor.cols(), CvType.CV_32S);

maskColor contains the original mask in RGB. I have maskgris to bridge the conversion (it didn't work straight ahead). Now I convert it in gray, then to 32S, back to gray to visualize it and it doesn't work:

Imgproc.cvtColor( maskColor, maskgris, Imgproc.COLOR_BGR2GRAY);
Highgui.imwrite(directoriFitxer + "/maskengris.jpg", maskgris);
mask.convertTo( maskgris, CvType.CV_32F);
maskgris.convertTo(mask,  CvType.CV_8U);
Highgui.imwrite(directoriFitxer + "/maskengrisDespConv.jpg", maskgris);

When I check the two images, the last one maskengrisDespConv.jpg is all in black. What am I doing wrong?