简体   繁体   English

如何从这些彩色图像中提取文字?

[英]How to extract text from these colored images?

I want to extract the text on Labels from the images. 我想从图像中提取标签上的文本。 The images are coloured and are in a real-life environment. 图像是彩色的,并且处于现实生活中。 PFA images. PFA图像。 Sample Image 示例图像

I have tried multiple solutions: 我尝试了多种解决方案:

  1. I'm able to read text from flat images using Tesseract but it's not working if the text is at a certain angle. 我可以使用Tesseract从平面图像中读取文本,但如果文本处于某个角度则无法正常工作。
  2. Tried a lot of image pre-processing converting it to Binary and grayscale but not able to extract the required text. 尝试了很多图像预处理,将其转换为二进制和灰度,但无法提取所需的文本。
  3. Since the above step failed I was not able to de-skew the text either. 由于上述步骤失败,我无法对文本进行去偏斜。
    image = cv2.imread("p18-73.png",0)
    thresh = cv2.adaptiveThreshold(image,255, cv2.ADAPTIVE_THRESH_GAUSSIAN_C, cv2.THRESH_BINARY, 11,2)
    coords = np.column_stack(np.where(thresh > 0))
    angle = cv2.minAreaRect(coords)[-1]

The above pre-processing code is not working. 上述预处理代码无效。 Can you please tell me what is the best way to approach this image? 你能否告诉我接近这张图片的最佳方法是什么?

Did you check the result of cv2.adaptiveThreshold()? 你检查了cv2.adaptiveThreshold()的结果吗? The result of cv2.adaptiveThreshold() is like this: cv2.adaptiveThreshold()的结果如下:

自适应阈值结果

I think this is not what you want. 我想这不是你想要的。 Try to use global threshold cv2.threshold(), and adjust the threshold value. 尝试使用全局阈值cv2.threshold(),并调整阈值。

ret, thresh = cv2.threshold(image, 240, 255, cv2.THRESH_BINARY)

全局阈值结果

Also, you can add cv2.morphologyEx() to remove the noise. 此外,您可以添加cv2.morphologyEx()来消除噪音。

kernel = np.ones((2,2),np.uint8)
thresh = cv2.morphologyEx(thresh, cv2.MORPH_OPEN, kernel)

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM