作者:gnuhpc
出处:http://www.cnblogs.com/gnuhpc/
#pragma comment( lib, "cxcore.lib" ) #pragma comment( lib, "cv.lib" ) #pragma comment( lib, "highgui.lib" ) #include <cv.h> #include <highgui.h> #include <stdio.h> int main(int argc, char** argv) { IplImage *src,*sub_img; cvNamedWindow("Example3_13_pre", CV_WINDOW_AUTOSIZE); cvNamedWindow("Example3_13_post", CV_WINDOW_AUTOSIZE); src = cvLoadImage("dog.jpg"); int x = 150; int y = 300; int width = 200; int height = 200; int add = 150; //子窗口的初始化 sub_img = cvCreateImageHeader(cvSize(width, height),src->depth,src->nChannels); sub_img->origin = src->origin; //子窗口的widthStep和主窗口的widthStep相等 sub_img->widthStep = src->widthStep; //注意这个公式,子窗口的图像数据指针首地址指向了主窗口中由子窗口左上角坐标x,y指定的相应位置 sub_img->imageData = src->imageData + y * src->widthStep + x * src->nChannels; cvShowImage( "Example3_13_pre", src); cvAddS(sub_img, cvScalar(add),sub_img); cvShowImage( "Example3_13_post",src); cvWaitKey(); cvReleaseImage( &src ); //释放子窗口的头部资源 cvReleaseImageHeader(&sub_img); cvDestroyWindow("Example3_13_pre"); cvDestroyWindow("Example3_13_post"); return 0; }
作者:gnuhpc
出处:http://www.cnblogs.com/gnuhpc/
作者:gnuhpc
出处:http://www.cnblogs.com/gnuhpc/
除非另有声明,本网站采用知识共享“署名 2.5 *”许可协议授权。