久久久久久久av_日韩在线中文_看一级毛片视频_日本精品二区_成人深夜福利视频_武道仙尊动漫在线观看

OpenCV 無法設置 SVM 參數

OpenCV unable to set up SVM Parameters(OpenCV 無法設置 SVM 參數)
本文介紹了OpenCV 無法設置 SVM 參數的處理方法,對大家解決問題具有一定的參考價值,需要的朋友們下面隨著小編來一起學習吧!

問題描述

我剛剛開始學習使用 C++ OpenCV 的 SVM,并參考了 SVM 文檔

I have just started my learning on SVM using C++ OpenCV and was referring to the SVM documentation here. I wanted to try out the sample source code from the link to get familiar with it first but I couldn't run the sample source code. It returns the error :

Error 1 error C2065: 'CvSVMParams' : undeclared identifier

I'm using Visual Studio 2012 with OpenCV 3.0.0. The setup process should be correct as all other codes are working well except this.

解決方案

A lot of things changed from OpenCV 2.4 to OpenCV 3.0. Among others, the machine learning module, which isn't backward compatible.

This is the OpenCV tutorial code for the SVM, update for OpenCV 3.0:

#include <opencv2/core.hpp>
#include <opencv2/imgproc.hpp>
#include "opencv2/imgcodecs.hpp"
#include <opencv2/highgui.hpp>
#include <opencv2/ml.hpp>

using namespace cv;
using namespace cv::ml;

int main(int, char**)
{
    // Data for visual representation
    int width = 512, height = 512;
    Mat image = Mat::zeros(height, width, CV_8UC3);

    // Set up training data
    int labels[4] = { 1, -1, -1, -1 };
    Mat labelsMat(4, 1, CV_32SC1, labels);

    float trainingData[4][2] = { { 501, 10 }, { 255, 10 }, { 501, 255 }, { 10, 501 } };
    Mat trainingDataMat(4, 2, CV_32FC1, trainingData);

    // Set up SVM's parameters
    Ptr<SVM> svm = SVM::create();
    svm->setType(SVM::C_SVC);
    svm->setKernel(SVM::LINEAR);
    svm->setTermCriteria(TermCriteria(TermCriteria::MAX_ITER, 100, 1e-6));

    // Train the SVM with given parameters
    Ptr<TrainData> td = TrainData::create(trainingDataMat, ROW_SAMPLE, labelsMat);
    svm->train(td);

    // Or train the SVM with optimal parameters
    //svm->trainAuto(td);

    Vec3b green(0, 255, 0), blue(255, 0, 0);
    // Show the decision regions given by the SVM
    for (int i = 0; i < image.rows; ++i)
        for (int j = 0; j < image.cols; ++j)
        {
            Mat sampleMat = (Mat_<float>(1, 2) << j, i);
            float response = svm->predict(sampleMat);

            if (response == 1)
                image.at<Vec3b>(i, j) = green;
            else if (response == -1)
                image.at<Vec3b>(i, j) = blue;
        }

    // Show the training data
    int thickness = -1;
    int lineType = 8;
    circle(image, Point(501, 10), 5, Scalar(0, 0, 0), thickness, lineType);
    circle(image, Point(255, 10), 5, Scalar(255, 255, 255), thickness, lineType);
    circle(image, Point(501, 255), 5, Scalar(255, 255, 255), thickness, lineType);
    circle(image, Point(10, 501), 5, Scalar(255, 255, 255), thickness, lineType);

    // Show support vectors
    thickness = 2;
    lineType = 8;
    Mat sv = svm->getSupportVectors();

    for (int i = 0; i < sv.rows; ++i)
    {
        const float* v = sv.ptr<float>(i);
        circle(image, Point((int)v[0], (int)v[1]), 6, Scalar(128, 128, 128), thickness, lineType);
    }

    imwrite("result.png", image);        // save the image

    imshow("SVM Simple Example", image); // show it to the user
    waitKey(0);

}

The output should look like:

這篇關于OpenCV 無法設置 SVM 參數的文章就介紹到這了,希望我們推薦的答案對大家有所幫助,也希望大家多多支持html5模板網!

【網站聲明】本站部分內容來源于互聯網,旨在幫助大家更快的解決問題,如果有圖片或者內容侵犯了您的權益,請聯系我們刪除處理,感謝您的支持!

相關文檔推薦

Assertion failed (size.widthgt;0 amp;amp; size.heightgt;0)(斷言失敗(size.width0 amp;amp; size.height0))
Rotate an image in C++ without using OpenCV functions(在 C++ 中旋轉圖像而不使用 OpenCV 函數)
OpenCV: process every frame(OpenCV:處理每一幀)
Why can#39;t I open avi video in openCV?(為什么我不能在 openCV 中打開 avi 視頻?)
Convert a single color with cvtColor(使用 cvtColor 轉換單一顏色)
Easiest way to rotate by 90 degrees an image using OpenCV?(使用 OpenCV 將圖像旋轉 90 度的最簡單方法?)
主站蜘蛛池模板: www.色午夜.com | 国产福利在线小视频 | 青青草精品 | 91视频正在播放 | 国产精品亚洲一区 | 精品国产乱码久久久久久闺蜜 | 日韩午夜| 成人免费视频网站在线看 | 亚洲综合色站 | 国产精品久久久久久久久久久久久 | 一级片网站视频 | 中文字幕精品一区二区三区精品 | 欧美激情在线精品一区二区三区 | 国产激情一区二区三区 | 福利社午夜影院 | 欧美日韩久久久 | 一区二区三区国产在线观看 | 久久69精品久久久久久久电影好 | 亚洲成人毛片 | 亚洲欧美日韩精品 | 日韩亚洲欧美综合 | 91免费版在线观看 | 欧美中文一区 | 毛片黄片| 久久久久久亚洲精品 | 午夜精品久久久久久久久久久久久 | 99久久99久久精品国产片果冰 | 日韩欧美精品在线 | 午夜a级理论片915影院 | 国产91久久久久久 | 精品一区久久 | 精品视频网 | 一区欧美| 九色视频网站 | 黄色一级片视频 | 精品在线一区 | 在线观看国产视频 | 亚洲精品一区二区在线观看 | 日韩精品在线免费 | 欧美亚洲国产成人 | 亚洲一区二区三区在线 |