简体   繁体   English

如何使用给定的Image Python中的openCV从图像中裁剪字符?

[英]How to crop character from image using openCV from given Image Python?

Cropped Only character from Image and remove spaces 仅从图像中裁剪字符并删除空格

I am trying to remove extra spaces from left and right of character image through opencv .Every image has different dimension .Is there any way to crop or remove extra spaces from left and right only or fetch only character from image. 我试图通过opencv从字符图像的左侧和右侧删除多余的空格。每个图像都有不同的尺寸。有没有办法从左右裁剪或删除多余的空格或仅从图像中获取字符。

输入1

输入2

Under the assumption that all your images look like the examples provided you can go with HansHirse's solution. 假设所有图像看起来都像提供的示例,您可以使用HansHirse的解决方案。

Segment the image into fore- and background using a global threshold. 使用全局阈值将图像分割为前景和后景。 Then find the extreme coordinates of foreground pixels to define the boundaries of your sub image. 然后找到前景像素的极值坐标以定义子图像的边界。

Of course you can do both steps on the fly instead of doing two iterations over your image. 当然,您可以动态执行这两个步骤,而不是对图像执行两次迭代。

Another solution: Use a blob detector to find the character components and merge their bounding boxes. 另一种解决方案:使用blob检测器查找字符组件并合并其边界框。

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

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