图像格式处理,c++,cv::MAt,IplImage
1、cv::mat
string src_im_pth; im_src = cv::imread(src_im_pth, -1); if (im_src.empty()) { fprintf(stderr, "---[wjj] Error! image %s not valid\n", src_im_pth.c_str()); } else { //deal test_img, to ASVLOFFSCREEN ASVLOFFSCREEN ImgDataInput; ImgDataInput.i32Height = im_src.rows; ImgDataInput.i32Width = im_src.cols; ImgDataInput.u32PixelArrayFormat = ASVL_PAF_RGB24_B8G8R8; ImgDataInput.ppu8Plane[0] = im_src.data; ImgDataInput.ppu8Plane[1] = im_src.data + 1; ImgDataInput.ppu8Plane[2] = im_src.data + 2; ImgDataInput.pi32Pitch[0] = ImgDataInput.pi32Pitch[1] = ImgDataInput.pi32Pitch[2] = im_src.step; }
2、IplImage
string src_im_pth; IplImage* tmp_src = cvLoadImage(src_im_pth.c_str());//deal test_img, to ASVLOFFSCREEN ASVLOFFSCREEN GlassSceneInput; GlassSceneInput.i32Height = tmp_src->height; GlassSceneInput.i32Width = tmp_src->width; GlassSceneInput.u32PixelArrayFormat = ASVL_PAF_RGB24_B8G8R8; GlassSceneInput.ppu8Plane[0] = (MUInt8*)tmp_src->imageData; GlassSceneInput.pi32Pitch[0] = tmp_src->widthStep;
cvReleaseImage(&tmp_src);
3、IpIImage转Mat
im_src = cvarrToMat(tmp_src);
4、Mat转IpIImage
cv::Mat src_mat = cv::imread(im_pth); double nWid = src_mat.cols; double nHei = src_mat.rows; IplImage* tmp_src = cvCreateImage(cvSize(nWid, nHei), IPL_DEPTH_8U, 3); *tmp_src = IplImage(src_mat);
5、ASVLOFFSCREEN 转IpIImage再转Mat
cv::Mat mask; ASVLOFFSCREEN *maskData; IplImage * PLimg_mask = cvCreateImage(cvSize(frame.cols, frame.rows), IPL_DEPTH_8U, 1); MMemCpy(PLimg_mask->imageData, maskData->ppu8Plane[0], maskData->pi32Pitch[0] * maskData->i32Height); mask = cv::cvarrToMat(PLimg_mask);