简体   繁体   English

如何使用OpenCV从图像中检测旋转的对象?

[英]How to detect rotated object from image using OpenCV?

I have been training OpenCV classifier for recognition of books.The requirement is recognize book from an image. 我一直在训练OpenCV分类器来识别书籍。要求是从图像识别书籍。 I have used 1000+ images and OpenCV is able to detect books with no rotation. 我已经使用了1000多个图像,并且OpenCV能够不旋转地检测书籍。 However, when I try to detect books with rotations it does not work properly.So I am wondering if their anyway to detect objects with rotations in images using OpenCV? 但是,当我尝试旋转检测书籍时,它不能正常工作,所以我想知道它们是否仍然可以使用OpenCV检测图像中旋转对象?

What features are you using to detect your books? 您正在使用哪些功能来检测您的图书? Are you training a CNN and deploying it with OpenCV? 您是否正在训练CNN并通过OpenCV进行部署? In that case adding rotation image augmentation to your training would make it easy to detect rotated books. 在这种情况下,将旋转图像增强添加到您的训练中将使检测旋转书籍变得容易。

If you are using traditional computer vision techniques instead, you can try to use some rotation invariant feature extractors like SURF, however, the results will not be as good as using CNNs which are now the state of the art for this kind of problems. 如果您使用的是传统的计算机视觉技术,则可以尝试使用一些旋转不变特征提取器(例如SURF),但是结果将不如使用CNN(后者是目前解决此类问题的最新技术)那样好。

Firstly, you should get the main theoritical ideas of pose estimation and image warping . 首先,您应该获得姿势估计图像变形的主要理论思想。

You should define some important points of the books (some special and strong features that valid for each types of books) and then you can estimate the pose of the book by using this points. 您应该定义书籍的一些要点(某些特殊且强大的功能对每种类型的书籍都有效),然后可以使用这些要点来估计书籍的姿势。 After getting the pose angles, you should warp the image to align books. 在获得姿势角度后,您应该使图像变形以对齐书籍。 After book alignment you should perform feature extraction so you can improve the success of book detection by this way. 对齐书籍后,您应该执行特征提取,以便通过这种方式提高书籍检测的成功率。

As a summary, pose estimation and warping (alignment) are important for these kinf of rotation problems. 总之, 姿势估计翘曲(对齐)对于这些旋转问题很重要。

Your problem can be perfectly solved using OpenCV and keypoint matching algorithms such as SURF or ORB. 使用OpenCV和关键点匹配算法(例如SURF或ORB)可以完美解决您的问题。 You don't really need a classifier. 您实际上不需要分类器。 To my experience, such solution using unmodified openCv can scale up to recognize around 10.000 images. 以我的经验,使用未经修改的openCv的这种解决方案可以扩展到识别大约10.000张图像。

What I would do is: Offline: Loop over your book images to generate a database of keypoint descriptors matching each descriptor to the id of the book in which it comes from. 我要做的是:脱机:遍历您的书本图像以生成关键点描述符数据库,该描述符将每个描述符与该书的来源ID相匹配。 Online: Compute the keypoints of the query image and try to match (using BF, FLANN, or LSH) each of them to a keypoint of the pre-computed database. 在线:计算查询图像的关键点,并尝试将它们每个匹配(使用BF,FLANN或LSH)与预先计算的数据库的关键点。 Vote for the database book cover which has matched with the most query keypoints. 为与大多数查询要点匹配的数据库书籍封面投票。 Try to compute an homography matrix between selected db book cover and query image to validate match. 尝试计算所选数据库书籍封面和查询图像之间的单应性矩阵以验证匹配。

ORB, BRISK, SURF, SIFT feature descriptors are all usable for this task, and rotation invariant. ORB,BRISK,SURF,SIFT特征描述符都可用于此任务,并且旋转不变。 ORB and BRISK are faster and a bit less performant. ORB和BRISK更快,性能更低。

See this link for simple example: https://docs.opencv.org/3.3.0/dc/dc3/tutorial_py_matcher.html 参见以下链接获取简单示例: https : //docs.opencv.org/3.3.0/dc/dc3/tutorial_py_matcher.html

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

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