SVM的链接器错误OpenCV

问题描述 投票:0回答:2

我的代码似乎有链接器问题。

代码是:

#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:无效__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 __thiscallcv :: MatConstIterator :: seek(int,bool)“(?seek @ MatConstIterator @ cv @@ QAEXH_N @ Z)在函数“ public:”中引用类cv :: MatConstIterator和__thiscallcv :: MatConstIterator :: operator ++(void)“(?? EMatConstIterator @ cv @@ QAEAAV01 @ XZ)2> SVM.obj:错误LNK2019:未解析的外部符号“ public:void __thiscallcv :: Mat :: copySize(class cv :: Mat const&)“(?copySize @ Mat @ cv @@ QAEXABV12 @@ Z)():__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 __thiscallcv :: Mat :: create(int,int const *,int)“(?create @ Mat @ cv @@ QAEXHPBHH @ Z)在函数“ public:void __thiscall中引用”cv :: Mat :: create(int,int,int)“(?create @ Mat @ cv @@ QAEXHHH @ Z)2> SVM.obj:错误LNK2019:无法解析的外部符号“ public:void __thiscallcv :: MatConstIterator :: seek(int const *,bool)“函数中引用的(?seek @ MatConstIterator @ cv @@ QAEXPBH_N @ Z)“ public:__thiscall cv :: MatConstIterator :: MatConstIterator(classcv :: Mat const *)“(?? 0MatConstIterator @ cv @@ QAE @ PBVMat @ 1 @@@ Z)2> SVM.obj:错误LNK2019:无法解析的外部符号“公共:无效__thiscallcv :: Mat :: convertTo(class cv :: _ OutputArray const&,int,double,double)const“在(?convertTo @ Mat @ cv @@ QBEXABV_OutputArray @ 2 @ HNN @ Z)中引用函数“ public:类cv :: Mat_&_ thiscallcv :: Mat :: operator =(class cv :: Mat const&)“(?? 4?$ Mat_ @ M @ cv @@ QAEAAV01 @ ABVMat @ 1 @@ Z)2> SVM.obj:错误LNK2019:未解析的外部符号“ public:__ thiscallcv :: _ OutputArray :: _ OutputArray(class cv :: Mat&)“在函数“ public:”中引用(0_OutputArray @ cv @@ QAE @ AAVMat @ 1 @@ Z)class cv :: Mat_&_ thiscall cv :: Mat :: operator =(classcv :: Mat const&)“(?? 4?$ Mat_ @ M @ cv @@ QAEAAV01 @ ABVMat @ 1 @@ Z)2> SVM.obj:错误LNK2019:无法解析的外部符号“ public:类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 =(classcv :: Mat const&)“(?? 4?$ Mat_ @ M @ cv @@ QAEAAV01 @ ABVMat @ 1 @@ Z)2> SVM.obj:错误LNK2019:无法解析的外部符号“ public:虚拟__thiscallCvSVM ::〜CvSVM(void)“(?? 1CvSVM @@ UAE @ XZ)在函数_main中引用2> SVM.obj:错误LNK2019:未解析的外部符号“ int __cdeclcv :: waitKey(int)“(?waitKey @ cv @@ YAHH @ Z)在函数_main中引用2> SVM.obj:错误LNK2019:未解决的外部符号“ void __cdeclcv :: imshow(class std :: basic_string,class std :: allocator> const&,classcv :: _ 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:未解决外部符号“布尔__cdecl cv :: imwrite(classstd :: basic_string,classstd :: allocator> const&,class cv :: _ InputArray const&,classstd :: 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(classcv :: Mat const&)“(?? 0_InputArray @ cv @@ QAE @ ABVMat @ 1 @@@ Z)中引用函数_main 2> SVM.obj:错误LNK2019:未解析的外部符号“ public:虚拟float const * __thiscallCvSVM :: get_support_vector(int)const“函数_main中引用的(?get_support_vector @ CvSVM @@ UBEPBMH @ Z)2> SVM.obj:错误LNK2019:未解决的外部符号“ public:虚拟int __thiscall CvSVM :: get_support_vector_count(void)const“函数_main中引用的(?get_support_vector_count @ CvSVM @@ UBEHXZ)2> SVM.obj:错误LNK2019:未解决的外部符号“ void _ cdeclcv :: circle(类cv :: Mat&,类cv :: Point,int,classcv :: 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:虚拟浮点数__thiscall CvSVM :: predict(classcv :: Mat const&,bool)const“(?predict @ CvSVM @@ UBEMABVMat @ cv @@ __ N @ Z)在函数_main 2> SVM.obj中引用:错误LNK2019:未解决外部符号“ public:虚拟布尔__thiscall CvSVM :: train(classcv :: Mat const&,class cv :: Mat const&,class cv :: Mat const&,classcv :: Mat const&,struct CvSVMParams)”在(?train @ CvSVM @@ UAE_NABVMat @ cv @@ 000UCvSVMParams @@@@ Z)中引用函数_main 2> SVM.obj:错误LNK2019:未解析的外部符号引用了“ public:__thiscall CvSVM :: CvSVM(void)”(?? 0CvSVM @@ QAE @ XZ)在函数_main 2> SVM.obj中:错误LNK2019:无法解析的外部符号“公共:__thiscall CvSVMParams :: CvSVMParams(void)”在函数_main 2> SVM.obj中引用的(0CvSVMParams @@ QAE @ XZ):错误LNK2019:无法解析的外部符号“ public:静态类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上找到了,但找不到任何工作。

谢谢

opencv linker svm
2个回答
3
投票

对于那些有相同问题的人,请确保您拥有所有正确的链接器输入(配置->链接器->输入),包括诸如opencv,highgui等的dll。


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

© www.soinside.com 2019 - 2024. All rights reserved.