简体   繁体   English

使用Opencv计算haar功能

[英]Using Opencv to calculate the haar feature


I try to calculate Haar feature using opencv (Given an image). 我尝试使用opencv计算Haar功能 (给出图像)。
Input : an image 输入 :图像
output : haar feature 输出 :haar功能
For that, I am using the FeatureEvaluator from OpenCV. 为此,我使用了OpenCV的FeatureEvaluator。

But I got an exception when I try to calculate one feature. 但是当我尝试计算一个特征时出现了异常 Here is how I am doing: 这是我的工作方式:

Ptr<FeatureEvaluator> ptrHaar = FeatureEvaluator::create(FeatureEvaluator::HAAR);

Mat img = imread(image_path);       // image of size 2048*1536 correctly loaded
ptrHaar->setImage(img, Size(100, 100));
ptrHaar->setWindow(Point(0, 0));
double res = ptrHaar->calcOrd(0);   // get the exception here

I think that you need to load/create some type of Haar feature, not just create an object. 我认为您需要加载/创建某种类型的Haar功能,而不仅仅是创建一个对象。 Try to load some Haar cascade classifier using load method and than try to use calcOrd method. 尝试使用load方法加载一些Haar级联分类器,然后尝试使用calcOrd方法。

Your code is almost right. 您的代码几乎是正确的。 Only is missing is to read the CascadeClassifier previously trained. 唯一缺少的是阅读以前训练过的CascadeClassifier。 You can do this as follow: 您可以按照以下步骤进行操作:

FileStorage fs( "cascade.xml", FileStorage::READ );

//2) Then, create a FileNode to access the features: // 2)然后,创建一个FileNode来访问功能:

FileNode featuresNode = fs["cascade"]["features"];

//3) Create the FeatureEvaluator, as you did in your first line // 3)像在第一行中一样创建FeatureEvaluator

//4) Read the FileNode you have created: // 4)读取您创建的FileNode:

ptrHaar->read(featuresNode);

And continue accordingly your code. 并据此继续执行您的代码。

Note that ptrHaar->calcOrd(0) will read just the first feature rectangle, if you have more to read, you will need a loop, like this: 请注意,ptrHaar-> calcOrd(0)将仅读取第一个要素矩形,如果您需要读取更多内容,则需要一个循环,如下所示:

FileNodeIterator it = featuresNode.begin(), it_end = featuresNode.end();

int idx = 0;

for( ; it != it_end; ==it, idx++ )
{
    res = ptrHaar.calcOrd(idx);
}

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

相关问题 OpenCV Haar分类器阈值 - OpenCV Haar Classifier Threshold OpenCV:如何使用Haar分类器级联提高眼睛检测的准确性? - OpenCV: How to improve accuracy of eyes detection using Haar Classifier Cascade? Opencv - 如何在 Haar Classifier Cascade 中计算移动物体与相机的距离和速度? - Opencv - How to calculate moving object distance from camera and speed in Haar Classifier Cascade? 是否可以在opencv中继续进行haar培训? - Is it possible to continue haar training in opencv? haar培训OpenCV断言失败 - haar training OpenCV assertion failed OpenCV中使用GridAdaptedFeatureDetector进行特征检测 - feature detection using GridAdaptedFeatureDetector in opencv 检测STATIC摄像机图像中的人物的最佳方法(不使用视频流)-OpenCV中的HOG,Haar,BackgroundSubtract? - Best approach to detect people in a STATIC camera images ( not using video stream ) - HOG, Haar, BackgroundSubtract in OpenCV? OpenCV:如何使用5点算法根据来自不同相机的两个图像之间的特征匹配来计算基本矩阵? - OpenCV: How to calculate essential matrix from feature matches between two images from different cameras using 5-point algorithm? Opencv - Haar级联 - 面部跟踪非常慢 - Opencv - Haar cascade - Face tracking is very slow 在Haar级联opencv之后跟踪对象 - Track objects after Haar cascade opencv
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM