OpenCV图像变换

void OnMirror() 
{
	// TODO: Add your command handler code here
	IplImage* img = cvCreateImage(cvGetSize(GetDocument()->Image), IPL_DEPTH_32F, 0);
	
	// my code start here 
	IplImage* image1 = 0;   
	image1 = cvCloneImage(GetDocument()->Image); 
	
	cvFlip(image1, image1, 1); 
  	cvNamedWindow("src1", CV_WINDOW_AUTOSIZE);
	cvShowImage("src1", image1);
	global_image = cvCloneImage(image1);
}

void OnFlip() 
{
	// TODO: Add your command handler code here
	IplImage* img = cvCreateImage(cvGetSize(GetDocument()->Image), IPL_DEPTH_32F, 0);
	
	// my code start here 
	IplImage* image1 = 0;   
	image1 = cvCloneImage(GetDocument()->Image); 
	
	cvFlip(image1, image1, 0); 
  	cvNamedWindow("src1", CV_WINDOW_AUTOSIZE);
	cvShowImage("src1", image1); 
	global_image = cvCloneImage(image1);   
}

void OnNegative() 
{
	// TODO: Add your command handler code here
	IplImage* img = cvCreateImage(cvGetSize(GetDocument()->Image), IPL_DEPTH_32F, 0);
	// my code start here 
	//	extract image parameters
	IplImage* image1 = 0;   
	image1 = cvCloneImage(GetDocument()->Image); 
	int channels  = image1->nChannels; 
	int height  = image1->height;  
	int width   = image1->width;  
	CvScalar s;

	for(int i=0; i<height; i++) 
		for(int j=0; j<width; j++) 			
		{
			s=cvGet2D(image1, i, j);
			for(int k=0; k<channels; k++) 
			{	
				s.val[k]=255-s.val[k]; 
			}
			cvSet2D(image1, i, j, s);
		}
 
  	cvNamedWindow("src1", CV_WINDOW_AUTOSIZE);
	cvShowImage("src1", image1);  
	global_image = cvCloneImage(image1); 
}

void OnRotate() 
{
	// TODO: Add your command handler code here
	IplImage* img = cvCreateImage(cvGetSize(GetDocument()->Image), IPL_DEPTH_32F, 0);
	// my code start here 
	IplImage* dst = 0; 
	IplImage* image1 = cvCloneImage(GetDocument()->Image); 
    
	/* the first command line parameter must be image file name */
 	//int  delta = 1;
	int  angle;
	int opt = 0;   // 0:  仅仅旋转                        

	dst = cvCloneImage( image1 );
	
	DLG3 dlg;
	if( dlg.DoModal() == IDOK )
	{
		//angle = m_degre;
		angle =(float) dlg.m_degre/2;	   
		float m[6];
				// Matrix m looks like:
				//
				// [ m0  m1  m2 ] ===>  [ A11  A12   b1 ]
				// [ m3  m4  m5 ]       [ A21  A22   b2 ]
				// 
		CvMat M = cvMat( 2, 3, CV_32F, m );
		int w = image1->width;
		int h = image1->height;
		
		double factor = 1;
		m[0] = (float)(factor*cos(-angle*2*CV_PI/180.));
		m[1] = (float)(factor*sin(-angle*2*CV_PI/180.));
		m[3] = -m[1];
		m[4] = m[0];
		// 将旋转中心移至图像中间
                m[2] = w*0.5f;  
		m[5] = h*0.5f;  
  
				//  dst(x,y) = A * src(x,y) + b
		cvZero(dst);
		cvGetQuadrangleSubPix( image1, dst, &M);
		cvNamedWindow( "dst", 1 );
		cvShowImage( "dst", dst );
		global_image = cvCloneImage(dst);

	//angle =(int) (angle + delta) % 360;
	} // for-loop
}

void OnResample() 
{
	// TODO: Add your command handler code here
	IplImage* img = cvCreateImage(cvGetSize(GetDocument()->Image), IPL_DEPTH_32F, 0);
	// my code start here 
	
	IplImage* image1 = cvCloneImage(GetDocument()->Image); 
  	image1 = cvCloneImage(GetDocument()->Image); 
	int channels  = image1->nChannels; 
	int height  = image1->height;  
	int width   = image1->width; 
	int step    = image1->widthStep;   
	/* the first command line parameter must be image file name */
 	//int  delta = 1;
	IplImage *dst = 0;			//目标图像指针    
        CvSize dst_cvsize;			//目标图像尺寸
	float scale;


	DLG3 dl3g;
	if( dl3g.DoModal() == IDOK )
	{
		//scale = 2.0;	  //缩放倍数 
		scale = (float) dl3g.m_degre;	 
		
		//float 
		dst_cvsize.width = (int)width * scale;		//目标图像的宽为源图象宽的scale倍    
		dst_cvsize.height = (int)height * scale;	//目标图像的高为源图象高的scale倍     
		dst = cvCreateImage( dst_cvsize, image1->depth, image1->nChannels);	//构造目标图象    
		cvResize(image1, dst, CV_INTER_LINEAR);	//缩放源图像到目标图像
	
		cvNamedWindow( "dst", 1 );
		cvShowImage( "dst", dst );
		global_image = cvCloneImage(dst);

		//angle =(int) (angle + delta) % 360;
	} 
}

void OnRotateLeft() 
{
	// TODO: Add your command handler code here
	IplImage* img = cvCreateImage(cvGetSize(GetDocument()->Image),IPL_DEPTH_32F, 0);
	
	IplImage* image1 = cvCloneImage(GetDocument()->Image);  
	int height  = image1->height;  
	int width   = image1->width;  
	int channels  = image1->nChannels;  
 
	IplImage* image2 = cvCreateImage(cvSize(height, width),
					  IPL_DEPTH_8U,
					  channels);
	
	//  convert the inoput image to gray image 
	cvTranspose(image1, image2);     // two  
	cvFlip(image2, image2, 0);       // 倒置   
	cvNamedWindow("dst", CV_WINDOW_AUTOSIZE);
	cvShowImage("dst", image2);	 
	global_image = cvCloneImage(image2);

}

void OnRotateRight() 
{
	// TODO: Add your command handler code here
	IplImage* img = cvCreateImage(cvGetSize(GetDocument()->Image),IPL_DEPTH_32F, 0);
	
	IplImage* image1 = cvCloneImage(GetDocument()->Image);  
	int height  = image1->height;  
	int width   = image1->width;  
	int channels  = image1->nChannels;  
 
	IplImage* image2 = cvCreateImage(cvSize(height, width),
					  IPL_DEPTH_8U,
					  channels);
	
	//  convert the inoput image to gray image 
	cvTranspose(image1, image2);     // two  
	cvFlip(image2, image2, 1);       // 倒置   
	cvNamedWindow("dst", CV_WINDOW_AUTOSIZE);
	cvShowImage("dst", image2);	
	global_image = cvCloneImage(image2);

}

void OnGrayScale() 
{
	// TODO: Add your command handler code here
	IplImage* img = cvCreateImage(cvGetSize(GetDocument()->Image),IPL_DEPTH_32F, 0);
	
	IplImage* image1 = cvCloneImage(GetDocument()->Image);  
	int w = image1->width;

	IplImage* image2 = cvCreateImage(cvGetSize(image1),
					  IPL_DEPTH_8U,
					  1);
	
	//  convert the inoput image to gray image 
	cvCvtColor(image1, image2, CV_BGR2GRAY);

	cvNamedWindow("dst", CV_WINDOW_AUTOSIZE);
	cvShowImage("dst", image2);	
	global_image = cvCloneImage(image2);
}

void OnQuasiColor() 
{
	// TODO: Add your command handler code here
	IplImage* img = cvCreateImage(cvGetSize(GetDocument()->Image),IPL_DEPTH_32F, 0);
	
	IplImage* image1 = cvCloneImage(GetDocument()->Image);  
	IplImage* image2 = cvCreateImage(cvGetSize(image1),
					  IPL_DEPTH_8U,
					  3);
	IplImage* image3 = cvCreateImage(cvGetSize(image1),
					  IPL_DEPTH_8U,
					  1);
	CvScalar s, s1;
	float gry;
	int width = image1->width;
	int height = image1->height;
	int channels  = image1->nChannels; 	
	
	if(channels==3)
		image2 = cvCloneImage(image1);  
	else
	{
		cvCvtColor(image1, image3, CV_BGR2GRAY);  
		for(int i=0; i<height; i++) 
			for(int j=0; j<width; j++) 			
			{
				s1=cvGet2D(image3, i, j);
			    gry=s1.val[0]; 		
				switch((int)gry/85)  
				{
					case 0:
						s.val[2] = 0;
						s.val[1] = 255*sin(CV_PI*3*s1.val[0]/2/256);
						s.val[0] = 255*cos(CV_PI*3*s1.val[0]/2/256);
						break;
					case 1:
						s.val[2] = 255*cos(CV_PI+CV_PI*3*s1.val[0]/2/256);
						s.val[1] = 255*sin(CV_PI*3*s1.val[0]/2/256);
						s.val[0] = 0;
					break;
					case 2:
						 s.val[2] =255*cos(CV_PI+CV_PI*3*s1.val[0]/2/256);
						 s.val[1] = 0;
						 s.val[0] = 255*sin(CV_PI+CV_PI*3*s1.val[0]/2/256);
						 break;
					case 3:
						s.val[2] = 255;
						s.val[1] = 255;
						s.val[0] = 255;
						break;
					}  
				cvSet2D(image2, i, j, s);
			}

	}
	cvNamedWindow("dst", CV_WINDOW_AUTOSIZE);
	cvShowImage("dst", image2);	 
	global_image = cvCloneImage(image2);
}

评论 2
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值