How to crop the biggest object in image with python opencv?

后端 未结 2 2109
情歌与酒
情歌与酒 2021-01-01 05:21

I want to crop the biggest object in the image (Characters). This code only works if there is no line (shown in the first image). But I need to ignore the line and make the

2条回答
  •  青春惊慌失措
    2021-01-01 05:30

    Python's findContours is your best option

        #use this only on grayscaled image
        thresh = cv2.threshold(yourImage, 40, 255, cv2.THRESH_BINARY)[1]
    
        # dilate the thresholded image to fill in holes, then find contours
        # on thresholded image
        thresh = cv2.dilate(thresh, None, iterations=2)
        (_,cnts, _) = cv2.findContours(thresh.copy(), cv2.RETR_EXTERNAL,
            cv2.CHAIN_APPROX_SIMPLE)
    
        largest = max(cnts)
    

提交回复
热议问题