简体   繁体   English

从现有模型创建OpenCV Haar分类器

[英]Creating OpenCV Haar Classifier from an existing model

I want to make an application that recognizes screws. 我想制作一个识别螺丝的应用程序。 there is a standard for each screw size and shape, and there are softwares that provide a 360 3d model of each screw (Autocad for example) 每个螺丝尺寸和形状都有一个标准,并且有软件可以提供每个螺丝的360 3d模型(例如Autocad)

I wanted to know if there is a any way to take an existing model (of some extension) and create an Haar classifier from it. 我想知道是否有任何方法可以采用现有模型(某些扩展)并从中创建一个Haar classifier

If it wasn't clear, I don't want to take thousands of pictures of every model. 如果不清楚,我不想拍摄每张模特的数千张照片。 I want to somehow reuse the existing models 我想以某种方式重用现有的模型

Thanks 谢谢

In short: I don't think it is possible, unless you are able to render your 3D models realistically according to various lighting conditions. 简而言之:除非您能够根据各种照明条件逼真地渲染3D模型,否则我认为不可能。

Haar and LBP classifiers do use some kind of texture information, so the pure shape information isn't enough, afaik. Haar和LBP分类器确实使用某种纹理信息,因此纯粹的形状信息是不够的,afaik。 (so instead of HAAR, HoG might or might not be more appropriate for such an approach) (因此,不是HAAR,HoG可能或可能不适合这种方法)

For haar classifier training you could render your 3D models with different material and lighting conditions and in various poses. 对于haar分类器训练,您可以使用不同的材质和光照条件以及各种姿势渲染3D模型。 You'll need background images however as negative samples and as background for your rendered screws (but you could merge the screws to background with opencv_createsamples tool afterwards, too). 然而,你需要背景图像作为负样本和渲染螺丝的背景(但你也可以将螺丝合并到背景中,然后使用opencv_createsamples工具)。

So depending on how realistically or appropriate you are able to render the screews, you can use them for your training. 因此,根据您能够渲染screews的现实或适当程度,您可以将它们用于训练。 Keep in mind that in reality, two screws of same type don't look perfectly the same, the length might vary in small amounts (depending on production quality) and there might be deformations or "noise" like burrs might be present that differ from the perfect model, maybe you would have to consider that in your rendering. 请记住,实际上,两个相同类型的螺钉看起来并不完全相同,长度可能会有少量变化(取决于生产质量),并且可能存在变形或“噪音”,如可能存在的毛刺与完美的模型,也许你必须在渲染中考虑到这一点。

In addition, keep in mind, that haar and lbp cascade classifier work best if they cover a class only from a single pose (like frontal faces or profile faces, not both at the same time), this reduces the use of a signle 3D model. 另外,请记住,haar和lbp级联分类器如果仅从单个姿势(如正面或轮廓面,而不是同时覆盖两个)覆盖一个类,则效果最佳,这减少了使用符号3D模型。

sometimes, 3D models can be used in combination with chamfer matching to compare them to 2D models. 有时,3D模型可以与倒角匹配结合使用,以将它们与2D模型进行比较。

A Haar classifier operates on 2D images, both for training and recognition. Haar分类器用于2D图像,用于训练和识别。 It requires a set of normalized positive 2D images (with screw) and a set of normalized negative 2D images (without screw) for training the classifier. 它需要一组标准化的正2D图像(带螺钉)和一组标准化的负2D图像(无螺钉)来训练分类器。 It thus cannot be trained directly with a 3D model, if that is your question. 因此,如果这是您的问题,则不能直接使用3D模型进行训练。 Of course you could render 2D images using the 3D model, but as I understood your comment at the end of your question, this is not what you would like to do. 当然,您可以使用3D模型渲染2D图像,但正如我在您的问题结束时理解您的评论,这不是您想要做的。

Besides, depending on your actual task, a Haar classifier is unlikely to be the method of choice. 此外,根据您的实际任务,哈尔分类器不太可能是选择的方法。 Some important questions are: Can you segment the screw in the image? 一些重要的问题是:你能分割图像中的螺丝吗? Can there be several screws in the image? 图像中可以有几个螺丝吗? Is it a classification task or do you know which screw type is present in the image? 它是分类任务还是您知道图像中存在哪种螺钉类型? Do you require localization or is it only about recognition? 您需要本地化还是仅仅是认可? Are the possible poses of your screws restricted (or can be normalized beforehand due to segmentation)? 是否限制了螺钉的可能姿势(或者由于分割而可以预先标准化)?

Note that a Haar classifier is meant for "learning" variations of the appearance of different instances of a class with similar pose (like more or less upright faces of different persons, ie face detection) and not for handling completely different poses of the same object, not even in 2D, not to even talk about 3D. 注意,Haar分类器用于“学习”具有相似姿势的类的不同实例的外观的变化(例如,不同人的或多或少的直立面部,即面部检测),而不是用于处理相同对象的完全不同的姿势。 ,甚至不是2D,甚至不谈3D。 So it could be only applicable in a very restricted scenario. 所以它可能只适用于非常有限的情况。

UPDATE: A few hints to lead you into the right direction: 更新:一些提示,引导您进入正确的方向:

  1. If you can segment the screws and want to try a simple approach, try to treat it as a 2D problem (assuming the screws do not stand upright) and perform normalization on the basis of image moments. 如果您可以分割螺钉并想尝试一种简单的方法,请尝试将其视为2D问题(假设螺钉不能直立)并根据图像矩进行标准化。

  2. If you can segment the screws and want to treat it as a 2D/3D problem (a 3D model projected to a 2D image), you can look into my (now old) research on efficient appearance-based matching against views generated with a 3D model. 如果你能部分的螺丝,并希望把它当作一个2D / 3D的问题(3D模型投影到二维图像),你可以看看我的(现在老了) 研究高效的基于外观的匹配来用3D生成的视图模型。

  3. If you cannot segment the screw and you know which type of screw is present in the image, you can look into so-called geometric pattern matching from an industrial machine vision library, eg Shape-based matching from Halcon. 如果您无法分割螺钉并且您知道图像中存在哪种类型的螺钉,则可以从工业机器视觉库(例如Halcon的基于形状的匹配)中查看所谓的几何图案匹配。 It offers training from CAD-like data as well. 它还提供类似CAD数据的培训。

  4. If you cannot segment the screw and you don't know which type of screw is present in the image, you can train a Deep Convolutional Neural Network for the classification task and then use 3. for verification and localization. 如果您无法分割螺钉并且您不知道图像中存在哪种类型的螺钉,则可以为分类任务训练深度卷积神经网络,然后使用3.进行验证和本地化。

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

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