|||
/***********************************************
*功能:在当前窗口中显示IplImage的图像
*输入参数:src 指向图片的指针
*输出参数:无
*返回值:无
*作者:张建成
***********************************************/
void ShowImage(IplImage *src)
{
if(src->nChannels==3)// color
{
TheImage=cvCloneImage(src);
IplImage *TheImage = src;
CvSize ImgSize;
ImgSize.width = TheImage->width;
ImgSize.height = TheImage->height;
CClientDC dc(this);
CDC * pDC = &dc;
int res = StretchDIBits(pDC->GetSafeHdc(),0,0,int(TheImage->width),int(TheImage->height),
0,0,TheImage->width,TheImage->height,TheImage->imageData,
(BITMAPINFO*)bmi,DIB_RGB_COLORS,SRCCOPY);
}
else
{
if(src->nChannels==1)// gray
{
IplImage *grayImg=cvCreateImage(cvSize(src->width,src->height),IPL_DEPTH_8U,3);
IplImage * planes[3] ={0,0,0};
for(int i=0;i<3;i++)
{
planes[i] = cvCreateImage(cvSize(src->width,src->height),8,1);
(planes[i]->imageData)= (src->imageData);
}
cvCvtPlaneToPix(planes[0],planes[1],planes[2],0,grayImg);
IplImage * TheImage=cvCloneImage(grayImg);
CvSize ImgSize;
ImgSize.width = TheImage->width;
ImgSize.height = TheImage->height;
CClientDC dc(this);
CDC * pDC = &dc;
int res = StretchDIBits(pDC->GetSafeHdc(),0,0,int(TheImage->width),int(TheImage->height),
0,0,TheImage->width,TheImage->height,TheImage->imageData,
(BITMAPINFO*)bmi,DIB_RGB_COLORS,SRCCOPY);
}
}
}
Archiver|手机版|科学网 ( 京ICP备07017567号-12 )
GMT+8, 2024-11-23 09:38
Powered by ScienceNet.cn
Copyright © 2007- 中国科学报社