zoukankan      html  css  js  c++  java
  • OpenCV 通过 MFC 的 Picture Control 控件操作图像

    如果希望对显示在MFC Picture Control 控件里的图像进行操作,比如画线画点之类的,可以利用 OpenCV 结合 MFC 本身的鼠标响应函数来实现。

    如何将图像显示到 Picture Control 控件不谈,本文是采用的这篇博客所介绍的方法实现的。 点击打开链接 

    给对话框添加 WM_LBUTTONDOWN 鼠标左键点击消息,在消息响应函数中添加如下代码:

    void CMFCOpenCVShowDlg::OnLButtonDown(UINT nFlags, CPoint point)
    {
    	CRect myshowwinrect;
    	GetDlgItem(IDC_STATIC_SHOW)->GetWindowRect(myshowwinrect);//获得屏幕坐标
    	ScreenToClient(&myshowwinrect);//转到客户区相对坐标
    	if (point.x >= myshowwinrect.left && point.x <= myshowwinrect.right && point.y >= myshowwinrect.top && point.y <= myshowwinrect.bottom)//鼠标在Picture Control 控件上进行了单击操作
    	{
    		int img_x = (double)img->width*(double)(point.x - myshowwinrect.left) / (double)myshowwinrect.Width();//计算鼠标点击横坐标相对图片上的横位置
    		int img_y = (double)img->height*(double)(point.y - myshowwinrect.top) / (double)myshowwinrect.Height();
    		int changepoint = img_y*img->widthStep / sizeof(uchar)+img_x*img->nChannels;
    
    		//将图片的相应点标记为白色
    		img->imageData[changepoint+0] = 255;
    		img->imageData[changepoint+1] = 255;
    		img->imageData[changepoint+2] = 255;
    		drawpic(img, IDC_STATIC_SHOW);
    	}
    	CDialogEx::OnLButtonDown(nFlags, point);
    }
    到此,鼠标在 Picture Control 控件上点击,则会在图像相应位置处画出一个白点。

  • 相关阅读:
    C++Josephus问题
    C++背包示例
    C++1000以内的质数
    as3+asp+access编码
    fb设置flashplayer
    三视图示例
    正确实现 IDisposable 接口
    .net垃圾回收和CLR 4.0对垃圾回收所做的改进之二
    .net垃圾回收和CLR 4.0对垃圾回收所做的改进之三
    CLR 全面透彻解析:大型对象堆揭秘
  • 原文地址:https://www.cnblogs.com/weixinhum/p/3916687.html
Copyright © 2011-2022 走看看