图像镜像之竖直镜像

原理简单,代码如下:

void Ctry::OnTryTyr1()
{
	 //TODO:  在此添加命令处理程序代码
	IplImage *img = cvLoadImage("C:\\Users\\Administrator\\Desktop\\3838.jpg");
	IplImage *mirror = cvCreateImage(cvGetSize(img), IPL_DEPTH_8U, 3);
	CvScalar pixel;
	int u = 0;
	for (int i = 0; i < img->width; i++)
	{	
		for (int j = 0; j < img->height; j++)
		{
			u = img->height - j - 1;
			pixel = cvGet2D(img, u, i);
			cvSet2D(mirror, j, i, pixel);
			
		}
	}
	
	cvNamedWindow("mirror", CV_WINDOW_AUTOSIZE);
	cvShowImage("mirror", mirror);
	cvNamedWindow("img", CV_WINDOW_AUTOSIZE);
	cvShowImage("img", img);
	cvWaitKey(0);

	cvReleaseImage(&img);
	cvReleaseImage(&mirror);
	cvDestroyWindow("mirror");
	cvDestroyWindow("img");
}


效果见图: 图像镜像之竖直镜像_第1张图片  图像镜像之竖直镜像_第2张图片

你可能感兴趣的:(图像镜像,竖直镜像)