0

I have two UIImageViews. The first one is in the background and contains an image. The second one is in the foreground and it is to be used so that the user can trace out a portion of what he sees in the background.

After the user traces the area I want the program to be able to fill in that polygon with my chosen colour slightly transparent so you can see the image beneath the polygon.

What I have accomplished so far is the ability to show the images and have the user do the tracing. I can use a floodfill to fill in the polygon black but the area on the outside is white, instead of being transparent. Here is what I do:

cv::Mat input = [traceImageView.image CVMat];
cv::Mat output, finalOutput, mask;
cv::Rect rect;

cv::cvtColor(input, output, cv::COLOR_RGB2GRAY);
cv::floodFill(output, cv::Point(0, 0), cv::Scalar(255,0,0,0), &rect, cv::Scalar(0,0,0), cv::Scalar(0,0,0));

traceImageView.image = [UIImage imageWithCVMat:output];

And here is what the output looks like:

output
(source: mulvaandgipple.com)

The result is that the front image completely covers the image behind it. I want the white on the outside of the polygon to be transparent. Any ideas on how to do this?

Community
  • 1
  • 1
fawsha1
  • 780
  • 8
  • 13
  • Have you tried to play around with the Photoshop blendingmodes: http://stackoverflow.com/questions/5919663/how-does-photoshop-blend-two-images-together ? – Maecky Nov 10 '12 at 08:53
  • I'm writing a program using opencv. Photoshop won't help me. – fawsha1 Nov 11 '12 at 22:39
  • Yes I know, but you can play around with the blending modes in Photoshop to test if some of these operations might help you. And in the link i posted you can implement the blend modes used in Photoshop in OpenCV. I think that probably one of these blend modes might solve your problems... Here is a second link, where you can see example images: http://www.barbato.us/2010/12/01/blimageblending-emulating-photoshops-blending-modes-opencv/ – Maecky Nov 12 '12 at 11:00

0 Answers0