www.pudn.com > B-spline.zip > test.cpp, change:2012-03-20,size:3125b


#include<cv.h> 
#include<cxcore.h> 
#include<highgui.h> 
#include<math.h> 
#include"bspline.h" 
#include"bsplineinter.h" 
 
#pragma comment (lib,"cv210.lib") 
#pragma comment (lib,"cxcore210.lib") 
#pragma comment (lib,"highgui210.lib") 
 
//#define DRAW_A_BSPLINE				//根据所给出的控制点画出B样条曲线 
//#define DRAW_BSPLINE_BYMOUSE		//通过鼠标点击输入控制点,然后根据这些控制点画出B样条曲线 
#define TEST_BSPLINEINTER			//测试B样条插值 
 
#ifdef TEST_BSPLINEINTER 
 
#include<string.h> 
 
//#define IMAGE_PATH "D:\\MYJPG\\HKQ\\HKQ7.JPG" 
#define IMAGE_PATH "D:\\MYJPG\\animal\\rabbit.jpg" 
#define STRBUFSIZE 128 
 
int main() 
{ 
	char imagename[STRBUFSIZE]; 
	int scale; 
	int len; 
	B_SPLineInter inter; 
 
 
	printf("Please input an image:\n"); 
	fgets(imagename,STRBUFSIZE-1,stdin); 
	printf("Please input the scale(integer):"); 
	scanf("%d",&scale); 
 
	len=strlen(imagename); 
	imagename[len-1]='\0'; 
 
	IplImage *img=cvLoadImage(imagename); 
 
	if(img==NULL) 
	{ 
		fprintf(stderr,"Failed to open file %s.\n",imagename); 
		return -1; 
	} 
	IplImage *imgout=cvCreateImage(cvSize(img->width*scale,img->height*scale),img->depth,img->nChannels); 
	inter.Interpolate(img,imgout,scale); 
 
	cvShowImage("result",imgout); 
	cvShowImage("original",img); 
	cvWaitKey(0); 
	cvDestroyWindow("result"); 
	cvDestroyWindow("original"); 
	cvReleaseImage(&img); 
	cvReleaseImage(&img); 
	cvReleaseImage(&imgout); 
	return 0; 
} 
 
#endif 
 
#ifdef DRAW_BSPLINE_BYMOUSE 
 
#define IMAGE_HEIGHT 480 
#define IMAGE_WIDTH 640 
#define WINDOW_NAME "bspline" 
 
int main() 
{ 
	char key; 
	B_SPLine bspline; 
	IplImage *img=cvCreateImage(cvSize(IMAGE_WIDTH,IMAGE_HEIGHT),8,1); 
	cvNamedWindow(WINDOW_NAME,CV_WINDOW_AUTOSIZE); 
	bspline.InitMouseControlPoint(WINDOW_NAME,img); 
 
	key='a'; 
 
	while(key!='q') 
	{ 
		cvShowImage(WINDOW_NAME,img); 
		key=cvWaitKey(20); 
		if(key=='d') 
			bspline.DrawBSPLine(img); 
	} 
	cvDestroyWindow(WINDOW_NAME); 
	cvReleaseImage(&img); 
 
	return 0; 
} 
 
#endif 
 
#ifdef DRAW_A_BSPLINE 
int main() 
{ 
	ControlPoint tmppoint; 
	B_SPLine bspline; 
 
	IplImage *img=cvCreateImage(cvSize(640,480),8,1); 
 
	tmppoint.point=cvPoint(100,100); 
	bspline.m_ControlPoints.push_back(tmppoint); 
 
	tmppoint.point=cvPoint(100,120); 
	bspline.m_ControlPoints.push_back(tmppoint); 
	tmppoint.point=cvPoint(130,120); 
	bspline.m_ControlPoints.push_back(tmppoint); 
	tmppoint.point=cvPoint(150,140); 
	bspline.m_ControlPoints.push_back(tmppoint); 
	tmppoint.point=cvPoint(160,130); 
	bspline.m_ControlPoints.push_back(tmppoint); 
	tmppoint.point=cvPoint(180,150); 
	bspline.m_ControlPoints.push_back(tmppoint); 
	tmppoint.point=cvPoint(220,160); 
	bspline.m_ControlPoints.push_back(tmppoint); 
	tmppoint.point=cvPoint(210,140); 
	bspline.m_ControlPoints.push_back(tmppoint); 
	tmppoint.point=cvPoint(200,120); 
	bspline.m_ControlPoints.push_back(tmppoint); 
	tmppoint.point=cvPoint(220,100); 
	bspline.m_ControlPoints.push_back(tmppoint); 
 
 
	bspline.DrawBSPLine(img); 
 
 
	cvShowImage("result",img); 
	cvWaitKey(0); 
	cvDestroyWindow("result"); 
	cvReleaseImage(&img); 
	getchar(); 
	return 0; 
} 
 
#endif