License plate character segmentation python opencv

后端 未结 1 451
刺人心
刺人心 2021-01-14 05:21

I want to isolate every character in the following image:

and it should create a rectangular bounding box around each character. My code is creating a circular bou

1条回答
  •  太阳男子
    2021-01-14 06:01

    After removing background noises you can input image like this:

    Then you can get what you want using following code:

    import cv2
    img = cv2.imread('test4.jpg', 0)
    cv2.threshold(img,0,255,cv2.THRESH_BINARY+cv2.THRESH_OTSU,img)
    image, contours, hier = cv2.findContours(img, cv2.RETR_EXTERNAL,cv2.CHAIN_APPROX_NONE)
    contours = sorted(contours, key=lambda ctr: cv2.boundingRect(ctr)[0])
    cv2.imshow("contours", img)
    cv2.waitKey(0)
    d=0
    for ctr in contours:
        # Get bounding box
        x, y, w, h = cv2.boundingRect(ctr)
        # Getting ROI
        roi = image[y:y+h, x:x+w]
    
        cv2.imshow('character: %d'%d,roi)
        cv2.imwrite('character_%d.png'%d, roi)
        cv2.waitKey(0)
        cv2.destroyAllWindows()
        d+=1
    

    0 讨论(0)
提交回复
热议问题