Ask Your Question

arp1561_ans's profile - activity

2020-02-10 04:07:49 -0600 received badge  Famous Question (source)
2019-01-21 20:37:51 -0600 received badge  Notable Question (source)
2018-06-19 07:25:31 -0600 received badge  Popular Question (source)
2017-08-01 18:47:31 -0600 received badge  Student (source)
2015-11-28 03:47:36 -0600 commented answer Contour approximation not working correctly

Please keep this question active.

I really need to figure out what the problem is. I really hope you can help me out

2015-11-28 00:43:00 -0600 commented answer Contour approximation not working correctly

And even if i use poly lines instead of drawContours(), it gives me the same output

2015-11-28 00:38:20 -0600 commented answer Contour approximation not working correctly

For me, it does not create a proper circle.

import cv2
import numpy as np

im = cv2.imread("circle.png")
img = im
img = cv2.cvtColor(img,cv2.COLOR_BGR2GRAY)
ret,thresh = cv2.threshold(img,127,255,cv2.THRESH_BINARY)

(_,cnts,_) = cv2.findContours(thresh,cv2.RETR_EXTERNAL,cv2.CHAIN_APPROX_NONE)

print len(cnts)
cnt=cnts[0]
hull = cv2.convexHull(cnt)
cv2.drawContours(im,hull,-1,(0,255,0),3)

cv2.imshow("img",im)
cv2.waitKey(0)
cv2.destroyAllWindows()

This is how mine looks like http://postimg.org/image/igdb1270x/76...

2015-11-28 00:25:56 -0600 commented answer Contour Approximation OpenCV

I still dont get a line around the rectangle

import cv2
import numpy as np

im = cv2.imread("badrect.png")
img = im
img = cv2.cvtColor(img,cv2.COLOR_BGR2GRAY)
ret,thresh = cv2.threshold(img,127,255,cv2.THRESH_BINARY)

(_,cnts,_) = cv2.findContours(thresh,cv2.RETR_TREE,cv2.CHAIN_APPROX_NONE)

cnt = cnts[1]
hull = cv2.convexHull(cnt)
cv2.drawContours(im,hull,-1,(0,255,0),3)

cv2.imshow("img",im)
cv2.waitKey(0)
cv2.destroyAllWindows()

Here -> This is how it looks http://postimg.org/image/o9zuq40hl/23...

If you could help me, that would be great since i am stuck here for a very long time

2015-11-27 08:55:09 -0600 asked a question Contour Approximation OpenCV

I am using opencv for python. For a bad shape, we use approxpolyDP().For this, I created a bad rectangle(added to the post)

While using this, I only get 2 dots and not a proper rectangle.

Can anyone help me why this is happening?

import cv2
import numpy as np

im = cv2.imread("badrect.png")
img = im
img = cv2.cvtColor(img,cv2.COLOR_BGR2GRAY)
canny = cv2.Canny(img,100,200)


(_,cnts,_) = cv2.findContours(canny,cv2.RETR_TREE,cv2.CHAIN_APPROX_NONE)

cnt = cnts[0]

epsilon = 0.1*cv2.arcLength(cnt,True)
approx = cv2.approxPolyDP(cnt,epsilon,True)

cv2.drawContours(im,approx,-1,(0,255,0),3)

cv2.imshow("img",im)
cv2.waitKey(0)
cv2.destroyAllWindows()

This is how the output comes out as

This is how the output comes out as

This is my desired result This is my desired result!