代码如下:
(一)三通道分开分别镜像代码如下:
void Ctry::OnTryTyr1() { //TODO: 在此添加命令处理程序代码 IplImage *img = cvLoadImage("C:\\Users\\Administrator\\Desktop\\3838.jpg"); IplImage *mirror = cvCreateImage(cvGetSize(img), IPL_DEPTH_8U, 3); IplImage* r = cvCreateImage(cvGetSize(img), IPL_DEPTH_8U, 1); IplImage* g = cvCreateImage(cvGetSize(img), IPL_DEPTH_8U, 1); IplImage* b = cvCreateImage(cvGetSize(img), IPL_DEPTH_8U, 1); IplImage* r1 = cvCreateImage(cvGetSize(img), IPL_DEPTH_8U, 1); IplImage* g1 = cvCreateImage(cvGetSize(img), IPL_DEPTH_8U, 1); IplImage* b1 = cvCreateImage(cvGetSize(img), IPL_DEPTH_8U, 1); cvSplit(img, b, g, r, NULL); double temp1=0, temp2=0, temp3=0; int u = 0; for (int i = 0; i < r->width; i++) { u = r->width - i - 1; for (int j = 0; j < r->height; j++) { temp1 = cvGetReal2D(r, j , u); temp2 = cvGetReal2D(g, j , u); temp3 = cvGetReal2D(b, j , u); cvSetReal2D(r1, j, i, temp1); cvSetReal2D(g1, j, i, temp2); cvSetReal2D(b1, j, i, temp3); } } cvMerge(b1, g1, r1, 0, mirror); cvNamedWindow("move", CV_WINDOW_AUTOSIZE); cvShowImage("move", mirror); cvSaveImage("C:\\Users\\Administrator\\Desktop\\mirror.jpg", mirror); cvNamedWindow("img", CV_WINDOW_AUTOSIZE); cvShowImage("img", img); cvWaitKey(0); cvReleaseImage(&img); cvReleaseImage(&r); cvReleaseImage(&g); cvReleaseImage(&b); cvReleaseImage(&r1); cvReleaseImage(&g1); cvReleaseImage(&b1); cvReleaseImage(&mirror); cvDestroyWindow("move"); cvDestroyWindow("img"); }
(二)直接总体镜像代码如下:
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++) { u = img->width - i - 1; for (int j = 0; j < img->height; j++) { pixel = cvGet2D(img, j, u); cvSet2D(mirror, j, i, pixel); } } cvNamedWindow("mirror", CV_WINDOW_AUTOSIZE); cvShowImage("mirror", mirror); cvSaveImage("C:\\Users\\Administrator\\Desktop\\mirror.jpg", mirror); cvNamedWindow("img", CV_WINDOW_AUTOSIZE); cvShowImage("img", img); cvWaitKey(0); cvReleaseImage(&img); cvReleaseImage(&mirror); cvDestroyWindow("mirror"); cvDestroyWindow("img"); }