您的位置:首页 > 运维架构

用OpenCV保存处理的图片

2013-10-21 15:35 375 查看
1. 用OpenCV保存处理的图片

#include "./include/cv.h"

#include"./include/cxcore.h"

#include "./include/highgui.h"

IplImage*image = cvCreateImage(cvSize(m_nWidth, m_nHeight), IPL_DEPTH_8U, 1);

cvZero(image);

memcpy(image->imageData,(BYTE*)m_lpszImgSrc, m_nWidth*m_nHeight*sizeof(BYTE));

cvFlip(image);

cvSaveImage("e:\\project\\camera.bmp",image);

cvReleaseImage(&image);

2.求窗口和客户区域之间的空白

CRectrt,wndRect,MainRect,clntRect;

m_stat_Img.GetClientRect(rt);

GetWindowRect(MainRect);

GetClientRect(clntRect);

m_stat_Img.GetWindowRect(wndRect);

long x =(abs((MainRect.left+clntRect.right-clntRect.left)-MainRect.right))/2;

long y = abs((MainRect.top+clntRect.bottom-clntRect.top)-MainRect.bottom)-x;

long iL = abs((wndRect.left - MainRect.left));

long iT = abs((wndRect.top - MainRect.top));

iL = abs(x-iL);

iT = abs(y-iT);

3.MFC保存位图到路径

CStringstr="22.bmp";

m_PathName = str;

CFile file;

file.Open(str,CFile::modeWrite |CFile::modeCreate);

SaveDIB(m_hDIB,file);

file.Close();

4.MFC从路径读取位图

if(lpszPathName)

{

if(!m_Image.AttachFromFile(lpszPathName))

{

EndWaitCursor();

AfxMessageBox("打开文件时出错!请确保正确的位图(*.bmp)文件类型。");

return ;

}

}

// 判断读取成功否

if (!m_Image.m_lpData)

{

// 失败,可能非BMP格式

CString strMsg;

strMsg = "读取图像时出错!可能是不支持该类型的图像文件!";

// 提示出错

AfxMessageBox(/*NULL,*/ strMsg/*,"系统提示", MB_ICONINFORMATION | MB_OK*/);

// 返回FALSE

return ;

}
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: