读书人

1gt;MSVCRTD.lib(crtexe.obj) : error L

发布时间: 2013-03-27 11:22:42 作者: rapoo

1>MSVCRTD.lib(crtexe.obj) : error LNK2019: 无法解析的外部符号 _main,该符号在函数 ___tmainCRTSta
制作分类器的文件见下面,这么问题该如何解决啊???
#include "stdafx.h"
#include "cv.h"
#include "highgui.h"
#include "cvaux.h"
#include "opencv2/imgproc/imgproc.hpp"
#include "opencv2/objdetect/objdetect.hpp"
#include "opencv2/highgui/highgui.hpp"

#include <stdio.h>
#include <string.h>
#include <ctype.h>

using namespace cv;
using namespace std;

class Mysvm: public CvSVM

{
public:
int get_alpha_count()
{
return this->sv_total;
}

int get_sv_dim()
{
return this->var_all;
}

int get_sv_count()
{
return this->decision_func->sv_count;
}

double* get_alpha()
{
return this->decision_func->alpha;
}

float** get_sv()
{
return this->sv;
}

float get_rho()
{
return this->decision_func->rho;
}
};

int Train()
{
char classifierSavePath[256] = "d:/pedestrianDetect-peopleFlow.txt";//训练结果保存为文本

//string positivePath = "E:\\pictures\\train1\\pos\\";//正样本路径文件夹
//string negativePath = "E:\\pictures\\train1\\neg\\";//负样本路径文件夹
string positivePath = "D:\\最近要看的手势识别文章\\手势识别程序代码\\INRIAPerson\\train_64x128_H96\\pos\\";//正样本路径文件夹
string negativePath = "D:\\最近要看的手势识别文章\\手势识别程序代码\\INRIAPerson\\train_64x128_H96\\neg\\";//负样本路径文件夹
//int positiveSampleCount = 4900;
//int negativeSampleCount = 6192;//正负样本数
int positiveSampleCount = 2416;
int negativeSampleCount = 1218;//正负样本数
int totalSampleCount = positiveSampleCount + negativeSampleCount;

cout<<"//////////////////////////////////////////////////////////////////"<<endl;
cout<<"totalSampleCount: "<<totalSampleCount<<endl;
cout<<"positiveSampleCount: "<<positiveSampleCount<<endl;
cout<<"negativeSampleCount: "<<negativeSampleCount<<endl;

CvMat *sampleFeaturesMat = cvCreateMat(totalSampleCount , 1764, CV_32FC1);
//64*128的训练样本,该矩阵将是totalSample*3780,64*64的训练样本,该矩阵将是totalSample*1764
cvSetZero(sampleFeaturesMat); //初始化为0
CvMat *sampleLabelMat = cvCreateMat(totalSampleCount, 1, CV_32FC1);//样本标识
cvSetZero(sampleLabelMat);

cout<<"************************************************************"<<endl;
cout<<"start to training positive samples..."<<endl;

char positiveImgName[256];
string path;
for(int i=0; i<positiveSampleCount; i++)
{
memset(positiveImgName, '\0', 256*sizeof(char));//将正样本中的256个字节用\n填充
sprintf(positiveImgName, "%d.jpg", i);
int len = strlen(positiveImgName);
string tempStr = positiveImgName;
path = positivePath + tempStr;

cv::Mat img = cv::imread(path);
if( img.data == NULL )
{
cout<<"positive image sample load error: "<<i<<" "<<path<<endl;
system("pause");
continue;
}

cv::HOGDescriptor hog(cv::Size(64,64), cv::Size(16,16), cv::Size(8,8), cv::Size(8,8), 9);
vector<float> featureVec;



hog.compute(img, featureVec, cv::Size(8,8));
int featureVecSize = featureVec.size();

for (int j=0; j<featureVecSize; j++)
{
CV_MAT_ELEM( *sampleFeaturesMat, float, i, j ) = featureVec[j];
}
sampleLabelMat->data.fl[i] = 1;
}
cout<<"end of training for positive samples..."<<endl;

cout<<"*********************************************************"<<endl;
cout<<"start to train negative samples..."<<endl;

char negativeImgName[256];
for (int i=0; i<negativeSampleCount; i++)
{
memset(negativeImgName, '\0', 256*sizeof(char));
sprintf(negativeImgName, "%d.jpg", i);
path = negativePath + negativeImgName;
cv::Mat img = cv::imread(path);
if(img.data == NULL)
{
cout<<"negative image sample load error: "<<path<<endl;
continue;
}

cv::HOGDescriptor hog(cv::Size(64,64), cv::Size(16,16), cv::Size(8,8), cv::Size(8,8), 9);
vector<float> featureVec;

hog.compute(img,featureVec,cv::Size(8,8));//计算HOG特征
int featureVecSize = featureVec.size();

for ( int j=0; j<featureVecSize; j ++)
{
CV_MAT_ELEM( *sampleFeaturesMat, float, i + positiveSampleCount, j ) = featureVec[ j ];
}

sampleLabelMat->data.fl[ i + positiveSampleCount ] = -1;
}

cout<<"end of training for negative samples..."<<endl;
cout<<"********************************************************"<<endl;
cout<<"start to train for SVM classifier..."<<endl;

CvSVMParams params;
params.svm_type = CvSVM::C_SVC;
params.kernel_type = CvSVM::LINEAR;
params.term_crit = cvTermCriteria(CV_TERMCRIT_ITER, 1000, FLT_EPSILON);
params.C = 0.01;

Mysvm svm;
svm.train( sampleFeaturesMat, sampleLabelMat, NULL, NULL, params ); //用SVM线性分类器训练
svm.save(classifierSavePath);

cvReleaseMat(&sampleFeaturesMat);
cvReleaseMat(&sampleLabelMat);

int supportVectorSize = svm.get_support_vector_count();
cout<<"support vector size of SVM:"<<supportVectorSize<<endl;
cout<<"************************ end of training for SVM ******************"<<endl;

CvMat *sv,*alp,*re;//所有样本特征向量
sv = cvCreateMat(supportVectorSize , 1764, CV_32FC1);
alp = cvCreateMat(1 , supportVectorSize, CV_32FC1);
re = cvCreateMat(1 , 1764, CV_32FC1);
CvMat *res = cvCreateMat(1 , 1, CV_32FC1);

cvSetZero(sv);
cvSetZero(re);

for(int i=0; i<supportVectorSize; i++)
{
memcpy( (float*)(sv->data.fl+i*1764), svm.get_support_vector(i), 1764*sizeof(float));
}

double* alphaArr = svm.get_alpha();
int alphaCount = svm.get_alpha_count();

for(int i=0; i<supportVectorSize; i++)


{
alp->data.fl[i] = alphaArr[i];
}
cvMatMul(alp, sv, re);

int posCount = 0;
for (int i=0; i<1764; i++)
{
re->data.fl[i] *= -1;
}

FILE* fp = fopen("d:/hogSVMDetector-peopleFlow.txt","wb");
if( NULL == fp )
{
return 1;
}
for(int i=0; i<1764; i++)
{
fprintf(fp,"%f \n",re->data.fl[i]);
}
float rho = svm.get_rho();
fprintf(fp, "%f", rho);
cout<<"d:/hogSVMDetector.txt 保存完毕"<<endl;//保存HOG能识别的分类器
fclose(fp);

return 1;
}
[解决办法]
工程建立错了
[解决办法]
将项目属性->c/c++->预处理器 中的 _USRDLL ,去掉重新编译试试
[解决办法]
建议楼主重建一个新项目,再将所有源代码加入此新项目试试。
[解决办法]


int Train()
{
……
}


Train是你自定义的函数吗?

[Project] --> [Settings] --> 选择"Link"属性页,
在Project Options中将/subsystem:windows改成/subsystem:console

[Project] --> [Settings] --> 选择"Link"属性页,
在Category中选择Output,
再在Entry-point symbol中填入wWinMainCRTStartup, 即可

读书人网 >C++

热点推荐