0

コードにリンカの問題があるようです。

コードは次のとおりです。

#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <assert.h>
#include <math.h>
#include <float.h>
#include <limits.h>
#include <time.h>
#include <ctype.h>
#include <iostream>
#include <vector>

#include "opencv/ml.h"
#include "opencv/cvaux.h"
#include "opencv/highgui.h"
#include "opencv/cxcore.h"
#include "opencv/cv.h"
#include "opencv/highgui.h"

using namespace cv;
int main (int argc, char* argv[])
{
// Data for visual representation
    int width = 512, height = 512;
    Mat image = Mat::zeros(height, width, CV_8UC3);

    // Set up training data
    float labels[4] = {1.0, -1.0, -1.0, -1.0};
    Mat labelsMat(3, 1, CV_32FC1, labels);

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

    // Set up SVM's parameters
    CvSVMParams params;
    params.svm_type    = CvSVM::C_SVC;
    params.kernel_type = CvSVM::LINEAR;
    params.term_crit   = cvTermCriteria(CV_TERMCRIT_ITER, 100, 1e-6);

    // Train the SVM
    CvSVM SVM;
    SVM.train(trainingDataMat, labelsMat, Mat(), Mat(), params);

    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) << i,j);
            float response = SVM.predict(sampleMat);

            if (response == 1)
                image.at<Vec3b>(j, i)  = green;
            else if (response == -1) 
                 image.at<Vec3b>(j, i)  = 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;
    int c     = SVM.get_support_vector_count();

    for (int i = 0; i < c; ++i)
    {
        const float* v = SVM.get_support_vector(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);
return EXIT_SUCCESS;
}

エラーレポートは次のとおりです。

2>SVM.obj: エラー LNK2019: 未解決の外部シンボル "public: void __thiscall cv::Mat::deallocate(void)" (?deallocate@Mat@cv@@QAEXXZ) 関数で参照されている "public: void __thiscall cv:: Mat::release(void)" (?release@Mat@cv@@QAEXXZ) 2>SVM.obj: エラー LNK2019: 未解決の外部シンボル "public: void __thiscall cv::MatConstIterator::seek(int,bool)" ( ?seek@MatConstIterator@cv@@QAEXH_N@Z) 関数で参照されている "public: class cv::MatConstIterator & __thiscall cv::MatConstIterator::operator++(void)" (??EMatConstIterator@cv@@QAEAAV01@XZ) 2> SVM.obj : エラー LNK2019: 未解決の外部シンボル "public: void __thiscall cv::Mat::copySize(class cv::Mat const &)" (?copySize@Mat@cv@@QAEXABV12@@Z) 関数で参照" public: __thiscall cv::Mat::Mat(class cv::Mat const &)" (??0Mat@cv@@QAE@ABV01@@Z) 2>SVM.obj : エラー LNK2019: 未解決の外部シンボル "void __cdecl cv::fastFree(void *)" (?fastFree@cv@ @YAXPAX@Z) 関数 "public: __thiscall cv::Mat::~Mat(void)" で参照 (??1Mat@cv@@QAE@XZ) 2>SVM.obj: エラー LNK2019: 未解決の外部シンボル "public : void __thiscall cv::Mat::create(int,int const *,int)" (?create@Mat@cv@@QAEXHPBHH@Z) 関数内で参照 "パブリック: void __thiscall cv::Mat::create(int ,int,int)" (?create@Mat@cv@@QAEXHHH@Z) 2>SVM.obj: エラー LNK2019: 未解決の外部シンボル "public: void __thiscall cv::MatConstIterator::seek(int const *,bool) " (?seek@MatConstIterator@cv@@QAEXPBH_N@Z) 関数内で参照 "public: __thiscall cv::MatConstIterator::MatConstIterator(class cv::Mat const *)" (??0MatConstIterator@cv@@QAE@PBVMat@1@@Z) 2>SVM.obj : エラー LNK2019: 未解決の外部シンボル "public: void __thiscall cv::Mat::convertTo(class cv: :_OutputArray const &,int,double,double)const " (?convertTo@Mat@cv@@QBEXABV_OutputArray@2@HNN@Z) 関数内で参照 "public: class cv::Mat_ & _thiscall cv::Mat ::operator=(class cv::Mat const &)" (??4?$Mat_@M@cv@@QAEAAV01@ABVMat@1@@Z) 2>SVM.obj: エラー LNK2019:未解決の外部シンボル "public: __thiscall cv::_OutputArray::_OutputArray(class cv::Mat &)" (??0_OutputArray@cv@@QAE@AAVMat@1@@Z) が関数 "public: class cv:: Mat_ & _ thiscall cv::Mat ::operator=(class cv::Mat const &)" (??4?$Mat_@M@cv@@QAEAAV01@ABVMat@1@@Z) 2>SVM.obj :エラー LNK2019: 未解決の外部シンボル "パブリック: クラス cv::Mat __thiscall cv::Mat::reshape(int,int,int const *)const" (?reshape@Mat@cv@@QBE?AV12@HHPBH@Z)関数 "public: class cv::Mat_ & _ thiscall cv::Matで参照::operator=(class cv::Mat const &)" (??4?$Mat_@M@cv@@QAEAAV01@ABVMat@1@@Z) 2>SVM.obj: エラー LNK2019: 未解決の外部シンボル "public : 仮想 __thiscall CvSVM::~CvSVM(void)" (??1CvSVM@@UAE@XZ) 関数 _main で参照 2>SVM.obj: エラー LNK2019: 未解決の外部シンボル "int __cdecl cv::waitKey(int)" ( ?waitKey@cv@@YAHH@Z) 関数 _main 2>SVM.obj で参照: エラー LNK2019: 未解決の外部シンボル "void __cdecl cv::imshow(class std::basic_string,class std::allocator > const &,class cv::_InputArray const &)" (?imshow@cv@@YAXABV?$basic_string@DU?$char_traits@D@std@@V?$allocator@D@2@@std@@ABV_InputArray@1@@Z)関数 _main 2>SVM.obj で参照: エラー LNK2019: 未解決の外部シンボル "bool __cdecl cv::imwrite(class std::basic_string,class std::allocator > const &,class cv::_InputArray const &,class std::vector > const &)" (?imwrite@cv@@YA_NABV?$basic_string@DU?$char_traits@D@std@@V ?$allocator@D@2@@std@@ABV_InputArray@1@ABV?$vector@HV?$allocator@H@std@@@3@@Z) 関数 _main 2>SVM.obj で参照: エラー LNK2019:未解決の外部シンボル "public: __thiscall cv::_InputArray::_InputArray(class cv::Mat const &)" (??0_InputArray@cv@@QAE@ABVMat@1@@Z) 関数 _main で参照 2>SVM.obj : エラー LNK2019: 未解決の外部シンボル "public: virtual float const * __thiscall CvSVM::get_support_vector(int)const " (?get_support_vector@CvSVM@@UBEPBMH@Z) 関数 _main で参照 2>SVM.obj : エラー LNK2019: 未解決の外部symbol "public: virtual int __thiscall CvSVM::get_support_vector_count(void)const " (?get_support_vector_count@CvSVM@@UBEHXZ) 関数 _main で参照 2>SVM.obj: エラー LNK2019: 未解決の外部シンボル "void _cdecl cv::circle(class cv::Mat &,class cv::Point,int,class cv::Scalar_ const &,int,int,int)" (?circle@cv@@YAXAAVMat@1@V?$Point_@H@1@HABV?$Scalar_@N@1@HHH@Z ) 関数 _main で参照 2>SVM.obj : エラー LNK2019: 未解決の外部シンボル "public: virtual float __thiscall CvSVM::predict(class cv::Mat const &,bool)const " (?predict@CvSVM@@UBEMABVMat@cv @@_N@Z) 関数 _main 2>SVM.obj で参照: エラー LNK2019: 未解決の外部シンボル "public: virtual bool __thiscall CvSVM::train(class cv::Mat const &,class cv::Mat const &,class cv::Mat const &,class cv::Mat const &,struct CvSVMParams)" (?train@CvSVM@@UAE_NABVMat@cv@@000UCvSVMParams@@@Z) 関数 _main 2>SVM.obj で参照: エラー LNK2019:未解決の外部シンボル "public: __thiscall CvSVM::CvSVM(void)"関数 _main で参照されている (??0CvSVM@@QAE@XZ) 2>SVM.obj : エラー LNK2019: 未解決の外部シンボル "public: __thiscall CvSVMParams::CvSVMParams(void)" (??0CvSVMParams@@QAE@XZ) で参照されていますfunction _main 2>SVM.obj : エラー LNK2019: 未解決の外部シンボル "public: static class cv::MatExpr __cdecl cv::Mat::zeros(int,int,int)" (?zeros@Mat@cv@@SA? AVMatExpr@2@HHH@Z) 関数 _main で参照

私は、WillowGarage で入手できる Windows 7 用の OpenCV の最新の完全ビルド バージョンを持っています。この例を wiki ページから実行しようとしています: link。私のコンパイラは VC++ です。

私はすでにGoogleで検索しましたが、何も機能していません。

ありがとう

4

2 に答える 2

3

同じ問題を抱えている人のために、opencv、highgui などの dll が含まれているすべての正しいリンカー入力 (構成 -> リンカー -> 入力) があることを確認してください。

于 2012-05-11T15:09:31.010 に答える
0

一部の入力のリストが必要な場合:

opencv_core412.lib
opencv_imgcodecs412.lib
opencv_imgproc412.lib
opencv_highgui412.lib
opencv_ml412.lib
opencv_video412.lib
opencv_features2d412.lib
opencv_calib3d412.lib
opencv_objdetect412.lib
opencv_flann412.lib

412 はバージョンであり、この場合はリリース モードであるため、末尾に d がありません。それ以外の場合は、opencv_flann412d.lib

于 2019-11-22T03:32:24.507 に答える