I have an image, and a selection given by a list of points (a poly). My goal is to get another image where everything except the selection is transparent.
There are two parts to this question:
* how to create the mask from the list of points?
* what’s the best way of creating the new image using the mask? I was thinking of cvCopy but how can I handle the alpha channel?
I had a simillar issue and I solved it in a strange (not very fast) way:
extractChannel).bitwise_andoperation between each of the channels and poygon mask image.mergefunction).Note that if you have one-channel image than you just need to do a
bitwise_and.C++ code:
You can create
polyMatmask usingfillPoly/fillConvexPolyfunctions (depends on your polygon). For example: