在Header Files中的***.h中定义函数名:
void TranImgH(IplImage *cImg, IplImage *hImg);
在Source Files中添加函数功能:
void CImageProcessing_2View::TranImgH(IplImage *cImg, IplImage *hImg)
{
uchar *data= (uchar *)cImg->imageData;//show color
int wp = cImg->widthStep;
uchar *data1= (uchar *)hImg->imageData;//show h
int wp1 = hImg->widthStep;
for(int i = 0; i < cImg->height; i++)
{
for(int j = 0; j < cImg->width;j++)
{
int r = data[i * wp + 3 * j];
int g = data[i * wp + 3 * j + 1];
int b = data[i * wp + 3 * j + 2];
data1[i * wp1 + 3 * j] = data[i * wp + 3 * (cImg->width-j-1)];//防止数组越界,0~255
data1[i * wp1 + 3 * j + 1] = data[i * wp + 3 * (cImg->width-j-1) + 1];
data1[i * wp1 + 3 * j + 2] = data[i * wp + 3 * (cImg->width-j-1) + 2];
}
}
}
//垂直翻转只需要将函数更名为TranImgP()
修改部分内容:
data1[i * wp1 + 3 * j] = data[(cImg->height-i-1) * wp + 3 * j];//防止数组越界,0~255
data1[i * wp1 + 3 * j + 1] = data[(cImg->height-i-1) * wp + 3 * j + 1];
data1[i * wp1 + 3 * j + 2] = data[(cImg->height-i-1) * wp + 3 * j + 2];
//
界面水平翻转的映射函数:
void CImageProcessing_2View::OnImgTranh()
{
// TODO: Add your command handler code here
CImageProcessing_2Doc pDoc = GetDocument();
ASSERT_VALID(pDoc);
IplImage hImg = cvCreateImage(cvSize(pDoc->m_img.Width(),pDoc->m_img.Height()),8,3);
//cvCreateImage( CvSize size, int depth, int channels )
TranImgH(pDoc->m_img.GetImage(),hImg);
cvSaveImage(“D:\ImageProcessing\Pictures\TranImageH.jpg”,hImg);
//cvSaveImage( const char filename, const CvArr image )
pDoc->m_img.Load(“D:\ImageProcessing\Pictures\TranImageH.jpg”);
Invalidate();
}