Ask Your Question
0

Why are contours points stored two times(Contour clockwise and then in clockwise) in numpy array?

asked 2017-09-04 01:56:45 -0600

Santhosh1 gravatar image

I want to know how the the contours are stored in opencv. The stored points seems to be like stack. Where in the last object detected is the first object that is printed out.

Here we can see that the points are first stored in the contour clockwise direction the first time, and then in the clockwise direction the second time round

ORIGINAL IMAGE

ORIGINAL IMAGE

PROCESSED IMAGE

PROCESSED IMAGE

Here the python code

import cv2
import numpy as np

s_img = cv2.imread("SimpleShape.jpg")

e_img = cv2.Canny(s_img,1,10)

im2, contours, hi =cv2.findContours(e_img,cv2.RETR_TREE,cv2.CHAIN_APPROX_NONE)

print(contours)

Output:

(I'll only show the first object that this prints as the list is very long)

[array([[[126, 279]],

   [[125, 280]],

   [[124, 281]],

   [[124, 282]],

   [[124, 283]],

   [[123, 284]],

   [[122, 284]],

   [[121, 284]],

   [[120, 284]],

   [[119, 284]],

   [[118, 284]],

   [[117, 284]],

   [[116, 284]],

   [[115, 285]],

   [[114, 286]],

   [[114, 287]],

   [[114, 288]],

   [[115, 289]],

   [[116, 289]],

   [[117, 289]],

   [[118, 289]],

   [[119, 289]],

   [[120, 289]],

   [[121, 289]],

   [[122, 289]],

   [[123, 289]],

   [[124, 289]],

   [[125, 289]],

   [[126, 289]],

   [[127, 289]],

   [[128, 289]],

   [[129, 289]],

   [[129, 288]],

   [[129, 287]],

   [[129, 286]],

   [[129, 285]],

   [[129, 284]],

   [[129, 283]],

   [[129, 282]],

   [[129, 281]],

   [[129, 280]],

   [[128, 279]],

   [[127, 279]]], dtype=int32), array([[[125, 280]],

   [[126, 279]],

   [[127, 279]],

   [[128, 279]],

   [[129, 280]],

   [[129, 281]],

   [[129, 282]],

   [[129, 283]],

   [[129, 284]],

   [[129, 285]],

   [[129, 286]],

   [[129, 287]],

   [[129, 288]],

   [[128, 289]],

   [[127, 289]],

   [[126, 289]],

   [[125, 289]],

   [[124, 289]],

   [[123, 289]],

   [[122, 289]],

   [[121, 289]],

   [[120, 289]],

   [[119, 289]],

   [[118, 289]],

   [[117, 289]],

   [[116, 289]],

   [[115, 289]],

   [[114, 288]],

   [[114, 287]],

   [[114, 286]],

   [[115, 285]],

   [[116, 284]],

   [[117, 284]],

   [[118, 284]],

   [[119, 284]],

   [[120, 284]],

   [[121, 284]],

   [[122, 284]],

   [[123, 284]],

   [[124, 284]],

   [[124, 283]],

   [[124, 282]],

   [[124, 281]]], dtype=int32), array([[[ 61, 269]],
edit retag flag offensive close merge delete

1 answer

Sort by ยป oldest newest most voted
3

answered 2017-09-04 04:33:43 -0600

Ziri gravatar image

by using RETR_TREE you're getting internal and external contours. Try RETR_EXTERNAL .

edit flag offensive delete link more

Comments

@Ziri Thank You ๐Ÿ˜…

Here the official explanation for others Contour Retrieval Mode

Santhosh1 gravatar imageSanthosh1 ( 2017-09-04 04:55:26 -0600 )edit

Question Tools

1 follower

Stats

Asked: 2017-09-04 01:56:45 -0600

Seen: 1,807 times

Last updated: Sep 04 '17