0

I have a region of an image selected, like this:

http://slideplayer.com/4593320/15/images/9/Intelligent+scissors+http%3A%2F%2Frivit.cs.byu.edu%2FEric%2FEric.html.jpg

and now, using OpenCV I would like to extract the region selected.

How could I do it? I have already researched but nothing useful got.

Thanks in advance.

Antman
  • 453
  • 2
  • 8
  • 18
  • How do you "have it selected"? Please, elaborate... – Dan Mašek Jan 05 '18 at 17:58
  • I have the list of points that make the selected region . – Antman Jan 05 '18 at 18:01
  • In case you want to automatically select the region, the problem is called image segmentation. There are few deep learning techniques you can use to achieve this. https://www.kaggle.com/c/carvana-image-masking-challenge – pratsJ Jan 06 '18 at 03:07

1 Answers1

1

First of all you have to import your pixel locations into the program and you have to create contour object using the points. I guess you know how to do this.

You can find from following link how to create contour object:

Creating your own contour in opencv using python

You can fill black using following code out of your selected image

black = np.zeros(img.shape).astype(img.dtype)
color = [1, 1, 1]
cv2.fillPoly(black, contours, color)
new_img = img * black

I guess you know (or find) how to crop after black out remaining image using contour pixels.

verdery
  • 489
  • 1
  • 6
  • 20