【发布时间】:2019-04-18 10:37:21
【问题描述】:
我正在做一个关于尼泊尔车牌检测的项目,我从车辆中检测到我的车牌,但车牌歪斜,但结果是车牌的嘈杂图像。
我想知道如何从中分割出每个字符,以便将其发送到检测部分。我试过这样做,但它只是从第二行分割字符。
def segment(image):
H = 100.
height, width, depth = image.shape
imgScale = H/height
newX,newY = image.shape[1]*imgScale, image.shape[0]*imgScale
image = cv2.resize(image,(int(newX),int(newY)))
cv2.imshow("Show by CV2",image)
cv2.waitKey(0)
cv2.imwrite("resizeimg.jpg",image)
idx =0
gray = cv2.cvtColor(image, cv2.COLOR_BGR2GRAY)
_,thresh = cv2.threshold(gray,127,255,cv2.THRESH_TOZERO)
cv2.imshow("thresh",thresh)
cv2.waitKey(0)
# gray=cv2.cvtColor(plate,cv2.COLOR_BW2GRAY)
_,contours,_ = cv2.findContours(thresh,cv2.RETR_LIST,cv2.CHAIN_APPROX_SIMPLE)
for cnt in contours:
idx += 1
x,y,w,h = cv2.boundingRect(cnt)
roi = image[y:y+h,x:x+w]
if(w > 10 and h > 10):
cv2.imwrite(str(idx) + '.jpg', roi)
【问题讨论】:
-
您需要从输入图像中分割出白色。
cv2.inRange()方法可用于分割数字,然后您可以对其应用轮廓检测来分割字符。 -
但我们也有车牌号为白色背景和红色文字的车辆。 @ZdaR
-
那么你应该进行边缘检测,但请记住,阴影等会产生很多噪音。我猜你写了一个小的 sn-p 来检测背景颜色,具体取决于背景的颜色,你可以切换分割哪种颜色的逻辑。
标签: python opencv image-processing image-segmentation text-segmentation