OpenCV 基本图形处理集锦

来源:互联网 发布:centos 7 route add 编辑:程序博客网 时间:2024/06/01 10:11
//opencv显示文件中图片方法bool ShowImg(){UpdateData(true);CFileDialog fd(TRUE,_T("bmp"),_T(".bmp"),OFN_HIDEREADONLY|OFN_OVERWRITEPROMPT,"位图文件(*.bmp)|*.bmp||",this);CString path;if(fd.DoModal()==IDOK){path=fd.GetPathName();}else return false;IplImage * pImgEmbed = cvLoadImage((const char *)(LPCTSTR)path, CV_LOAD_IMAGE_UNCHANGED);CDC* pDC = GetDlgItem(IDC_STATIC1) ->GetDC(); // 获得显示控件的 DC   HDC hDC = pDC ->GetSafeHdc(); // 获取 HDC(设备句柄) 来进行绘图操作   CRect rect;GetDlgItem(IDC_STATIC1) ->GetClientRect( &rect );   int rw = rect.right - rect.left; // 求出图片控件的宽和高   int rh = rect.bottom - rect.top;   int iw = pImgEmbed->width; // 读取图片的宽和高   int ih = pImgEmbed->height;   int tx = (int)(rw - iw)/2; // 使图片的显示位置正好在控件的正中   int ty = (int)(rh - ih)/2;   SetRect( rect, tx, ty, tx+iw, ty+ih );   //if(TraceFlag==FALSE) DrawFrame(pImgEmbed,TraceLocation);   CvvImage cimg;cimg.CopyOf(pImgEmbed); // 复制图片   cimg.DrawToHDC( hDC, &rect ); // 将图片绘制到显示控件的指定区域内   cvWaitKey(50);   ReleaseDC( pDC );   GetDlgItem(IDC_STATIC1)->ShowWindow(SW_SHOW);UpdateData(FALSE);return true;}//opencv矩形,圆,直线和文字的画法void showShape(){IplImage *iplImage_tem = cvLoadImage("test.jpg"); cvRectangle(iplImage_tem, pre_pt, cur_pt, cvScalar(GetBValue(stImageEditing.color),GetGValue(stImageEditing.color),GetRValue(stImageEditing.color),0), stImageEditing.iLineSize, 8, 0 ); int radius = sqrt((float)((pre_pt.x - cur_pt.x)*(pre_pt.x - cur_pt.x)) + (float)((pre_pt.y - cur_pt.y)*(pre_pt.y - cur_pt.y)));cvCircle( iplImage_tem , pre_pt , radius , cvScalar(GetBValue(stImageEditing.color),GetGValue(stImageEditing.color),GetRValue(stImageEditing.color),0) , stImageEditing.iLineSize , CV_AA , 0 );cvLine(iplImage_tem , pre_pt , cur_pt , cvScalar(GetBValue(stImageEditing.color),GetGValue(stImageEditing.color),GetRValue(stImageEditing.color),0) , stImageEditing.iLineSize , 8 , 0);CvxText text("simhei.ttf");//初始化为黑体CHAR showThisText[100]={"测试文字内容"};CvScalar tem_scalar;tem_scalar.val[0] = stImageEditing.iFontSize+20;tem_scalar.val[1] = 0.5;tem_scalar.val[2] = 0.1;tem_scalar.val[3] = 0;text.restoreFont(tem_scalar);pre_pt.y -=10;text.putText(iplImage_tem, showThisText, pre_pt, CV_RGB(GetRValue(stImageEditing.color),GetGValue(stImageEditing.color),GetBValue(stImageEditing.color)));}

0 0
原创粉丝点击