欢迎大家加入图像识别技术交流群:271891601,另外,特别欢迎成都从事图像识别工作的朋友交流,我的QQ号248787278
-------------------------------------------
// 从文件中加载原图
IplImage *pSrcImage = cvLoadImage("coins.png", CV_LOAD_IMAGE_UNCHANGED);
//输出图像到硬盘
cvSaveImage("D:\\saveImage.jpg",image);
//创建输出的图像
IplImage *pOutImage_8U = cvCreateImage(cvGetSize(pSrcImage), IPL_DEPTH_8U,1);IplImage *pOutImage_64F = cvCreateImage(cvGetSize(pSrcImage), IPL_DEPTH_64F,1);
// 转为灰度图
IplImage *g_pGrayImage = cvCreateImage(cvGetSize(pSrcImage), IPL_DEPTH_8U, 1);
cvCvtColor(pSrcImage, g_pGrayImage, CV_BGR2GRAY);
//获取并改变某个像素的值
s = cvGet2D(img,i,j); // get the (i,j) pixel value
s.val[0]=255;
s.val[1]=34;
s.val[2]=123;cvSet2D(img,i,j,s);//set the (i,j) pixel value
//如果是灰度图像,则是下面的代码
s1 = cvGet2D(img,i,j).val[0]; // get the (i,j) pixel value
CvScalar s2;
s2.val[0]=X;
cvSet2D(img,i,j,s2);//set the (i,j) pixel value
//观察中间变量值
①图像像素值
double watch_pOutImage_64[100];
int i;
for(i=0;i<100;i++)
{
watch_pOutImage_64[i]=cvGet2D(pOutImage_64F,0,i).val[0];
}
②图像直方图值
double watch_hist[256];
int k;
for(k=0;k<256;k++)
{
watch_hist[k]=cvQueryHistValue_1D(hist,k);
}
//数据存储格式的转换
cvConvertScale(pSrcImage,pOutImage_64F);
//图像长和宽的转换
M=pSrcImage->height;
N=pSrcImage->width;
//显示图像到Windows窗口
const char *pstrWindowsTitle = "Windows窗口的标题"; //创建窗口 cvNamedWindow(pstrWindowsTitle, CV_WINDOW_AUTOSIZE); //在指定窗口中显示图像 cvShowImage(pstrWindowsTitle, pImage); //等待按键事件 cvWaitKey(); cvDestroyWindow(pstrWindowsTitle); cvReleaseImage(&pImage);
//