logo资料库

opencv中在MFC下的图像放大缩小.doc

第1页 / 共3页
第2页 / 共3页
第3页 / 共3页
资料共3页,全文预览结束
void CPsView::OnRimg(IplImage*inputImg,IplImage*RImg)//单通道处理 { uchar *data= (uchar *)inputImg->imageData; int wp = inputImg->widthStep; uchar *data1= (uchar *)RImg->imageData; int wp1 = RImg->widthStep; for(int i = 0; i < inputImg->height; i++) { for(int j = 0; j < inputImg->width; j++) { int r = data[i * wp + 3 * j]; int g = data[i * wp + 3 * j + 1]; int b = data[i * wp + 3 * j + 2]; data1[i * wp1+j]=r; } } } void CPsView::OnOnRimg() { // TODO: Add your command handler code here CPsDoc * pDoc = GetDocument(); IplImage *RImg = cvCreateImage(cvSize(pDoc->m_img.Width(),pDoc->m_img.Height()),8,1); OnRimg(pDoc->m_img.GetImage(),RImg); cvSaveImage("E:\\新建文件夹\\R.jpg",RImg); pDoc->m_img.Load("E:\\新建文件夹\\R.jpg"); Invalidate(); } void CPsView::ImgZoom(IplImage *inputImg,IplImage *outputImg,double ratio)//图像放大缩小 函数 { uchar *data= (uchar *)inputImg->imageData; int wp = inputImg->widthStep;
uchar *data1= (uchar *)outputImg->imageData; int wp1 = outputImg->widthStep; for(int i = 0; i < outputImg->height; i++) { for(int j = 0; j < outputImg->width; j++) { int m=i/ratio; int n=j/ratio; data1[i * wp1 + 3 * j]=data[m * wp + 3 * n]; data1[i * wp1 + 3 * j + 1]=data[m * wp + 3 * n + 1]; data1[i * wp1 + 3 * j + 2]=data[m * wp + 3 * n + 2]; } } } void CPsView::OnImgzoomout() //图像放大 { // TODO: Add your command handler code here CPsDoc * pDoc = GetDocument(); /*IplImage *inputImg =pDoc->m_img.GetImage(); IplImage *outputImg = cvCreateImage(cvSize(inputImg->width*1.2,inputImg->height* 1.2),8,3); double ra = 1.0 * outputImg->width / pDoc->m_imgCopy.width(); ImgZoom(pDoc->m_imgCopy.GetImage(),outputImg,ra);*/ ASSERT_VALID(pDoc); int height= pDoc->m_img.Height(); int width = pDoc ->m_img.Width(); IplImage *outputImg = cvCreateImage(cvSize(width* 1.2,height *1.2), 8, 3); ImgZoom(pDoc->m_img.GetImage(), outputImg , 1.2); cvSaveImage("E:\\新建文件夹\\zoomb.jpg",outputImg); pDoc->m_img.Load("E:\\新建文件夹\\zoomb.jpg"); Invalidate(); } void CPsView::OnImgzoomin() //图像缩小 {
// TODO: Add your command handler code here CPsDoc * pDoc = GetDocument(); ASSERT_VALID(pDoc); int height= pDoc->m_img.Height(); int width = pDoc ->m_img.Width(); IplImage *outputImg = cvCreateImage(cvSize(width* 0.8,height *0.8), 8, 3); ImgZoom(pDoc->m_img.GetImage(), outputImg , 0.8); cvSaveImage("E:\\新建文件夹\\zoomM.jpg",outputImg); pDoc->m_img.Load("E:\\新建文件夹\\zoomM.jpg"); Invalidate(); }
分享到:
收藏