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,
And I just want to remove the shape, something like this (I reshape the image in Photoshop),
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 ') resulting file, Code> Click on the edges , looks like this: The next step, if you want to extract the coordinates of the edges. It can be done with: The grayscale approach shows many internal structures of flowers. Whether it is good or bad depends on your objectives. 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)
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:
Comments
Post a Comment