Ask Your Question
0

Android java convertTo

asked 2012-11-08 05:59:20 -0500

Jep gravatar image

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?

edit retag flag offensive close merge delete

2 answers

Sort by ยป oldest newest most voted
5

answered 2012-11-09 02:42:06 -0500

Pay attention on mat data types and convertTo params:

source.convertTo(destination, type)

Fixed code:

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_32F);

Imgproc.cvtColor( maskColor, maskgris, Imgproc.COLOR_BGR2GRAY);
Highgui.imwrite(directoriFitxer + "/maskengris.jpg", maskgris);
maskgris.convertTo(mask, CvType.CV_32F);
mask.convertTo(maskgris, CvType.CV_8U);
Highgui.imwrite(directoriFitxer + "/maskengrisDespConv.jpg", maskgris);
edit flag offensive delete link more
1

answered 2012-12-14 03:11:29 -0500

V.G. gravatar image

If you believe, that this issue has been resolved, could you please accept the most appropriate answer (even if it's your own one) and close this question. It would greatly improve navigation and overall experience with OpenCV Q&A.

Thanks.

edit flag offensive delete link more
Login/Signup to Answer

Question Tools

Stats

Asked: 2012-11-08 05:59:20 -0500

Seen: 3,944 times

Last updated: Dec 14 '12