简体   繁体   English

如何使用OpenCV和Java检测图像中的上下颠倒文本

[英]How to detect upside down text in image / upside down image using OpenCV and Java


I face this problem for a while and still cannot figure it out. 我面对这个问题已有一段时间,但仍然无法解决。
I'm using OpenCV and Java to detect the card from image and crop it then transfrom, every thing goes fine if the original image is in correct orientation. 我正在使用OpenCV和Java从图像中检测卡并对其进行裁剪然后进行转换,如果原始图像方向正确,一切都会很好。 The task for now is: How to rotate image in 180 degrees? 现在的任务是:如何将图像旋转180度? Or how to detect the text is upside down then we can rotate it to right orientation. 或者如何检测文本是否上下颠倒,然后我们可以将其旋转到正确的方向。
The result i get from OpenCV in Java is the Mat object contains the cropped cards. 我从Java中的OpenCV获得的结果是Mat对象包含裁剪的卡片。
Does anyone faced and solved this before or have any idea please direct me to the right solution. 是否有人以前曾面对并解决过此问题,或有任何想法请引导我找到正确的解决方案。
Thanks in advance. 提前致谢。

Here is sample images i cropped from originals 这是我从原件裁剪的样本图像
Sample 1 样品1
Sample 2 样品2

Just run your code, and if it finds nothing on the first pass then you can just rotate the image and try again? 只需运行您的代码,如果它在第一遍没有发现任何东西,那么您可以旋转图像并重试? Or you could try scanning a small portion of the card only, and then you can determine if the card is the right way up or not. 或者,您可以尝试仅扫描卡的一小部分,然后确定卡是否正确朝上。

It will pay to sit down and think it through for yourself on how this might be done best. 坐下来思考一下自己如何做得最好将是值得的。

As for rotating images, have you tried looking it up? 至于旋转图像,您是否尝试过查找? Because if you are using a buffered image then rotating can be done with a simple AffineTransform: 因为如果您使用的是缓冲图像,则可以使用简单的AffineTransform完成旋转:

AffineTransform at = AffineTransform.getRotateInstance(Math.PI, image.getWidth()/2, image.getHeight()/2.0);
BufferedImage myRotatedImage = createTransformed(image, at);

Edit: For rotating a Mat object you can use: 编辑:要旋转Mat对象,可以使用:

Imgproc.warpAffine(Mat source, Mat dest, Mat M, Size size)

Taken from: http://docs.opencv.org/java/3.0.0/ 摘自: http : //docs.opencv.org/java/3.0.0/

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

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