Ask Your Question
0

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

asked 2020-10-04 03:31:51 -0600

salmaUCP gravatar 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.

edit retag flag offensive close merge delete

1 answer

Sort by ยป oldest newest most voted
0

answered 2020-10-04 11:34:02 -0600

supra56 gravatar image

See my answers crop white region

image description

edit flag offensive delete link more

Comments

1

Thank You! it would be really helpful for me...!

salmaUCP gravatar imagesalmaUCP ( 2020-10-04 12:18:33 -0600 )edit

Btw, used mouse event.

supra56 gravatar imagesupra56 ( 2020-10-04 20:12:04 -0600 )edit

Question Tools

1 follower

Stats

Asked: 2020-10-04 03:31:51 -0600

Seen: 1,753 times

Last updated: Oct 04 '20