锐英源软件
第一信赖

精通

英语

开源

擅长

开发

培训

胸怀四海 

第一信赖

当前位置:锐英源 / OCR开源 / 以MFC文档视图形式使用opencv
服务方向
人工智能数据处理
人工智能培训
kaldi数据准备
小语种语音识别
语音识别标注
语音识别系统
语音识别转文字
kaldi开发技术服务
软件开发
运动控制卡上位机
机械加工软件
软件开发培训
Java 安卓移动开发
VC++
C#软件
汇编和破解
驱动开发
技术分类
讨论组翻译
调用Office打印预览
联系方式
固话:0371-63888850
手机:138-0381-0136
Q Q:396806883
微信:ryysoft

锐英源精品开源心得,转载请注明:“锐英源www.wisestudy.cn,孙老师作品,电话13803810136。需要全文内容也请联系孙老师。

以MFC文档视图形式使用opencv


Introduction

Several times, I have read questions regarding how to use OpenCV in MFC projects, so I decided to made a simple application demo, a VS2010 project, that reveals a way to use computer vision library inside of VC/MFC project, developed in an MDI application. Through my findings, as far as I remember, I saw somewhere a CDialog based app that embeds OpenCV ... here is another approach: multi-document interface, where you can load multiple media files.几次,我都阅读了有关如何在MFC项目中使用OpenCV的问题,因此我决定制作一个简单的VS2010项目应用程序演示,该示例演示了一种在在VC / MFC项目内部以MDI形式使用计算机视觉库的方法。应用。根据我的发现,据我所知,我在某处看到了一个CDialog嵌入OpenCV 的基础应用程序……这是另一种方法:多文档界面,您可以在其中加载多个媒体文件。

Background

This article does not treat the OpenCV compilation, it does contain the compiled OpenCV library, ready to go, inside of two folders: include, and res86, all of them are included inside the project. On the internet, you can easily find the way in which to compile OpenCV, this is not the purpose of this article.本文不介绍OpenCV编译,它确实包含准备就绪的已编译OpenCV库,位于两个文件夹内:includeres86,所有这些文件夹均包含在项目内。在Internet上,您可以轻松地找到编译OpenCV的方法,这不是本文的目的。

Step to Setup the Project项目设置步骤

1. Put "input" and "x86" folders inside your project:在项目中放入“ input ”和“ x86 ”文件夹:

Image 2

2. Setup project settings as follows:

Additional include directories: C:\Flaviu\Tempo\include;%(AdditionalIncludeDirectories) (replace "C:\Flaviu\" with your path).设置项目设置,如下所示:

其他包含目录:C:\ Flaviu \ Tempo \ include;%(AdditionalIncludeDirectories)(用你的路径替换“ C:\ Flaviu \”)。

Image 3

Additional library directories: C:\Flaviu\Tempo\x86\vc10\lib;%(AdditionalLibraryDirectories) (replace "C:\Flaviu\" with your path).其他库目录:C:\ Flaviu \ Tempo \ x86 \ vc10 \ lib;%(AdditionalLibraryDirectories)(用你的路径替换“ C:\ Flaviu \”)。

Image 4

Additional dependencies:其他依赖项:

opencv_calib3d341d.lib
opencv_core341d.lib
opencv_features2d341d.lib
opencv_flann341d.lib
opencv_highgui341d.lib
opencv_imgcodecs341d.lib
opencv_imgproc341d.lib
opencv_ml341d.lib
opencv_objdetect341d.lib
opencv_photo341d.lib
opencv_shape341d.lib
opencv_stitching341d.lib
opencv_superres341d.lib
opencv_video341d.lib
opencv_videoio341d.lib
opencv_videostab341d.lib

in Debug case, and the same libs for Release but without "d" from file names. Example: opencv_calib3d341.lib as opencv_calib3d341d.lib.在Debug情况下不变,Release相同,下去掉d。示例:opencv_calib3d341.lib对应opencv_calib3d341d.lib

Image 5

Using the Code

The structure of the project is pretty simple: the document class contains a cv::VideoCapture object, used to read video files, a cv::Mat object that is needed to convert cv::VideoCapture into cv::Mat object, and a BITMAPINFO structure used to convert cv::Mat object into bitmap object in order to be used for CViewrendering. This conversion could be found on CTempoDoc::SetupBitmapInfo method.该项目的结构非常简单:文档类包含一个cv::VideoCapture用于读取视频文件的cv::Mat对象,一个需要转换cv::VideoCapture为cv::Mat对象的对象以及一个BITMAPINFO用于将cv::Mat对象转换为bitmap对象以便进行CView渲染的结构。可以在CTempoDoc::SetupBitmapInfo方法上找到此转换。

void CTempoDoc::SetupBitmapInfo(cv::Mat& mat)
{
if(NULL != m_pBmi)
{
delete m_pBmi;
m_pBmi = NULL;
}
m_pBmi = new BITMAPINFO;
BITMAPINFOHEADER* pHeader = &m_pBmi->bmiHeader;
pHeader->biSize = sizeof(BITMAPINFOHEADER);
pHeader->biPlanes = 1;
pHeader->biCompression = BI_RGB;
pHeader->biXPelsPerMeter = 100;
pHeader->biYPelsPerMeter = 100;
pHeader->biClrUsed = 0;
pHeader->biClrImportant = 0;
pHeader->biWidth = m_Mat.cols;
pHeader->biHeight = -m_Mat.rows;
pHeader->biBitCount = 24;
m_pBmi->bmiHeader.biSizeImage = 0;
}

I should say that CTempoDoc has a tricky method: ResizeMat(cv::Mat& mat) ... this method corrects the cv::Mat that does not have the right format (actually, add a new column to matrix OpenCV object retrieved from cv:imread, when it is needed).

The rendering is handled inside CView class. Here, you can spot the well known OnDraw method, which renders the content of CTempoDoc::BITMAPINFO content, double-buffered. And a timer is implemented for the case when the loaded file is a video stream, and this timer will know when to load and render the next frame from video. Also, this class contains another handler that takes care of how the content is erased and drawn on CView, when the size of the window has been changed or when the next frame of video is ready to render, and some methods that scale the images inside window. All of them can be explored inside the sample project.

Here, you have an application that can load static images or all kinds of videos into an MDI app. Enjoy it!我应该说CTempoDoc有一个棘手的方法:ResizeMat(cv::Mat& mat)...该方法纠正cv::Mat格式不正确的方法(实际上,在需要时,向OpenCV矩阵对象中添加新列,该对象来自于cv:imread)。

渲染在CView类内部处理。在这里,您可以发现一种众所周知的OnDraw方法,该方法以CTempoDoc::BITMAPINFO双缓冲的方式呈现内容的内容。当加载的文件是视频流时,将实现一个计时器,该计时器将知道何时加载和渲染视频中的下一帧。此外,此类还包含另一个处理程序,该处理程序负责如何擦除和绘制内容CView,何时更改了窗口的大小或何时准备渲染下一帧视频,以及一些缩放窗口内图像的方法。 。所有这些都可以在示例项目中进行探索。

在这里,您有一个可以将静态图像或各种视频加载到MDI应用程序中的应用程序。好好享受!

友情链接
版权所有 Copyright(c)2004-2021 锐英源软件
公司注册号:410105000449586 豫ICP备08007559号 最佳分辨率 1024*768
地址:郑州大学北校区院(文化路97号院)内