opencv将图像转换成二维数组再将数组数据传给新图像

#include
#include
#include "cv.h"
#include "highgui.h"

using namespace std;

int main(int argc, char** argv)
{
	cout << "进入系统----------->" << endl;
	//读入图片,将矩阵拉成一行
	IplImage* img = cvLoadImage("F:\\temp\\00.jpg", 0);
	cvNamedWindow("原图", CV_WINDOW_AUTOSIZE);
	cvShowImage("原图", img);
	CvSize imgsize;
	imgsize.height = 288;
	imgsize.width = 352;
	//格式转换
	cv::Mat matimage = cv::cvarrToMat(img);
	unsigned char imgmat[288][352];
	
	
	for (size_t nrow = 0; nrow < matimage.rows; nrow++)
	{
		for (size_t ncol = 0; ncol < matimage.cols; ncol++)
		{
			imgmat[nrow][ncol] = matimage.at(nrow, ncol);
		
		}
	}
	//定义新空图像
	IplImage *src = cvCreateImage(imgsize, IPL_DEPTH_8U, 1);

	//将数组数据传给图像
	src->imageData = (char*)imgmat;
	cvNamedWindow("生成", CV_WINDOW_AUTOSIZE);
	cvShowImage("生成", src);


	cvNamedWindow("window", CV_WINDOW_AUTOSIZE);
	cvShowImage("window", img);
	cvWaitKey(0);
	cvReleaseImage(&img);
	cvDestroyWindow("window");
}

 

opencv将图像转换成二维数组再将数组数据传给新图像_第1张图片

 

你可能感兴趣的:(opencv)