基于OPENCV的视频播放器设计.doc_第1页
基于OPENCV的视频播放器设计.doc_第2页
基于OPENCV的视频播放器设计.doc_第3页
基于OPENCV的视频播放器设计.doc_第4页
基于OPENCV的视频播放器设计.doc_第5页
已阅读5页,还剩68页未读 继续免费阅读

下载本文档

版权说明:本文档由用户提供并上传,收益归属内容提供方,若内容存在侵权,请进行举报或认领

文档简介

沈阳理工大学学士学位论文 I 摘 要 本文旨在通过VC 6 0 开发平台开发一个基于OpenCV 的视频播放器 OpenCV 是 计算机视觉库 基于OpenCV 的视频播放器可以更简单的实现AVI 视频的播放 首先 本文简单介绍了 VC 6 0 软件开发平台 OpenCV 计算机视觉库的特点和应 用领域 计算机视频技术的发展 以及各种视频格式的分类等 其次选择在微软的 Microsoft Visual Studio 6 0 开发平台上使用C 语言进行开发 编写出基于OpenCV 的 功能简单实用方便的视频播放器 主要包括以下几个方面 开发本软件所使用的开发平 台与技术 功能模块 功能设计 功能实现等 关键词 Microsoft Visual Studio 6 0 OpenCV C 视频播放器 AVI 格式 沈阳理工大学学士学位论文 II Abstract This paper aims to develop a VC 6 0 development platform based on the video player OpenCV OpenCV is based on computer vision the video player can OpenCV more simple realization video playback AVI Firstly the paper simply introduces vc 6 0 software development platform under OpenCV computer vision the characteristics and application fields of the library computer video technology development as well as various video format of classification Second choice at Microsoft Microsoft Visual Studio 6 0 development platform using c language development and write a simple and practical OpenCV based on the function of video player convenience Mainly includes the following aspects the development of the software development platform and technology of use Function module Functional design Functions etc Keywords Microsoft Visual Studio 6 0 OpenCV C Video Player AVI format 沈阳理工大学学士学位论文 III 目 录 1 绪论 1 1 1 概述 1 1 2 OPENCV 简介 2 1 2 1 OpenCV 2 1 2 2 OpenCV 的应用领域 3 1 2 3 计算机视觉 4 1 3 论文主要研究内容及研究意义 6 1 4 论文组织结构 6 2 视频技术概述 7 2 1 多媒体技术 7 2 2 视频格式及视频流播放回放 13 2 2 1 视频格式分类 13 2 2 2视频流播放与回放 17 3 OPENCV 库使用 18 3 1 在 VC 下安装 OPENCV 18 4 VC 开发环境 22 4 1 VC 的组件工具 22 4 1 1编译器工具 23 4 1 2VC 库 23 4 1 3VC 开发环境 24 5 视频播放器的设计与实现 25 5 1 模块划分 25 5 1 1播放器功能模块图 25 5 2 详细设计 26 5 2 1 主界面的实现 26 5 2 2 文件控制的实现 28 5 2 3 播放控制的实现 30 5 2 4 进度控制的实现 34 沈阳理工大学学士学位论文 IV 5 2 5 系统声明 34 6 程序运行结果及分析 35 6 1 运行结果测试 35 6 2 结果分析 37 结 论 38 致 谢 39 参考文献 40 附录 A 英文原文 41 附录 B 汉语翻译 47 附录 C 程序源代码 52 沈阳理工大学学士学位论文 1 1 绪论 1 1 概述 C 语言是一种优秀的面向对象程序设计语言 它在 C 语言的基础上发展而来 但它比 C 语言更容易为人们学习和掌握 C 以其独特的语言机制在计算机科学的各 个领域中得到了广泛的应用 面向对象的设计思想是在原来结构化程序设计方法基础 上的一个质的飞跃 C 完美地体现了面向对象的各种特性 1 C 程序设计语言是由来自 AT Dialog Data AFX DATA CAboutDlg enum IDD IDD ABOUTBOX AFX DATA ClassWizard generated virtual function overrides AFX VIRTUAL CAboutDlg Protected virtual void DoDataExchange CDataExchange pDX DDX DDV support AFX VIRTUAL Implementation protected AFX MSG CAboutDlg AFX MSG DECLARE MESSAGE MAP CAboutDlg CAboutDlg CDialog CAboutDlg IDD AFX DATA INIT CAboutDlg AFX DATA INIT 沈阳理工大学学士学位论文 29 void CAboutDlg DoDataExchange CDataExchange pDX CDialog DoDataExchange pDX AFX DATA MAP CAboutDlg AFX DATA MAP BEGIN MESSAGE MAP CAboutDlg CDialog AFX MSG MAP CAboutDlg No message handlers AFX MSG MAP END MESSAGE MAP 5 2 2 文件控制的实现 打开文件的功能是许多应用程序的一个常见任务 MFC 命名空间包含了一组常用 对话框 支持这些类型的活动 在本程序中我们使用的是OpenFileDialog 类 OpenFileDialog 类表示常用的文件对话框 用于从磁盘上加载一个文件 是用于打开现 有文件的标准类 部分实现代码如下 void CIVSDlg OnOpen TODO Add your control notification handler code here 打开文件前 先关闭当前正在播放视频文件 if IsPlaying MessageBox 请先停止当前文件的播放 提示 0 GetDlgItem IDC STOP SetFocus return 沈阳理工大学学士学位论文 30 if IsAviFile 关闭先前已经打开了AVI 视频文件 myvideo CloseFile 打开视频文件 CString szFilters Data Files avi avi All Files CFileDialog fileDlg TRUE NULL avi OFN FILEMUSTEXIST OFN HIDEREADONLY szFilters this if fileDlg DoModal IDOK KillTimer 1 pwnd GetDlgItem IDC STATIC1 获取显示视频图像的控件ID pdc pwnd GetDC hdc pdc GetSafeHdc 获取句柄 GetDlgItem IDC STATIC1 GetClientRect rect 获取控件的RECT if myvideo OpenVideo fileDlg GetPathName hdc rect 构造视频播放对象 IsAviFile TRUE 当前用户选择了播放AVI 视频文件 framepos 0 第一帧播放 myvideo PlayVideo 0 预览第一帧图像 初始化对话框界面 GetDlgItem IDC PLAY EnableWindow TRUE GetDlgItem IDC STOP EnableWindow TRUE GetDlgItem IDC PAUSE EnableWindow TRUE m slider SetRange 0 myvideo m totalframes 设置滑动范围 m slider SetTicFreq 1 每 1 个单位画一刻度 m slider SetPos 0 沈阳理工大学学士学位论文 31 m totalframes myvideo m totalframes UpdateData FALSE Windows 窗体 Listbox 控件显示运行结果如图5 1 所示 图 5 1 主窗体 5 2 3 播放控制的实现 播放才是一个播放器最重要的功能 Windows 提供了丰富的多媒体服务功能 包 括大量从低级到高级的多媒体API 函数 利用这些功能强大的API 用户可以在不同层 次上编写多媒体应用程序 这里简要地介绍一些最常用的多媒体服务 MCI Media Control Interface 媒体控制接口是MircroSoft 提供的一组多媒体设备和文 件的标准接口 它的好处是可以方便地控制绝大多数多媒体设备包括音频 视频 影碟 录像等多媒体设备 而不需要知道它们的内部工作状况 应用程序通过向MCI 发送命令 来控制媒体设备 MCI 命令接口分命令字符串和命令消息两种 两者具有相同的功能 沈阳理工大学学士学位论文 32 命令字符串具有使用简单的特点 但是它的执行效率不如命令消息 mciSendString 字 符串消息 mciSendCommand 命令消息 所有的 MCI 命令字符串都是通过多媒体API 函数 mciSendString 传递给 MCI 的 该函数的声明为 MCIERROR mciSendString LPCTSTR lpszCommand MCI 命令字符串 LPTSTR lpszReturnString 存放反馈信息的缓冲区 UINT cchReturn 缓冲区的长度 HANDLE hwndCallback 回调窗口的句柄 一般为NULL 若成功则返回0 否则返回错误码 该函数返回的错误码可以用mciGetErrorString 函数进行分析 该函数的声明为 BOOL mciGetErrorString DWORD fdwError 函数 mciSendString 或 mciSendCommand 返回的错误码 LPTSTR lpszErrorText 接收描述错误的字符串的缓冲区 UINT cchErrorText 缓冲区的长度 本文播放 AVI 视频代码如下 void Video PlayVideo int frame pos 播放视频 即显示当前帧的图像到控件 if frame pos m totalframes return m framepos frame pos 播放帧开始位置 cvSetCaptureProperty m pcapture CV CAP PROP POS FRAMES m framepos m totalframes 设置播放帧位置 m pframe cvQueryFrame m pcapture 获取一帧 if m pframe 沈阳理工大学学士学位论文 33 m showimage CopyOf m pframe 1 m showimage DrawToHDC m hdc 显示到控件 class Video public CDialog public Video int OpenVideo CString FilePath HDC hdc CRect rect 打开 FilePath 视频文件 并设置好显示区域等参数 void CloseFile 关闭播放文件 void PlayVideo int frame pos 播放第 frame pos 帧视频 void PauseVideo 暂停播放 void StopVideo 停止播放 int GetPlaySpeed 得到视频文件的播放速度 virtual Video public CvvImage m showimage CvvImage 对象 用于显示帧到控件 IplImage m pframe 获取帧 CvCapture m pcapture 捕获 CString m filepath 文件路径 CRect m rect 播放区域 HDC m hdc 用于显示帧图像的句柄 bool m isplay 判断是否播放中 int m framepos 帧位置 int m totalframes 帧总数 int m fps 沈阳理工大学学士学位论文 34 UINT m timer 定时器 int m speed 播放速度 endif 播放开始与播放过程如图5 3 和图 5 4 所示 图 5 3 播放开始 图 5 4 播放过程中 沈阳理工大学学士学位论文 35 5 2 4 进度控制的实现 进度控制的实现其实在上节就略有提及 其实就是把进度条和当前播放长度同步结 合起来 并能使用鼠标随意拖放进度条进行选择性播放 而本程序中就是通过改变Value 的值实现进度条和当前播放时间的同步 当鼠标拖 动进度条时也就是跟踪条的Value 属性值发生变化 此时事件OnHScroll 发生 在实现 这个功能时还需用到MCIWndPlay属性 位置是浮点型的 注意这里以 帧为单位 代码如 下 void CIVSDlg OnHScroll UINT nSBCode UINT nPos CScrollBar pScrollBar CSliderCtrl pSlidCtrl CSliderCtrl GetDlgItem IDC SLIDER1 framepos pSlidCtrl GetPos 取得当前位置值 CDialog OnHScroll nSBCode nPos pScrollBar Void CIVSDlg OnAbout CAboutDlg dlg dlg DoModal 5 2 5 系统声明 这部分功能比较简单 也的非常容易实现的 只需调用个MFC 中 AboutBox 消息对 话框即可 AboutBox 显示一个通知用户的包含文本 按钮 符号的消息框 其参数 Caption 在消息框中显示文本信息 name 显示消息框的名称 在消息框中显示指定的 按钮如 确定 系统说明界面如下图5 5 所示 沈阳理工大学学士学位论文 36 图 5 5 系统声明界面 6 程序运行结果及分析 程序编写完成后对程序进行差错 没有错误后按 F5 运行程序 生成 IVS exe 快捷 方式 6 1 运行结果测试 1 首先运行 IVS exe 界面如下 图 6 1 初始界面 沈阳理工大学学士学位论文 37 2 选择打开按钮 弹出打开对话框 如图6 2 所示 图 6 2 打开界面 3 选择一个视频并打开 视频被添加到播放器中 如图 6 3 所示 沈阳理工大学学士学位论文 38 图 6 3 视频准备就绪界面 4 点击播放按钮即可播放当前视频 进度控制可以控制视频播放的进度 如图 6 4 所 示 图 6 4 视频播放界面 5 单击暂停按钮当前播放视频暂停 左侧图像状态显示为暂停 单击停止按钮播放停 止 当再次点击播放时 视频从头开始播放 6 点击退出按钮 关闭播放器 6 2 结果分析 通过上述调试 播放器实现了对 AVI 视频文件的播放 暂停 停止 进度拖动等要求 说明本课题设计成功 沈阳理工大学学士学位论文 39 结 论 本文详细介绍了基于OpenCV 视频播放器设计的过程 通过设计 调试 最终实现 了播放器设计 并实现了播放器对AVI 视频文件的播放 暂停 停止 进度拖动等要求 通过对软件的调试发现自己所学的知识还很浅薄 从接到设计任务书开始 收集相关 资料 深入了解课题 制定课题研究方案 到完成相应的功能设计历时16 周 表面看 时间很充裕 其实在这期间要完成相应的设计 时间还是很紧的 因为整个设计需要查 阅大量资料 了解OpenCV 计算机视觉库的功能 特点和应用 还要学习掌握 Microsoft Visual Studio 6 0 软件编程环境 并且还要用该平台设计基于OpenCV 的视频播 放器 一时间真是无从下手 幸好在导师的细心指导下 在同学的无私帮助下 在自己 的不懈努力下 终于克服了开发前期的茫然 攻克了前期软件调不通和程序运行错误的 难题 完成了本次课题设计 通过本次课题设计 我了解了软件开发的过程 熟悉了Microsoft Visual Studio 6 0 软件开发平台 学习了OpenCV 计算机视觉库的功能 特点和应用 掌握了把大学所 学的理论知识转化为实践的能力 同时也对软件开发产生了一定的兴趣 我相信这次的 毕业设计对我以后的工作生活有很大的帮助 在本软件的开发过程中 由于本人是初次开发软件 在知识 经验方面都存在着 很 多不足 请老师指点 致 谢 沈阳理工大学学士学位论文 40 另外还要感谢电子科学与技术教研组的所有老师正式在他们的帮助下我才能学到相 关的专业知识 才使我有条件去完成本次设计 此外 能顺利的完成我的论文也离不开陪伴我走完大学四年的同学 是他们给了我 家一般的感觉 让我的大学生活不孤独 安心去学习文化知识 最后 再次向上述的老师和同学们表示衷心的感谢 谢谢你们 沈阳理工大学学士学位论文 41 参考文献参考文献 1 Gary Bradski Adrian Kaehler 著 于仕琪 刘瑞祯译 学习 OPENCV 中文版 清华大 学出版社 2009 年 2 谭浩强 C 程序设计 第三版 2005 年 7 月第 3 版 清华大学出版社 2005 年 3 三扬科技 Visual C 开发入行真功夫 2009 年 4 月第 1 版 电子工业出版社 2009 年 4 孙鑫 余安萍 VC 深入详解 2006 年 6 月第 1 版 电子工业出版社 2006 年 5 赵仕 视频技术介绍 2007 年 4 月第 2 版 西安电子科技大学出版社 2007 年 6 林福宗 多媒体技术基础 第 2 版 清华大学出版社 2002 年 7 钟玉琢 多媒体计算机技术基础及应用 清华大学出版社 2006 年 8 胡晓峰 吴玲达 老松杨 司光亚 多媒体技术教程 第 3 版 人民邮电出版社 2009 年 9 李泽年 多媒体技术教程 机械工业出版社 2007 年 10 Waite S Prata 著 范植华 樊莹译 新编 C 语言大全 清华大学出版社 1994 年 11 Davis Chapman 著 骆长乐译 学用 Visual C 6 0 清华大学出版社 1999 年 12 David J Kruglinski ProgrammingVisualC FifthEdition Micrsoft Press 2001 13 Gary Bradski Adrian Kaehler Learning OpenCV Computer Vision with the OpenCV Library Southeast university press 2009 14 Walter Savitch Absolute C 2nd Edition Addison Wesley 2006 沈阳理工大学学士学位论文 42 附录 A 英文原文 Avi and multimedia is introduced AVI Audio Video Interleaved is put forward under the Window in Microsoft video using standard In a series of bitmap to store information and video files to join in the form of digital video information stored in digital information is composed by a group of files AVI files with short large amount of files And avoid many traditional animation playback problems Multimedia control interface definition of Microsoft Windows are MCI multimedia interface standards Provide high level independent of equipment control of various multimedia equipment orders Main equipments such as multimedia cd roms VCD CD player audio and video digital waveform can command control MCI Using multimedia control interface MCI for multimedia programming has the following advantages First the various media device interface encapsulation details of the specific control programmers through multimedia control interface operation control multimedia equipment shorten the development of multimedia applications the efficiency and reduce the cost Secondly MCI is a high level access multimedia equipment independent of equipment the original function for hardware control parameters such as changes improve the procedures of portability and reliability Furthermore the function is strong programmers in MCI level of programming make multimedia application development easier Vc platform and language C language is structured and modular language it is facing the process In dealing with a smaller program the programmer is handy with C language But when the problem is more complex the program of big structured programming method will show it C program designers must careful design program in every detail the accurate considering program operation is every moment of things such as how to change their variables is when should be 沈阳理工大学学士学位论文 43 conducted on screen which input should be what output The programmer is relatively high If the face is a complex problem Programmers often feel inadequate Initially proposed structured programming method of software design purpose is to solve this crisis but not completely realized In order to solve the crisis of software design put forward in the 1980s object oriented program design in this case the c arises at the historic moment C is Bjarne Stroustrup by bell LABS and colleagues in C language developed on the base of success C retained the original all advantages increases the object oriented mechanism C is fully compatible with C write the code can not add modification for C In C name can see it on the expansion of the C language is C superset It can be used for structural design program and can be used in object oriented programming so it is a powerful mixture of programming language Visual c 6 0 is run on Windows platforms of interactive Visual integrated development environment On one hand Visual c hereinafter referred to as the VC and perfect combination of Windows platforms and use it to develop powerful function of the program On the other hand it with Windows update to the advantage of strong programmers are attractive Visual Studio integrated development environment IDE provides a set of tools it integrates create compilation links and application of the functional test Windows This group provides development environment for development tools completely is more convenient and debugging vc include vc compiler tools vc libraries and vc environment Vc compiler tool by source code in a target compile process procedure Due to the existing procedures for identifying code not caused by error or program structure erroneous The compiler support traditional machine code developers and facing the virtual machine platform such as the CLR the common language runtime developers Vc include x64 Itanium and facing the compiler The compiler still support directly facing in the computer and non x86 platforms to optimize the performance of two Vc library include industry standard template library ATL activities Microsoft basic class MFC library and all kinds of standard library such as standard C library these standards by the iostream library standard template library STL and C runtime library CRT CRT including known to cause problems of safety enhancement of the function of alternative STL CLR managed code library for developers STL is introduced Has the new function of 沈阳理工大学学士学位论文 44 sealing to send data c library its design is intended for the simplified procedures the CLR library reduced workload of programmers Vc environment for project management and configuration including better support large scale projects the source code editor browse and debugging tools provide strong support The environment also support in writing code IntelliSense this function can be provided in the context of intelligent and specific Suggestions The editing area in vc to automatic identification of the c language keywords and Windows keyword helps programmers writing program to check for errors The debugging tools for the breakpoint debugging method and debugging and tracking commissioning stack Besides conventional GUI application vc also allows developers to generate Web applications based on the Windows of the intelligent client applications and applicable to the client and the client mobile equipment solutions C is the world s most popular language and the system of vc is a world class software tools generated WMF SDK profile Windows is the Microsoft corporation development of Media streaming Media technology digital Media has become a professional platform Windows Media clusters are a group of bottom SDKS application programming interface API its processing using the data structure of ASF Windows Media Media Windows SDK clusters of Media Player core Windows Media Windows Media Services have identified Encoder and Windows are used to provide the core files I O networking and digital rights management DRM support WMF SDK system structure WMF SDK used the object oriented design is a set of completely based on COM component model of senior setups It introduced the generator reading editor as well as the ASF formats shielding network data transmission control are at the bottom of streaming media technology implementation details the upper left is for developers use programming interfaces 沈阳理工大学学士学位论文 45 Windows SDK with many Media clusters with ASF files of functions but its core function is written documents This paper mainly introduces the basic task system structure Generator structure Using the Windows Media clusters of constructing the SDK application will transfer to the source Media sample generator Generator used in configuration files specified Settings on files Configuration file object code file format has been defined including each flow of detailed information and how should flow of information Most of the audio and video coding by a Media Windows codecs But first coding manager with a switch to handle data preparing for the compression When the sample can add file transfer to multiplexing multiplexing device according to the time of presentation from all of the data and the usual frame rate sample pack Multiplexing for the creation of a flow is transferred to a receiver receiver for final destination with I O whether it is a disk file or the Internet or other network broadcasting Read the structure Reading process and data writing process but basically is the opposite of the order Reading is connected to the source the source documents may be network connection or custom Open the file data can be divided into a single data flow and then the sample solution samples if the DRM protected and through the corresponding Windows Media coding processing decoder By default the internal reading will be appropriate for ASF flow data decoder uncompress WMF SDK programming environment configuration WMF SDK only suitable for C C programming language develop platform can be vc 6 0 or Visual was introduced in this paper the method of VC6 0 set Open VC 6 0 select menu commands and portugues e click on Directories reports in Directories for the drop down menu then choose Include files you SDKS installation path in VC standards before the path 沈阳理工大学学士学位论文 46 In the development of Project application Debug version also need VC6 0 following Settings select menu commands the Project Settings enter tags in Category link drop down list before the choose and winmm wmvcore J lib and added lib file Object library modules and select its default all subscription based Introduction the history of DivX ISO released low bit rate activity image and speech compression standard sorting MPEG 4 1998 October 1998 edition approved in April 1994 and announced the second edition and calibration model VM mpeg 4 official Numbers is ISO IEC international standard 14496 it is a new type of multimedia standard it is an important and standard is a difference on the object code compression standard defined code rate control target is obtained under the code rate in a given quality it is optimal for Internet video transmission quality of multimedia technology platform provides a very good In 1998 was the first in the Microsoft PC using mpeg 4 encoder it includes MS MPEG4V1 MS MPEG4V2 MS MPEG4V3 series including coding code V1 and V2 used to make AVI files until now it is the default components as Windows but V1 and V2 coding quality is not very good until MS MPEG4V3 began to have better graphics a significant progress but somehow Microsoft for what purpose but the video coding the MS MPEGV3 kernel its application in the Windows just Media streaming Media technology also is our familiar ASF streaming Media files ASF files although there are some advantage but because of excessive can be widely applied to edit it ha

温馨提示

  • 1. 本站所有资源如无特殊说明,都需要本地电脑安装OFFICE2007和PDF阅读器。图纸软件为CAD,CAXA,PROE,UG,SolidWorks等.压缩文件请下载最新的WinRAR软件解压。
  • 2. 本站的文档不包含任何第三方提供的附件图纸等,如果需要附件,请联系上传者。文件的所有权益归上传用户所有。
  • 3. 本站RAR压缩包中若带图纸,网页内容里面会有图纸预览,若没有图纸预览就没有图纸。
  • 4. 未经权益所有人同意不得将文件中的内容挪作商业或盈利用途。
  • 5. 人人文库网仅提供信息存储空间,仅对用户上传内容的表现方式做保护处理,对用户上传分享的文档内容本身不做任何修改或编辑,并不能对任何下载内容负责。
  • 6. 下载文件中如有侵权或不适当内容,请与我们联系,我们立即纠正。
  • 7. 本站不保证下载资源的准确性、安全性和完整性, 同时也不承担用户因使用这些下载资源对自己和他人造成任何形式的伤害或损失。

评论

0/150

提交评论