how can i upgrade the detection of cv.findContours [closed]

asked 2018-05-07 03:12:50 -0500

pinoy gravatar image

updated 2018-05-15 13:39:05 -0500

i have a problem about encountering a wrong detection with this image ..i've used the cv.equalizeHist to brighten my images but there are some images with darker corners so my code fails to the detect the square image.

here's my code:

img = cv2.imread("AR5890039763178.tif")

gray = cv2.cvtColor(img, cv2.COLOR_BGR2GRAY)

equ = cv2.equalizeHist(gray)

h,w,d= img.shape
rect_img = np.zeros((h,w), np.uint8)
# default thresh=120, maxval=100
# threshold to get just the signature
# a = cv2.Canny(gray, threshold1 = 0, threshold2 = 255, apertureSize = 3)
# gray = cv2.GaussianBlur(gray,(5,5),0)
# retval, b = cv2.threshold(gray, thresh=127, maxval=255, type=cv2.THRESH_BINARY)

ret3,mask = cv2.threshold(equ,77,255,cv2.THRESH_BINARY)
blurred = cv2.GaussianBlur(mask,(5,5),0)
masked_data = cv2.bitwise_not(rect_img, rect_img, mask=mask)


lst_area = []
lst_rect = []

(_,contours,_) = cv2.findContours(masked_data, cv2.RETR_EXTERNAL, cv2.CHAIN_APPROX_SIMPLE)

for contour in contours:
    area = cv2.contourArea(contour)
    rect = cv2.boundingRect(contour)
    lst_area.append((area))
    lst_rect.append((rect))



    crop_img = cv2.rectangle(img, (rect[0],rect[1]), (rect[2]+rect[0],rect[3]+rect[1]), (0,255,0), 2)


cv2.imwrite('test.tif',blurred)
edit retag flag offensive reopen merge delete

Closed for the following reason question is not relevant or outdated by sturkmen
close date 2020-09-22 02:19:07.290883

Comments

1

Add some code and image example.

lezan gravatar imagelezan ( 2018-05-07 05:35:32 -0500 )edit

OpenCV is an image processing library, not a text analysis tool ... like @lezan said, with code, images and wrong outputs, there is no way of telling what is wrong. Hit the edit button and improve your question!

StevenPuttemans gravatar imageStevenPuttemans ( 2018-05-08 08:24:36 -0500 )edit