Ask Your Question

Revision history [back]

click to hide/show revision 1
initial version

how can i upgrade the detection of cv.findCountours

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.

how can i upgrade the detection of cv.findCountours

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)

how can i upgrade the detection of cv.findCountours

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)

how can i upgrade the detection of cv.findCountours

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")

cv2.imread("AR5890039763178.tif")

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

cv2.COLOR_BGR2GRAY)

equ = cv2.equalizeHist(gray)

cv2.equalizeHist(gray)

h,w,d= img.shape rect_img = np.zeros((h,w), np.uint8)

np.uint8) # default thresh=120, maxval=100

maxval=100 # threshold to get just the signature

signature # a = cv2.Canny(gray, threshold1 = 0, threshold2 = 255, apertureSize = 3)

3) # gray = cv2.GaussianBlur(gray,(5,5),0)

cv2.GaussianBlur(gray,(5,5),0) # retval, b = cv2.threshold(gray, thresh=127, maxval=255, type=cv2.THRESH_BINARY)

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)

mask=mask)

lst_area = [] lst_rect = []

[]

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

cv2.CHAIN_APPROX_SIMPLE)

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

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)

cv2.imwrite('test.tif',blurred)

how can i upgrade the detection of cv.findCountours

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)

how can i upgrade the detection of cv.findCountours

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)