Quantcast
Channel: OpenCV Q&A Forum - RSS feed
Viewing all articles
Browse latest Browse all 2088

How to clip an image by extreme points?

$
0
0
Hello, I have found the contours of the object in the image with a cv2.findContours and I want to clip the image in the extreme points. However, the image returned is not correct. Below is the code, I have implemented. Any hint? def clipping_image( image ): ''' Clip segmented imaged based on the contours of the leaf ''' image = cv2.cvtColor( image, cv2.COLOR_BGR2GRAY ); segmented, contours, hierarchy = cv2.findContours(image, cv2.RETR_TREE, cv2.CHAIN_APPROX_SIMPLE) cnt = contours[0] xmin = min(tuple(cnt[cnt[:, :, 0].argmin()][0])) ymin = min(tuple(cnt[cnt[:, :, 1].argmin()][0])) xmax = max(tuple(cnt[cnt[:, :, 0].argmax()][0])) ymax = max(tuple(cnt[cnt[:, :, 1].argmax()][0])) clipped = segmented[xmin:xmax, ymin:ymax] return clipped Thank you

Viewing all articles
Browse latest Browse all 2088

Trending Articles