# Revision history [back]

### OpenCV does not detect the my rectangle

Hello, im new on OpenCV.

I Have a picture like this;

I wrote code like this;

        image = cv2.imread("photos/testtt.png")
gray = cv2.cvtColor(image, cv2.COLOR_BGR2GRAY)
edged = cv2.Canny(image, 170, 490)
(cnts, _) = cv2.findContours(edged.copy(), cv2.RETR_EXTERNAL, cv2.CHAIN_APPROX_SIMPLE)
idx = 0
for c in cnts:
x,y,w,h = cv2.boundingRect(c)
if w>50 and h>50:
idx+=1
new_img=image[y:y+h,x:x+w]
cv2.imwrite(str(idx) + '.png', new_img)
cv2.imshow("im",image)
cv2.waitKey(0)


There are rectangles in the photo, but this code I wrote does not detect these rectangles. I guess I'm not sure, as it leaves very thinly.

I would be very grateful if you could help me, good day everyone.

### OpenCV does not detect the my rectangle

Hello, im new on OpenCV.

I Have a picture like this;

I wrote code like this;

        image = cv2.imread("photos/testtt.png")
gray = cv2.cvtColor(image, cv2.COLOR_BGR2GRAY)
edged = cv2.Canny(image, 170, 490)
(cnts, _) = cv2.findContours(edged.copy(), cv2.RETR_EXTERNAL, cv2.CHAIN_APPROX_SIMPLE)
idx = 0
for c in cnts:
x,y,w,h = cv2.boundingRect(c)
if w>50 and h>50:
idx+=1
new_img=image[y:y+h,x:x+w]
cv2.imwrite(str(idx) + '.png', new_img)
cv2.imshow("im",image)
cv2.waitKey(0)


There are rectangles in the photo, but this code I wrote does not detect these rectangles. I guess I'm not sure, as it leaves very thinly.

I would be very grateful if you could help me, good day everyone.