opencv中,图像的翻转,图像没有显示出来,只显示出Usage: invImage lena.jpg请大家帮下忙,谢谢……
/*程序名:invImage.c功能:读入图像文件,做图像反转,然后显示图像在屏幕上*/#include<stdlib.h>#include<stdio.h>#inclu...
/* 程序名:invImage.c
功能:读入图像文件,做图像反转,然后显示图像在屏幕上
*/
#include <stdlib.h>
#include <stdio.h>
#include <math.h>
#include <cv.h>
#include <highgui.h>
int main(int argc, char *argv[])
{
IplImage* img = 0;
int height,width,step,channels;
uchar *data;
int i,j,k;
if(argc<2)
{
printf("Usage: invImage lena.jpg \n\7");
exit(0);
}
// 载入图像
img=cvLoadImage(argv[1],1);
if(!img)
{
printf("Could not load image file: %s\n",argv[1]);
exit(0);
}
// 获取图像信息
height = img->height;
width = img->width;
step = img->widthStep;
channels = img->nChannels;
data = (uchar *)img->imageData;
printf("Processing a %dx%d image with %d channels\n",height,width,channels);
// 创建窗口
cvNamedWindow("mainWin", CV_WINDOW_AUTOSIZE);
cvMoveWindow("mainWin", 100, 100);
// 反转图像
for(i=0;i<height;i++) for(j=0;j<width;j++) for(k=0;k<channels;k++)
data[i*step+j*channels+k]=255-data[i*step+j*channels+k];
// 显示图像
cvShowImage("mainWin", img );
cvWaitKey(0);
cvReleaseImage(&img );
return 0;
} 展开
功能:读入图像文件,做图像反转,然后显示图像在屏幕上
*/
#include <stdlib.h>
#include <stdio.h>
#include <math.h>
#include <cv.h>
#include <highgui.h>
int main(int argc, char *argv[])
{
IplImage* img = 0;
int height,width,step,channels;
uchar *data;
int i,j,k;
if(argc<2)
{
printf("Usage: invImage lena.jpg \n\7");
exit(0);
}
// 载入图像
img=cvLoadImage(argv[1],1);
if(!img)
{
printf("Could not load image file: %s\n",argv[1]);
exit(0);
}
// 获取图像信息
height = img->height;
width = img->width;
step = img->widthStep;
channels = img->nChannels;
data = (uchar *)img->imageData;
printf("Processing a %dx%d image with %d channels\n",height,width,channels);
// 创建窗口
cvNamedWindow("mainWin", CV_WINDOW_AUTOSIZE);
cvMoveWindow("mainWin", 100, 100);
// 反转图像
for(i=0;i<height;i++) for(j=0;j<width;j++) for(k=0;k<channels;k++)
data[i*step+j*channels+k]=255-data[i*step+j*channels+k];
// 显示图像
cvShowImage("mainWin", img );
cvWaitKey(0);
cvReleaseImage(&img );
return 0;
} 展开
2个回答
展开全部
试试高版本的openCV吧,Mat比IplImage好用多了。帮你写了下
#include <opencv2\opencv.hpp>
#include<iostream>
using namespace cv;
#include "stdafx.h"
int _tmain(int argc, _TCHAR* argv[])
{
Mat img;
img = imread("D:\\download\\logo.png");
imshow("show", img);
for (int i = 0; i < img.rows; i++)
for (int j = 0; j < (img.cols/2); j++)
{
int tmpB = img.at<Vec3b>(i, j)[0];
int tmpG = img.at<Vec3b>(i, j)[1];
int tmpR = img.at<Vec3b>(i, j)[2];
img.at<Vec3b>(i, j)[0] = img.at<Vec3b>(i, img.cols - j - 1)[0];
img.at<Vec3b>(i, j)[1] = img.at<Vec3b>(i, img.cols - j - 1)[1];
img.at<Vec3b>(i, j)[2] = img.at<Vec3b>(i, img.cols - j - 1)[2];
img.at<Vec3b>(i, img.cols - j - 1)[0] = tmpB;
img.at<Vec3b>(i, img.cols - j - 1)[1] = tmpG;
img.at<Vec3b>(i, img.cols - j - 1)[2] = tmpR;
}
imshow("spieglt", img);
waitKey();
return 0;
}
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询