Revision history [back]

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

I have two contours in the first image: .

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

and

.

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: .

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

and

.

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: .

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

and

.

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: .

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

and

.

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)

 5 retagged sturkmen 6772 ●3 ●48 ●79 https://github.com/stu...

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

I have two contours in the first image: .

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

and

.

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)