这是我的代码:
// Image Processing.cpp : Defines the entry point for the console application.
//
//Save an available image.
#include "stdafx.h"
#include "cv.h"
#include "highgui.h"
#include "cxcore.h"
#include <sstream>
#include <string>
#include <iostream>
/*HW5
*/
int _tmain(int argc, _TCHAR* argv[])
{
IplImage* src = cvLoadImage("D:\\document\\Study\\university of technology\\semester_8\\Computer Vision\\Pics for test\\color_3.jpg");
IplImage* dst_1 = cvCreateImage(cvGetSize(src),8,3);
IplImage* dst_2 = cvCreateImage(cvGetSize(src),8,1);
IplImage* gray = cvCreateImage(cvGetSize(src),8,1);
//step 1: filter undesired colored items => retain only red items.
CvScalar s,c;
for(int i = 0; i < (src->height); i++)
{
for(int j = 0; j < (src->width); j++)
{
s = cvGet2D(src,i,j);
//s.val[2]=Kenh R,s.val[1]=Kenh G,s.val[0]=Kenh B
if( (s.val[2] > 210)&&(s.val[1] < 50)&&(s.val[0]<50) )
{
c.val[2] = 250;
c.val[1] = 0;
c.val[0] = 0;
cvSet2D(dst_1,i,j,c);
}
else
{
c.val[2] = 255;
c.val[1] = 255;
c.val[0] = 255;
cvSet2D(dst_1,i,j,c);
}
}
}
//step 2: calculate & add the result into image
cvCvtColor(dst_1,gray,CV_RGB2GRAY);
cvThreshold(gray,dst_2,100,255,CV_THRESH_BINARY);
CvSeq* contours = 0;
CvMemStorage* storage = cvCreateMemStorage(0);
int n = 0;
cvFindContours(dst_2,storage,&contours);
CvSeq* result;
CvPoint* p;
for(CvSeq* c = contours; c != NULL; c = c->h_next)//consider each contour
{
n++;
result = cvApproxPoly(c,
sizeof(CvContour),
storage,
CV_POLY_APPROX_DP,
cvContourPerimeter(c)*0.02,
0);
p = (CvPoint*)cvGetSeqElem(result,0);
for(int k1 = 1; k1 < result->total; k1++)//consider each point of a paticular contour
{
CvPoint* temp = (CvPoint*)cvGetSeqElem(result,k1);
if(p->y < temp->y)
p = temp;
}
//calculate Contour Area
double a;
a = cvContourArea(c,CV_WHOLE_SEQ);
if(a < 0.0)
a = -a;
std::ostringstream s;
s << a;
std::string output = "S = " + s.str();
const char* text1 = output.c_str();
//display result on image
double hscale = 1.0;
double vscale = 0.8;
double shear = 0.2;
int thickness = 1;
int line_type = 8;
CvScalar blue = CV_RGB(0,0,250);
CvPoint pt1 = cvPoint(p->x - n*40,p->y + 30);
CvFont font1;
cvInitFont(&font1,CV_FONT_HERSHEY_DUPLEX,hscale,vscale,shear,thickness,line_type);
cvPutText(dst_1,text1,pt1,&font1,blue);
}
cvNamedWindow("src",1);
cvNamedWindow("dst_1",1);
cvShowImage("src",src);
cvShowImage("dst_1",dst_1);
cvWaitKey(0);
cvReleaseImage(&src);
cvDestroyAllWindows();
return 0;
}
调试后,有2个错误如下:
1-error LNK1120: 1 unresolved externals.
2/-error LNK2019: unresolved external symbol _cvRodrigues2 referenced in function
"void __cdecl icvRandomQuad(int,int,double (* const)[2],double,double,double)"
(?icvRandomQuad@@YAXHHQAY01NNNN@Z).
我该如何解决?希望得到帮助!