Ask Your Question

Revision history [back]

click to hide/show revision 1
initial version

python: How to Crop White region from Number Plate image??

Hey I want to crop white region from image and show the characters written in white region on screen. Here is my code

import cv2
import imutils
# Read input image
img = cv2.imread(r'111.jpg')
hsv = cv2.cvtColor(img, cv2.COLOR_BGR2HSV)
s = hsv[:, :, 2]#saturation
cv2.imshow("HSV Image", hsv)#hsv
cv2.waitKey(0)
cv2.imshow("Saturated Image", s)
cv2.waitKey(0)
ret, thresh = cv2.threshold(s, 0, 255, cv2.THRESH_BINARY+cv2.THRESH_OTSU) #threshold
cv2.imshow("threshold Image", thresh)
cv2.waitKey(0)
cnts = cv2.findContours(thresh, cv2.RETR_EXTERNAL, cv2.CHAIN_APPROX_NONE)#contors find
cnts = imutils.grab_contours(cnts)
# print(cnts)
c = max(cnts, key=cv2.contourArea)
cv2.drawContours(img, cnts, -1, (255, 0, 0), 2)
x, y, w, h = cv2.boundingRect(c)
out = img[y:y+h, x:x+w, :].copy()
# print(out) 
cv2.imshow('crop',out)
cv2.imwrite('tryv.jpg',out)
cv2.waitKey(0)

Here is the image Image

Here out variable have to show the crop image (without green region area) Kindly Guide me how to solve this problem.