#include "opencv2/opencv.hpp"
using namespace cv;
int main()
int frameHeight = img.rows;
IplImage* _pImg = cvCreateImage(cvSize(frameWidth, frameHeight), 8, framenChannels);
for (int i = 0; i < frameHeight; i++)
{
for (int j = 0; j < frameWidth; j++)
{
_pImg->imageData[(i*frameWidth + j) * 3 + 0] = buf[i*framewidthStep + j * 3 + 0];
_pImg->imageData[(i*frameWidth + j) * 3 + 1] = buf[i*framewidthStep + j * 3 + 1];
_pImg->imageData[(i*frameWidth + j) * 3 + 2] = buf[i*framewidthStep + j * 3 + 2];
}
}
uchar* data = new uchar[IplImage->width * IplImage->height];
memcpy_s(data, IplImage->width * IplImage->height, IplImage->imageData, IplImage->width * IplImage->height);
//uchar 转mat
Mat image(frameHeight, frameWidth, CV_8UC3, buf);
imshow("image", image);
waitKey();
}
using namespace cv;
int main()
{
//图片路径
string image_name = "H:\\vegData\\1\\yuanshi\\dongua\\IMG_20170407_132802_BURST1.jpg";Mat img = imread(image_name);
IplImage *pImg;
int frameWidth = img.cols;int frameHeight = img.rows;
int framenChannels = 3;
pImg = &(IplImage)img;int framewidthStep = pImg->widthStep;
uchar *buf, *src;
//Mat 转uchar
buf=img.data;
//uchar 转iplimage
//----------------------------------------------------------------------------------------------------------------------------------IplImage* _pImg = cvCreateImage(cvSize(frameWidth, frameHeight), 8, framenChannels);
for (int i = 0; i < frameHeight; i++)
{
for (int j = 0; j < frameWidth; j++)
{
_pImg->imageData[(i*frameWidth + j) * 3 + 0] = buf[i*framewidthStep + j * 3 + 0];
_pImg->imageData[(i*frameWidth + j) * 3 + 1] = buf[i*framewidthStep + j * 3 + 1];
_pImg->imageData[(i*frameWidth + j) * 3 + 2] = buf[i*framewidthStep + j * 3 + 2];
}
}
//------------------------------------------------------------------------------------------------------------------------------------------
uchar* data = new uchar[IplImage->width * IplImage->height];
memcpy_s(data, IplImage->width * IplImage->height, IplImage->imageData, IplImage->width * IplImage->height);
//uchar 转mat
Mat image(frameHeight, frameWidth, CV_8UC3, buf);
imshow("image", image);
waitKey();
}