How to find the shape of an object in an image using python -


I want to know how to find an object's shape in the image and store it in a variable for further use For example,

Enter image details here

And I just want to remove the shape, something like this (I reshape the image in Photoshop),

 Image Description Here

Only me of the image Need Uprekha, and I want it to save on disk. I have not tried so far, and I am using Python 2.7

Any suggestion is welcome

Thank you in advance!

I do not recommend grayscale for your image. You are interested in red flowers versus green background. To identify any pixels with flowers, there is a simple and clear way to create that difference in your image, whose red value is more than its green value. Imported from Numpy import array, cv2img = cv2.imread ('flower.jpg') img2 = array (200 * (IMG [:,:, 2] & gt; IMG [:,:, 1]), dtype = ' uint8 ')

img2 clearly shows the shape of the flower to achieve only the edges, you can use a very sharp detector :

  edges = cv2.Canny (img2, 70, 50) cv2.imwrite ('edges.png', edges)   

resulting file, Code> Click on the edges , looks like this:

Enter the image details hereT

The next step, if you want to extract the coordinates of the edges. It can be done with:

  framework, hierarchy = cv2.findContours (edges, cv2.RETR_LIST, cv2.CHAIN_APPROX_SIMPLE)   

Cv2.canny and cv2.findContours and, respectively, can be found.

More: What happens if you use grayscale:
  img = cv2.imread ('flower.jpg', cv2.CV_LOAD_IMAGE_GRAYSCALE) gray1 = cv2 The result image is:  

The grayscale approach shows many internal structures of flowers. Whether it is good or bad depends on your objectives.

Comments

Popular posts from this blog

Java - Error: no suitable method found for add(int, java.lang.String) -

java - JPA TypedQuery: Parameter value element did not match expected type -

c++ - static template member variable has internal linkage but is not defined -