我的代码似乎有链接器问题。
代码是:
#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&gt; SVM.obj:错误LNK2019:未解析的外部符号&#34; public:void __thiscall cv :: Mat :: deallocate(void)&#34; (?deallocate @ Mat @ cv @@ QAEXXZ)在函数中引用&#34; public:void __thiscall CV ::垫::释放(无效)&#34; (?发布@ Mat @ cv @@ QAEXXZ)2&gt; SVM.obj:错误 LNK2019:未解析的外部符号&#34; public:void __thiscall CV :: MatConstIterator ::寻求(INT,布尔)&#34; (?seek @ MatConstIterator @ cv @@ QAEXH_N @ Z)在函数&#34; public中引用: class cv :: MatConstIterator&amp; __thiscall CV :: MatConstIterator ::运算++(无效)&#34; (?? EMatConstIterator @ cv @@ QAEAAV01 @XZ)2&gt; SVM.obj:错误LNK2019: 未解决的外部符号&#34; public:void __thiscall cv :: Mat :: copySize(class cv :: Mat const&amp;)&#34; (?copySize @ Mat @ cv @@ QAEXABV12 @@ Z)在函数&#34; public中引用: __thiscall cv :: Mat :: Mat(class cv :: Mat const&amp;)&#34; (?? 0Mat @ cv @@ QAE @ ABV01 @@ Z)2&gt; SVM.obj:错误LNK2019:未解决 外部符号&#34; void __cdecl cv :: fastFree(void *)&#34; (?fastFree @ cv @@ YAXPAX @ Z)在函数&#34; public中引用:__thiscall CV ::垫::〜垫(无效)&#34; (?? 1Mat @ cv @@ QAE @ XZ)2&gt; SVM.obj:错误LNK2019: 未解决的外部符号&#34; public:void __thiscall cv :: Mat :: create(int,int const *,int)&#34; (?创建@ @垫CV @@ QAEXHPBHH @ Z) 在函数中引用&#34; public:void __thiscall CV ::垫::创建(INT,INT,INT)&#34; (?create @ Mat @ cv @@ QAEXHHH @ Z)2&gt; SVM.obj: 错误LNK2019:未解析的外部符号&#34; public:void __thiscall cv :: MatConstIterator :: seek(int const *,bool)&#34; (?seek @ MatConstIterator @ cv @@ QAEXPBH_N @ Z)在函数中引用 &#34; public:__ thiscall cv :: MatConstIterator :: MatConstIterator(class cv :: Mat const *)&#34; (?? 0MatConstIterator @ cv @@ QAE @ PBVMat @ 1 @@ Z)2&gt; SVM.obj :错误LNK2019:未解析的外部符号&#34; public:void __thiscall cv :: Mat :: convertTo(class cv :: _ OutputArray const &amp;,int,double,double)const&#34; (?convertTo @ Mat @ cv @@ QBEXABV_OutputArray @ 2 @ HNN @ Z)在 function&#34; public:class cv :: Mat_&amp; _ thiscall cv :: Mat :: operator =(class cv :: Mat const&amp;)&#34; (?? 4?$ Mat_ @ M @ cv @@ QAEAAV01 @ ABVMat @ 1 @@ Z)2&gt; SVM.obj:错误LNK2019: 未解决的外部符号&#34; public:__ thishisall cv :: _ OutputArray :: _ OutputArray(class cv :: Mat&amp;)&#34; (?? 0_OutputArray @ cv @@ QAE @ AAVMat @ 1 @@ Z)在函数&#34; public中引用: class cv :: Mat_&amp; _ thiscall cv :: Mat :: operator =(class cv :: Mat const&amp;)&#34; (?? 4?$ Mat_ @ M @ cv @@ QAEAAV01 @ ABVMat @ 1 @@ Z)2&gt; SVM.obj: 错误LNK2019:未解析的外部符号&#34; public:class cv :: Mat __thiscall cv :: Mat :: reshape(int,int,int const *)const&#34; (?重塑@ Mat @ cv @@ QBE?AV12 @HHPBH @ Z)在函数&#34; public中引用: class cv :: Mat_&amp; _ thiscall cv :: Mat :: operator =(class cv :: Mat const&amp;)&#34; (?? 4?$ Mat_ @ M @ cv @@ QAEAAV01 @ ABVMat @ 1 @@ Z)2&gt; SVM.obj: 错误LNK2019:未解析的外部符号&#34; public:virtual __thiscall CvSVM ::〜CvSVM(无效)&#34; (?? 1CvSVM @@ UAE @ XZ)在函数_main中引用 2&gt; SVM.obj:错误LNK2019:未解析的外部符号&#34; int __cdecl CV :: waitKey(INT)&#34; (?waitKey @ cv @@ YAHH @ Z)在函数_main中引用 2&gt; SVM.obj:错误LNK2019:未解析的外部符号&#34; void __cdecl cv :: imshow(class std :: basic_string,class std :: allocator&gt; const&amp;,class cv :: _ InputArray const&amp;)&#34; (?imshow @ @@ CV YAXABV?$ basic_string的@ DU?$ char_traits @ d @ @@ STD V'$分配器@ d @ @@ 2 STD @@ @ ABV_InputArray 1个@@ Z) 在函数_main 2&gt; SVM.obj中引用:错误LNK2019:未解析 外部符号&#34; bool __cdecl cv :: imwrite(类 的std :: basic_string的,类 std :: allocator&gt; const&amp;,class cv :: _ InputArray const&amp;,class std :: vector&gt; const&amp;)&#34; (?imwrite @ @@ CV YA_NABV?$ basic_string的@ DU?$ char_traits @ d @ @@ STD V'$分配器@ d @ @@ 2 STD @@ @ ABV_InputArray 1 @ ABV?$矢量@ HV?$分配器3 H @std @@@ 3 @@ Z) 在函数_main 2&gt; SVM.obj中引用:错误LNK2019:未解析 外部符号&#34; public:__ thiscall cv :: _ InputArray :: _ InputArray(class cv :: Mat const&amp;)&#34; (?? 0_InputArray @ cv @@ QAE @ ABVMat @ 1 @@ Z)参考 function _main 2&gt; SVM.obj:错误LNK2019:未解析的外部符号 &#34; public:virtual float const * __thiscall CvSVM :: get_support_vector(int)const&#34; (?get_support_vector @ CvSVM @@ UBEPBMH @ Z)在函数_main中引用 2&gt; SVM.obj:错误LNK2019:未解析的外部符号&#34; public:virtual int __thiscall CvSVM :: get_support_vector_count(void)const&#34; 函数_main中引用的(?get_support_vector_count @ CvSVM @@ UBEHXZ) 2&gt; SVM.obj:错误LNK2019:未解析的外部符号&#34; void _ cdecl cv :: circle(class cv :: Mat&amp;,class cv :: Point ,int,class cv :: Scalar_ const&amp;,int,int,int)&#34; (?圆@ @@ CV @ YAXAAVMat 1 @ V'$ Point_ @ H + 1 @ HABV?$ Scalar_ @ N @ 1 @ HHH @ Z) 在函数_main 2&gt; SVM.obj中引用:错误LNK2019:未解析 外部符号&#34; public:virtual float __thiscall CvSVM :: predict(class cv :: Mat const&amp;,bool)const&#34; (?预测@ @@ CvSVM @ UBEMABVMat CV @@ _ N - [Z) 在函数_main 2&gt; SVM.obj中引用:错误LNK2019:未解析 外部符号&#34; public:virtual bool __thiscall CvSVM :: train(class cv :: Mat const&amp;,class cv :: Mat const&amp;,class cv :: Mat const&amp;,class cv :: Mat const&amp;,struct CvSVMParams)&#34; (?train @ CvSVM @@ UAE_NABVMat @ cv @@ 000UCvSVMParams @@@ Z)在 function _main 2&gt; SVM.obj:错误LNK2019:未解析的外部符号 &#34; public:__ thiscall CvSVM :: CvSVM(void)&#34; (?? 0CvSVM @@ QAE @ XZ)引用 在函数_main 2&gt; SVM.obj中:错误LNK2019:未解析的外部 符号&#34; public:__ thiscall CvSVMParams :: CvSVMParams(void)&#34; (?? 0CvSVMParams @@ QAE @ XZ)在函数_main 2&gt; SVM.obj中引用: 错误LNK2019:未解析的外部符号&#34; public:static class cv :: MatExpr __cdecl cv :: Mat :: zeros(int,int,int)&#34; (?zeros @ Mat @ cv @@ SA?AVMatExpr @ 2 @HHH @ Z)在函数_main
中引用
我有最新的Windows 7 OpenCV版本,可以在WillowGarage上找到,我试图从维基页面运行这个例子:link。我的编译器是VC ++。
我已经在谷歌上搜身,但我找不到任何有用的东西。
由于
答案 0 :(得分:3)
对于那些遇到同样问题的人,请确保您拥有所有正确的链接器输入(配置 - >链接器 - >输入),包括dc,如opencv,highgui等。
答案 1 :(得分: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