How to crop image by main canny edge

Viewed 65

I got the following image:

enter image description here

And trying to crop image by code:

def getoriginpaper(image):

    image2 = image.copy()
    w, h = image.shape[::-1]

    # image = cv2.blur(image, (3, 3), 0)
    image = cv2.medianBlur(image, 9)  # 9
    
    img = cv2.GaussianBlur(image, (9, 9), 0)

    canny = cv2.Canny(img, 30, 100)  # 50 150

    x, y, w, h = cv2.boundingRect(canny)
    cv2.rectangle(img, (x, y), (x + w, y + h), (0, 255, 0), 2)
    cv2.imshow('boundingrect_canny', img)
    cv2.waitKey(0)
    return image2[y:y+h, x:x+w]

canny image like this: enter image description here

Problem is, see image below: enter image description here

So, above is what I got by boundingRect, but acctually, I wanna left side go likes the green line, and I know reason is the corner marked with red circle.

Any way to remove the red circle part to make it left side as the green line?

Any suggestions are great appreciated.

Thanks.

0 Answers
Related