opencv 图像显示IplImage

图像显示的origin属性改变 (原点的改变)

#include <opencvcv.h>
#include <opencvhighgui.h>
#include <opencvcxcore.h>
#include <stdlib.h>
#include <stdio.h>
 
int main(int argc, char* argv[]){
	
	IplImage* img;
	img=cvLoadImage("d://1.jpg");

	//原点显示 默认值 0:左上角是原点 1:左下角是原点
	img->origin=1;

	//输出图像通道数 3通道图像RGB模式
	printf("nChannels is %d",img->nChannels);
	cvNamedWindow("1");
	cvShowImage("1",img);
	cvWaitKey(0);
	return 0;
}


三个颜色通道分割显示:

#include <opencvcv.h>
#include <opencvhighgui.h>
#include <opencvcxcore.h>
#include <stdlib.h>
#include <stdio.h>
 

int main(int argc, char* argv[])
{
        IplImage* img , *sub_img;
        int y,x;
        //加载图像1.jpg
        img = cvLoadImage("d:\1.jpg");
        
    /*   将3通道图像 分解成 3幅单通道的图像 */
        
        //声明三个图像变量
        IplImage* b_img ,*g_img,*r_img;
 
        //给三个单通图像 分配内存空间
        b_img = cvCreateImage(cvGetSize(img),IPL_DEPTH_8U , 1 );
        g_img = cvCreateImage(cvGetSize(img),IPL_DEPTH_8U , 1 );
        r_img = cvCreateImage(cvGetSize(img),IPL_DEPTH_8U , 1 );
 
        for(y=0;y<img->height;y++)
        {
                //将图像指针偏移到第y行
                unsigned char* prow = (unsigned char*)(  img->imageData + y*  img->widthStep);
                unsigned char* brow = (unsigned char*)(b_img->imageData + y*b_img->widthStep);
                unsigned char* grow = (unsigned char*)(g_img->imageData + y*g_img->widthStep);
                unsigned char* rrow = (unsigned char*)(r_img->imageData + y*r_img->widthStep);

                for(x=0;x<img->width;x++)
                {
                        //将B通道  G通道  R通道的值 分别拷贝到3个单通道的图像中去
                        brow[x] = prow[3*x + 0] ; //拷贝B通道的值prow[3*x + 0] 到 单通道图像b_img
                        grow[x] = prow[3*x + 1] ; //拷贝G通道的值prow[3*x + 0] 到 单通道图像b_img
                        rrow[x] = prow[3*x + 2] ; //拷贝R通道的值prow[3*x + 0] 到 单通道图像b_img
                }
        }
        //创建3个窗口
        cvNamedWindow("b");
        cvNamedWindow("g");
        cvNamedWindow("r");

        //显示b  g r三个通道的图像
        cvShowImage("b" , b_img);
        cvShowImage("g" , g_img);
        cvShowImage("r" , r_img);
 
        //显示大图像
        cvNamedWindow("1");
        cvShowImage("1",img);

        //等待按键
        cvWaitKey(0);
 
        //释放内存空间
        cvReleaseImage(&img);

        return 0;
 
}

++

人脸覆盖简单技术:

#include <opencvcv.h>
#include <opencvhighgui.h>
#include <opencvcxcore.h>
#include <stdlib.h>
#include <stdio.h>
 

 
int main(int argc, char* argv[])
 
{
        IplImage* img , *sub_img;
        int y,x;
 
        //加载图像1.jpg
        img = cvLoadImage("C:\Users\zxl\Desktop\1.jpg");

        //加载图像4.jpg
        sub_img = cvLoadImage("C:\Users\zxl\Desktop\4.jpg");

        //设置一个感兴趣区域
 
        CvRect rect;
 
        rect.x = 457;
        rect.y = 200 ;
 
        rect.width = sub_img->width;
        rect.height = sub_img->height;

		///方法1
		///////////////////////////////////
        ////将小图像 拷贝 到大图像的 roi区域
        //for( y=0;y<sub_img->height;y++)
        //{
		//		  //将指针偏移到第Y行
        //        unsigned char* subImgData = (unsigned char*)(sub_img->imageData + y*sub_img->widthStep);
        //        //将目标大图像指针偏移到第 (rect.y = 200)+1行上(进行覆盖)
		//		  unsigned char* bigImgData = (unsigned char*)(img->imageData     + (y+rect.y)*img->widthStep);
        //
        //        for( x=0;x<sub_img->width;x++)
        //        {
		//				//偏移到第x个像素
		//				//B通道
        //                bigImgData[3*(x+rect.x) + 0 ] = subImgData[3*x + 0 ];
        //              //G通道  
		//				  bigImgData[3*(x+rect.x) + 1 ] = subImgData[3*x + 1 ];
		//				//R通道	
        //                bigImgData[3*(x+rect.x) + 2 ] = subImgData[3*x + 2 ];
        //        }
        //}
		///////////////////////////////////

        //使用opencv中的函数 设置roi区域
 
        cvSetImageROI(img , rect);
		
		///方法2
		///////////////////////////////////
		cvCopy(sub_img,img);
		///////////////////////////////////
		
        //使用完 ROI区域后  要调用函数释放roi区域
        cvResetImageROI(img);
 
        //显示大图像
        cvNamedWindow("1");
        cvShowImage("1",img);
 
        //等待按键
        cvWaitKey(0);

        //释放内存空间
 
        /*cvReleaseImage(&img);
 
        cvReleaseImage(&sub_img);*/
 

        return 0;
 
}


 

效果:


 

原文地址:https://www.cnblogs.com/bbsno1/p/3265424.html