Ask Your Question

neojh's profile - activity

2017-03-12 00:13:14 -0500 received badge  Enthusiast
2017-03-05 21:49:00 -0500 commented answer Opencv Python 3.2: How to get freeman chain code from edge/contours

Regarding to the contour detection, as you said, if the object is not closed then duplications might be understood. However, I tried another example which is closed, as below:

test_image = np.array([
[0, 0, 0, 0, 0, 0, 0, 0, 0, 0],
[0, 0, 1, 0, 0, 0, 0, 0, 0, 0],
[0, 1, 0, 1, 0, 0, 0, 0, 0, 0],
[0, 1, 0, 0, 1, 0, 0, 0, 1, 1],
[0, 1, 0, 0, 1, 0, 0, 1, 0, 1],
[0, 1, 0, 0, 0, 1, 1, 0, 0, 1],
[0, 1, 0, 0, 0, 0, 0, 0, 0, 1],
[0, 1, 1, 0, 1, 1, 1, 1, 1, 1],
[0, 0, 0, 1, 0, 0, 0, 0, 0, 0],
[0, 0, 0, 0, 0, 0, 0, 0, 0, 0],

], dtype=np.uint8)

Then the contours still contains lots of duplications:

[2, 1],[1, 2],[1, 3],[1 ... (more)

2017-03-05 04:12:15 -0500 asked a question Opencv Python 3.2: How to get freeman chain code from edge/contours

I'm trying to get Freeman chain code from binary image/edge by using Python version of OpenCV 3.2. However, it seems this feature is not yet implemented in Python. By now, there are just possible method: CHAIN_APPROX_NONE, CHAIN_APPROX_SIMPLE, CHAIN_APPROX_TC89_KCOS and CHAIN_APPROX_TC89_L1. Is it right? Anybody has same requirements as mine?

Another question related to the findContours function. Let's assume I created 10x10 images with numpy array as following:

np.array([
[0, 0, 0, 0, 0, 0, 0, 0, 0, 0],
[0, 0, 1, 0, 0, 0, 0, 0, 0, 0],
[0, 1, 0, 1, 0, 0, 0, 0, 0, 0],
[0, 1, 0, 0, 1, 0, 0, 0, 1, 1],
[0, 0, 0, 0, 1, 0, 0, 1, 0, 0],
[0, 0, 0, 0, 0, 1, 1, 0, 0, 0],
[0, 0, 0, 0, 0, 0, 0, 0, 0, 0],
[0, 0, 0, 0, 0, 0, 0, 0, 0, 0],
[0, 0, 0, 0, 0, 0, 0, 0, 0, 0],
[0, 0, 0, 0, 0, 0, 0, 0, 0, 0],

], dtype=np.uint8)

cv2.findContours(test_image.copy(), cv2.RETR_EXTERNAL, cv2.CHAIN_APPROX_NONE)

Returned list coordinate contains lots duplication:

   [[[2, 1]],

   [[1, 2]],

   [[1, 3]],

   [[1, 2]],

   [[2, 1]],

   [[3, 2]],

   [[4, 3]],

   [[4, 4]],

   [[5, 5]],

   [[6, 5]],

   [[7, 4]],

   [[8, 3]],

   [[7, 4]],

   [[6, 5]],

   [[5, 5]],

   [[4, 4]],

   [[4, 3]],

   [[3, 2]]]

Anyone can explain why there are so many duplications, and the order of coordinate seems very mess. Thanks!