登录

  • 登录
  • 忘记密码?点击找回

注册

  • 获取手机验证码 60
  • 注册

找回密码

  • 获取手机验证码60
  • 找回
毕业论文网 > 外文翻译 > 电子信息类 > 电子科学与技术 > 正文

基于机器视觉的目标跟踪系统设计外文翻译资料

 2022-11-11 03:11  

CHAPTER 2

Introduction to OpenCV

Getting Started

After installing the OpenCV library, our first task is, naturally, to get started and make something interesting happen. In order to do this, we will need to set up the program-ming environment.

In Visual Studio, it is necessary to create a project and to configure the setup so that(a) the libraries highgui.lib, cxcore.lib, ml.lib, and cv.lib are linked* and (b) the prepro-cessor will search the OpenCV hellip;/opencv/*/include directories for header files. These “include” directories will typically be named something like C:/program files/opencv/ cv/include, hellip;/opencv/cxcore/include, hellip;/opencv/ml/include, and hellip;/opencv/otherlibs/ highgui. Once yoursquo;ve done this, you can create a new C file and start your first program.

Certain key header files can make your life much easier. Many useful macros are in the header files hellip;/opencv/cxcore/include/cxtypes.h and cxmisc.h. These can do things like initialize structures and arrays in one line, sort lists, and so on. The most important headers for compiling are.../cv/include/cv.h and hellip;/cxcore/include/cxcore.h for computer vision, hellip;/otherlibs/highgui/highgui.h for I/O, and hellip;/ml/include/ml.h for ma-chine learning.

First Program—Display a Picture

OpenCV provides utilities for reading from a wide array of image file types as well as from video and cameras. These utilities are part of a toolkit called HighGUI, which is included in the OpenCV package. We will use some of these utilities to create a simple program that opens an image and displays it on the screen. See Example 2-1.

* For debug builds, you should link to the libraries highguid.lib, cxcored.lib, mld.lib, and cvd.lib.

  • C:/program files/ is the default installation of the OpenCV directory on Windows, although you can choose to install it elsewhere. To avoid confusion, from here on wersquo;ll use “hellip;/opencv/” to mean the path to the opencv directory on your system.

16

Example 2-1. A simple OpenCV program that loads an image from disk and displays it on the screen

#include “highgui.h”

int main( int argc, char** argv ) { IplImage* img = cvLoadImage( argv[1] );

cvNamedWindow( “Example1”, CV_WINDOW_AUTOSIZE ); cvShowImage( “Example1”, img );

cvWaitKey(0); cvReleaseImage( amp;img );

cvDestroyWindow( “Example1” );

}

When compiled and run from the command line with a single argument, this program loads an image into memory and displays it on the screen. It then waits until the user presses a key, at which time it closes the window and exits. Letrsquo;s go through the program line by line and take a moment to understand what each command is doing.

IplImage* img = cvLoadImage( argv[1] );

This line loads the image.* The function cvLoadImage() is a high-level routine that deter-mines the file format to be loaded based on the file name; it also automatically allocates the memory needed for the image data structure. Note that cvLoadImage() can read a wide variety of image formats, including BMP, DIB, JPEG, JPE, PNG, PBM, PGM, PPM, SR, RAS, and TIFF. A pointer to an allocated image data structure is then returned. This structure, called IplImage, is the OpenCV construct with which you will deal the most. OpenCV uses this structure to handle all kinds of images: single-channel, multichannel, integer-valued, floating-point-valued, et cetera. We use the pointer that cvLoadImage() returns to manipulate the image and the image data.

cvNamedWindow( “Example1”, CV_WINDOW_AUTOSIZE );

Another high-level function, cvNamedWindow(), opens a window on the screen that can contain and display an image. This function, provided by the HighGUI library, also as-signs a name to the window (in this case, “Example1”). Future HighGUI calls that inter-act with this window will refer to it by this name.

The second argument to cvNamedWindow() defines window properties. It may be set ei-ther to 0 (the default value) or to CV_WINDOW_AUTOSIZE. In the former case, the size of the window will be the same regardless of the image size, and the image will be scaled to fit within the window. In the latter case, the window will expand or contract automati-cally when an image is loaded so as to accommodate the imagersquo;s true size.

cvShowImage( “Example1”, img );

Whenever we have an image in the form of an IplImage* pointer, we can display it in an existing window with cvShowImage(). The cvShowImage() function requires that a named window already exist (created by cvNamedWindow()). On the call to cvShowImage(), the

  • A proper program would check for the existence of argv[1] and, in its absence, deliver an instructional error message for the user. We will abbreviate such necessities in this book and assume that the reader is cultured enough to understand the importance of error-handling code.

First Program—Display a Picture | 17

window will be redrawn with the appropriate image in it, and the window will resize itself as appropriate if it was created using the CV_WINDOW_AUTOSIZE flag.

cvWaitKey(0);

The cvWaitKey() function asks the program to stop and wait for a keystroke. If a positive argument is given, the program will wait for that number of milliseconds and then con-tinue even if nothing is pressed. If the argument is set to 0 or to a negative number, t

剩余内容已隐藏,支付完成后下载完整资料


(英文文献翻译)

论文题目:Learning OpenCV

指导老师:韩屏

学院班级:电子1303班

学生姓名:闫力

学 号 : 0121309341826

Learning OpenCV

CHAPTER 2

Introduction to OpenCV

Getting Started

After installing the OpenCV library, our first task is, naturally, to get started and make something interesting happen. In order to do this, we will need to set up the program-ming environment.

In Visual Studio, it is necessary to create a project and to configure the setup so that(a) the libraries highgui.lib, cxcore.lib, ml.lib, and cv.lib are linked* and (b) the prepro-cessor will search the OpenCV hellip;/opencv/*/include directories for header files. These “include” directories will typically be named something like C:/program files/opencv/ cv/include, hellip;/opencv/cxcore/include, hellip;/opencv/ml/include, and hellip;/opencv/otherlibs/ highgui. Once yoursquo;ve done this, you can create a new C file and start your first program.

Certain key header files can make your life much easier. Many useful macros are in the header files hellip;/opencv/cxcore/include/cxtypes.h and cxmisc.h. These can do things like initialize structures and arrays in one line, sort lists, and so on. The most important headers for compiling are.../cv/include/cv.h and hellip;/cxcore/include/cxcore.h for computer vision, hellip;/otherlibs/highgui/highgui.h for I/O, and hellip;/ml/include/ml.h for ma-chine learning.

First Program—Display a Picture

OpenCV provides utilities for reading from a wide array of image file types as well as from video and cameras. These utilities are part of a toolkit called HighGUI, which is included in the OpenCV package. We will use some of these utilities to create a simple program that opens an image and displays it on the screen. See Example 2-1.

* For debug builds, you should link to the libraries highguid.lib, cxcored.lib, mld.lib, and cvd.lib.

  • C:/program files/ is the default installation of the OpenCV directory on Windows, although you can choose to install it elsewhere. To avoid confusion, from here on wersquo;ll use “hellip;/opencv/” to mean the path to the opencv directory on your system.

16

Example 2-1. A simple OpenCV program that loads an image from disk and displays it on the screen

#include “highgui.h”

int main( int argc, char** argv ) { IplImage* img = cvLoadImage( argv[1] );

cvNamedWindow( “Example1”, CV_WINDOW_AUTOSIZE ); cvShowImage( “Example1”, img );

cvWaitKey(0); cvReleaseImage( amp;img );

cvDestroyWindow( “Example1” );

}

When compiled and run from the command line with a single argument, this program loads an image into memory and displays it on the screen. It then waits until the user presses a key, at which time it closes the window and exits. Letrsquo;s go through the program line by line and take a moment to understand what each command is doing.

IplImage* img = cvLoadImage( argv[1] );

This line loads the image.* The function cvLoadImage() is a high-level routine that deter-mines the file format to be loaded based on the file name; it also automatically allocates the memory needed for the image data structure. Note that cvLoadImage() can read a wide variety of image formats, including BMP, DIB, JPEG, JPE, PNG, PBM, PGM, PPM, SR, RAS, and TIFF. A pointer to an allocated image data structure is then returned. This structure, called IplImage, is the OpenCV construct with which you will deal the most. OpenCV uses this structure to handle all kinds of images: single-channel, multichannel, integer-valued, floating-point-valued, et cetera. We use the pointer that cvLoadImage() returns to manipulate the image and the image data.

cvNamedWindow( “Example1”, CV_WINDOW_AUTOSIZE );

Another high-level function, cvNamedWindow(), opens a window on the screen that can contain and display an image. This function, provided by the HighGUI library, also as-signs a name to the window (in this case, “Example1”). Future HighGUI calls that inter-act with this window will refer to it by this name.

The second argument to cvNamedWindow() defines window properties. It may be set ei-ther to 0 (the default value) or to CV_WINDOW_AUTOSIZE. In the former case, the size of the window will be the same regardless of the image size, and the image will be scaled to fit within the window. In the latter case, the window will expand or contract automati-cally when an image is loaded so as to accommodate the imagersquo;s true size.

cvShowImage( “Example1”, img );

Whenever we have an image in the form of an IplImage* pointer, we can display it in an existing window with cvShowImage(). The cvShowImage() function requires that a named window already exist (created by cvNamedWindow()). On the call to cvShowImage(), the

  • A proper program would check for the existence of argv[1] and, in its absence, deliver an instructional error message for the user. We will abbreviate such necessities in this book and assume that the reader is cultured enough to understand the importance of error-handling code.

First Program—Display a Picture | 17

window will be redrawn with the appropriate image in it, and the window will resize itself as appropriate if it was created using the CV_WINDOW_AUTOSIZE flag.

cvWaitKey(0);

The cvWaitKey() function asks the program to stop and wait for a keystroke. If a positive argument is given, the program will wait for that number of milliseconds and then con-tinue even if nothing is pressed. If the argument is set

剩余内容已隐藏,支付完成后下载完整资料


资料编号:[137760],资料为PDF文档或Word文档,PDF文档可免费转换为Word

您需要先支付 30元 才能查看全部内容!立即支付

企业微信

Copyright © 2010-2022 毕业论文网 站点地图