Ask Your Question

stack-o-frankie's profile - activity

2020-02-18 06:49:17 -0600 received badge  Notable Question (source)
2017-05-04 01:54:23 -0600 received badge  Popular Question (source)
2013-11-12 00:53:45 -0600 asked a question Applying a mask to a Mat object in OpenCV for java

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...