首页 > 其他 > 详细

OpenCV+Hog预测

时间:2020-03-07 11:01:39      阅读:44      评论:0      收藏:0      [点我收藏+]

 

#include <iostream>
#include <opencv2/opencv.hpp>  //头文件
#include <stdio.h>  
#include <time.h>  
#include <opencv2/core/core.hpp>  
#include <opencv2/highgui/highgui.hpp>  
#include <opencv2/ml/ml.hpp>  
#include <io.h> //查找文件相关函数

using namespace cv::ml;
using namespace cv;  //包含cv命名空间
using namespace std;
Mat detector_HOG(Mat image)
{
    HOGDescriptor *hog = new HOGDescriptor(cvSize(64, 64), cvSize(16, 16), cvSize(8, 8), cvSize(8, 8), 9);

    Mat featureMat;
    vector<float> descriptors;
    hog->compute(image, descriptors, Size(1, 1));
    featureMat = Mat::zeros(1, descriptors.size(), CV_32FC1);

    for (int j = 0; j < descriptors.size(); j++)
    {
        featureMat.at<float>(0, j) = descriptors[j];
    }
    return featureMat;
}

void svm_pridect_HOG(Ptr<SVM> &model, Mat test)
{
    Mat tmp;
    float validity = 0;
    float rst;
    tmp = detector_HOG(test);

    tmp.convertTo(tmp, CV_32F);

    rst = model->predict(tmp);

    cout << rst << endl;

}

int main() 
{


    // 创建分类器并设置参数
    
    
    Ptr<ml::SVM>svm = StatModel::load<SVM>("svm_hog_726_2.xml");
    Mat src= imread("0.jpg",0);
    Mat image;
    resize(src, image, Size(64, 64));;
    svm_pridect_HOG(svm, image);
}

 

OpenCV+Hog预测

原文:https://www.cnblogs.com/hsy1941/p/12432724.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!