Ask Your Question

Revision history [back]

click to hide/show revision 1
initial version

Segmenting two contours into two different images of same size using openCV-python

I have two contours in the first image:input image .

I need to segment out individual contours and make two images out of it like this: Image 1

and

image2.

The individual output image has to be of the same dimension as the input image. How can this be achieved using openCV-python ? My code for drawing contours:

image, contours, hier = cv2.findContours(im, cv2.RETR_EXTERNAL, cv2.CHAIN_APPROX_SIMPLE)
for c in contours:
rect = cv2.minAreaRect(c)
box = cv2.boxPoints(rect)
# convert all coordinates floating point values to int
box = np.int0(box)
# draw a red 'nghien' rectangle
cv2.drawContours(im, [box], 0, (0, 0, 255))
cv2.drawContours(im, contours, -1, (255, 255, 0), 1)

Segmenting two contours into two different images of same size using openCV-python

I have two contours in the first image:input image .

I need to segment out individual contours and make two images out of it like this: Image 1

and

image2.

The individual output image has to be of the same dimension as the input image. How can this be achieved using openCV-python ? My code for drawing contours:

image, contours, hier = cv2.findContours(im, cv2.RETR_EXTERNAL, cv2.CHAIN_APPROX_SIMPLE)
for c in contours:
rect = cv2.minAreaRect(c)
box = cv2.boxPoints(rect)
# convert all coordinates floating point values to int
box = np.int0(box)
# draw a red 'nghien' rectangle
cv2.drawContours(im, [box], 0, (0, 0, 255))
cv2.drawContours(im, contours, -1, (255, 255, 0), 1)

Segmenting two contours into two different images of same size using openCV-python

I have two contours in the first image:input image .

I need to segment out individual contours and make two images out of it like this: Image 1

and

image2.

The individual output image has to be of the same dimension as the input image. How can this be achieved using openCV-python ? My code for drawing contours:

image, contours, hier = cv2.findContours(im, cv2.RETR_EXTERNAL, cv2.CHAIN_APPROX_SIMPLE)
for c in contours:
rect = cv2.minAreaRect(c)
box = cv2.boxPoints(rect)
# convert all coordinates floating point values to int
box = np.int0(box)
# draw a red 'nghien' rectangle
cv2.drawContours(im, [box], 0, (0, 0, 255))
cv2.drawContours(im, contours, -1, (255, 255, 0), 1)

Segmenting two contours into two different images of same size using openCV-python

I have two contours in the first image:input image .

I need to segment out individual contours and make two images out of it like this: Image 1

and

image2.

The individual output image has to be of the same dimension as the input image. How can this be achieved using openCV-python ? My code for drawing contours:

image, contours, hier = cv2.findContours(im, cv2.RETR_EXTERNAL, cv2.CHAIN_APPROX_SIMPLE)
for c in contours:
rect = cv2.minAreaRect(c)
box = cv2.boxPoints(rect)
# convert all coordinates floating point values to int
box = np.int0(box)
# draw a red 'nghien' rectangle
cv2.drawContours(im, [box], 0, (0, 0, 255))
cv2.drawContours(im, contours, -1, (255, 255, 0), 1)

Segmenting two contours into two different images of same size using openCV-python

I have two contours in the first image:input image .

I need to segment out individual contours and make two images out of it like this: Image 1

and

image2.

The individual output image has to be of the same dimension as the input image. How can this be achieved using openCV-python ? My code for drawing contours:

image, contours, hier = cv2.findContours(im, cv2.RETR_EXTERNAL, cv2.CHAIN_APPROX_SIMPLE)
for c in contours:
rect = cv2.minAreaRect(c)
box = cv2.boxPoints(rect)
# convert all coordinates floating point values to int
box = np.int0(box)
# draw a red 'nghien' rectangle
cv2.drawContours(im, [box], 0, (0, 0, 255))
cv2.drawContours(im, contours, -1, (255, 255, 0), 1)