Applying a mask to a Mat object in OpenCV for java

asked 2013-11-12 00:53:45 -0500

I'm trying to apply a mask to a photo:

Mat img = Highgui.imread( "/path/to/my/image.png" );

Mat mask = new Mat( new Size( img.cols(), img.rows() ), CvType.CV_8UC1 );
mask.setTo( new Scalar( 0.0 ) );

// Rect r = ...;
Core.ellipse( mask, new Point( r.x + ( r.width / 2 ), r.y + ( r.height / 2 ) ), new Size( r.width / 2, ( r.height ) / 2 ), 0.0, 0.0, 360.0, new Scalar( 255.0 ), 5 );

// Mat res = ...;
img.copyTo( res, mask );

But I always end up with res containing exactly the same image as img...

edit retag flag offensive close merge delete