// Gray32to8.cpp : 定义控制台应用程序的入口点。
//
#include "stdafx.h"
#include "cv.h"
#include "highgui.h"
#include "cxcore.h"
#include "cvaux.h"
#include <string>
#include <fstream>
#include <iostream>
using namespace std;
int _tmain(int argc, _TCHAR* argv[])
{
int i,j;
IplImage* img = NULL; // 原图
IplImage* dst=NULL;//灰度图
unsigned char DataArry[480][640];
img = cvLoadImage("13.BMP",1);
dst=cvCreateImage(cvSize(img->width,img->height),IPL_DEPTH_8U,1);
cvCvtColor(img, dst, CV_RGB2GRAY);
ofstream mf("13.txt");
for (i=0; i<img->height; i++)
{
mf<<"{";
for (j=0; j<img->width; j++)
{
DataArry[i][j] = ((dst->imageData + dst->widthStep*i))[j];
mf<<(int)DataArry[i][j];
if (j < img->width-1)
{
mf<<",";
}
else
{
mf<<"},";
mf<<"/r/t";
}
}
}
mf.close();
//cvSaveImage()
return 0;
}
这是一个C++程序,用于将32位或其他格式的图像转换为灰度图,并将处理后的图像数据保存到文本文件中。程序使用OpenCV库,通过cvLoadImage加载图像,cvCvtColor进行颜色转换,最后将结果写入到指定的文本文件中。
2162

被折叠的 条评论
为什么被折叠?



