Opencv 文档
opencv基本使用方法

OpenCV基本使用方法一、介绍O p en CV是一个开源的计算机视觉库,提供了丰富的图像处理和计算机视觉算法,可以用于图像处理、目标检测、人脸识别等各种应用。
本文档将介绍O pe nC V的基本使用方法,包括图像读取、显示、保存以及常用的图像处理操作。
二、图像读取与显示1.读取图像要读取图像,可以使用`cv2.im re ad()`函数。
该函数接受图像文件的路径作为参数,并返回一个表示图像的多维数组。
i m po rt cv2i m ag e=cv2.im re ad("im ag e.jp g")2.显示图像要显示图像,可以使用`cv2.im sh ow()`函数。
该函数接受一个窗口名称和一个表示图像的多维数组作为参数。
i m po rt cv2i m ag e=cv2.im re ad("im ag e.jp g")c v2.im sh ow("Im age",i ma ge)c v2.wa it Ke y(0)c v2.de st ro yA ll Wind ow s()三、图像保存与格式转换1.保存图像要保存图像,可以使用`cv2.im wr it e()`函数。
该函数接受图像保存的路径和表示图像的多维数组作为参数。
i m po rt cv2i m ag e=cv2.im re ad("im ag e.jp g")c v2.im wr it e("n ew_i ma ge.j pg",im age)2.格式转换要将图像从一种格式转换为另一种格式,可以使用`c v2.c vt Co lo r()`函数。
该函数接受表示图像的多维数组和转换的标志作为参数。
i m po rt cv2i m ag e=cv2.im re ad("im ag e.jp g")g r ay_i ma ge=c v2.cv t Co lo r(im ag e,cv2.CO LO R_BG R2GR AY)四、常用的图像处理操作1.转换为灰度图要将彩色图像转换为灰度图,可以使用`c v2.cv tC ol or()`函数,并指定转换标志为`cv2.CO LO R_BG R2GR AY`。
opencv for c# 开发文档

OpenCV for Unity 1.2.3iOS & Android supportWin & Mac Standalone support(if Unity4,Pro only)Support for preview in the Editor(if Unity4,Pro only)Work with Unity Free & ProSystem RequirementsBuild Win Standalone & Preview Editor : Windows7 or laterBuild Mac Standalone & Preview Editor : OSX 10.8 or laterOpenCV for Unity is an Assets Plugin for using OpenCV from within Unity.●Since this package is a clone of OpenCV Java, you can use as it is all the APIReference OpenCV Java 2.4.11 (link). (“org.opencv.android” and “SURF and SIFT of org.opencv.features2d” are excluded)●You can image processing in real-time by using the WebCamTexture capabilities ofUnity. (real-time face detection works smoothly in iPhone 5)●Provides a method to interconversion of Unity's Texture2D and OpenCV's Mat.●Includes many classes from OpenCVForUnity, and implements IDisposable. Youcan manage the resources with the "using" statement.Please download Demo Application for Android and watch Setup Tutorial Video(Unity4 Unity5).API Reference OpenCV for UnitySampleCode using OpenCV for Unity is available.●MarkerBased AR Sample●FaceTracker Sample●Voforia with OpenCV for Unity Sample●Kinect with OpenCV for Unity SampleIf you want to try the Beta7 Version of “OpenCV for Untiy” based on “OpenCV3.0.0”, unzip the OpenCVForUntiy3.0.0-beta7.zip, please replace the “OpenC VForUnity” folder.“OpenCV for Untiy” based on“OpenCV3.0.0” support Unity5.not support Unity4.Version changes1.2.3 [Common] Add Beta7 Version of “OpenCV for Untiy” based on “OpenCV3.0.0”. [Common]Add WrapPerspectiveSample, HandPoseEstimationSample, MultiObjectTrackingBasedOnColorSample.1.2.2 [iOS]Move “OpenCVForUnity/ iOSforXcode/opencv2.framework” to “OpenCVForUnity/Plugins/iOS/”folder. [iOS]Fix WebCamTexture bug of SampleScene in Unity5.2.1.2.1 [Common] Add Beta5 Version of “OpenCV for Untiy” based on “OpenCV3.0.0”(Add Linux support). [Common]Rewrite SampleScene.1.2.0 [Common]Add Utils. getGraphicsDeviceType(). [Common]Add SampleScene Setup Tutorial Video for Unity5.1.1.9 [Common]Add CamShiftSample.(Object Tracking) [Common]Add OpenCVForUnityMenuItem.cs.( This script set plugin import settings automatically from MenuItem.)1.1.8 [iOS] Fix problem when working with Metaio(UnityAppController problem). [iOS]Change file name fr om “OpenCVForUnity/Plugins/iOS/MyAppController.mm” to “OpenCVForUnity/Plugins/iOS/OpenCVForUnityAppController.mm”.[Common]Add [System.Serializable] to basic class. [iOS]Move “OpenCVForUnity/ iOSforXcode/iOS_BuildPostprocessor.cs” to “OpenCVForUnity/Editor”folder. [Common] Add Beta2 Version of “OpenCV for Untiy” based on “OpenCV3.0.0”(support Unity5).1.1.7 [Common] Update to OpenCV2.4.11. [Common] Add Beta Version of “OpenCV for Untiy” based on “OpenCV3.0.0”(support Unity5).1.1.6 [Common]Fix FaceRecognizer.cs(Compile Error had happened only in the case of Unity4 Non Pro License).1.1.5 [Common]Add Beta Version of “OpenCV for Untiy” based on “OpenCV3.0.0-rc1”(support Unity5).[Android]Fix Utils.getFilePath(). [Common]Add WebCamTextureAsyncDetectFaceSample. [iOS]Change folder name from “OpenCVForUnity/iOS for Xcode/” to “OpenCVForUnity/iOSfor Xcode/”.Add iOS_BuildPostprocessor.cs.1.1.4 [Common]Add FaceRecognizer subclass. [Common]AddFaceRecognizerSampleScene. [Common]Fix SampleScene.1.1.3 [Common]Fix SampleScene. [Common] Change Property of Platform Dependent Compilation from UNITY_IPHONE to UNITY_IOS.1.1.2 [Common]Fix the direction of rotation of the mat that is converted from WebCamTexture.1.1.1 [Common]Add OpticalFlowSampleScene.[Common]Fix SampleScene. [Common] Fix function name of CvANN_MLP_TrainParams class.1.1.0 [Common]Divide asset for Unity4 and Unity5.1.0.9 [Common]Support for Unity5.1.0.8 [Common]Update to OpenCV2.4.101.0.7 [iOS]Support for arm64 build target.(Unity 4.6.1p3 or higher) [Common]Add Constructor VideoCapture(string filename). [Common]Add Method copyToMat(),copyFromMat().1.0.6 [Android]Support for x86 build target.(Unity 4.6 or higher)1.0.5 [Common] Bug fixes SampleScene.1.0.4[Common]Add Method matToTexture2D( Mat mat, Texture2D texture2D, Color32[] bufferColors = null).1.0.3 [Common]Support for preview in the Editor.(Pro only) [Common]Support for Win & Mac Standalone.(Pro only) [Android]Change of location of the file that you want to use for Utils.getFilePath().Changed to use“Aseets/StreamingAssets/” folder. [iOS] Add the file that you want to use for Utils.getFilePath() to Xcode project is no longer required.Changed to use“Aseets/StreamingAssets/” folder.1.0.2 [iOS]fix library(libjpeg,libpng) version coflicts.1.0.1 Initial versionIn Unity4 and Unity5 the different files to be imported.When you update the project that you made in Unity4 to Unity5, please import again this asset in Unity5.Quick setup procedure to run the sample scene(Setup Tutorial Video Unity4Unity5)1.If Unity4, Move “OpenCVForUnity/Plugins/”folder to“Assets/”folder.2.If Unity5,Select MenuItem[Tools/OpenCV for Unity/Set Plugin Import Settings].3.Move “OpenCVForUnity/StreamingAssets/”folder to “Assets/”folder.4.Please set [PlayerSettings]-[Resolution and Presentation]-[Orientation]-[DefaultOrientation : Landscape Left] when you build the sample scene.5.Add all of the “***.unity” in the “OpenCVForUnity” folder to [Build Settings] –[Scene In Build].※Inspector Setting of “opencv2.framework” and “opencvforunity.bundle”might have been reset at the time of import. In that case, re-setup is required.Screenshot after the setupUnity4Unity5Android Setup ProcedureUnity4●Copy from “OpenCV ForUnity/Plugins/Android/” to “Assets/Plugin s/Android/”folder.( libnative_camera_r*.*.*.so is only required when using the VideoCapture.)Unity5●“OpenCVForUnity/Plugins/Android/opencvforunity.jar”–Select platformAndroid in Inspector.●“OpenCVForUnity/Plugins/libs/armeabi-v7a/*.so” –Select platform Androidand CPU ARMv7 in Inspector. ( libnative_camera_r*.*.*.so is only required when using the VideoCapture.)●“OpenCVForUnity/Plugins/libs/x86/*.so” – Select platform Android and CPUx86 in Inspector.( libnative_camera_r*.*.*.so is only required when using the VideoCapture.)Put the file that you want to use for Utils.getFilePath() in the “Aseets/StreamingAssets/”folder. (haarcascade_frontalface_alt.xml etc is forOpenCVForUnitySample.scene. Please copy only when necessary.)iOS Setup ProcedureUnity4●Copy from “OpenCVForUnity/Plugins/iOS/” to “Assets/Plugin s/iOS/” folder.●Link “OpenCVForUnity/Plugins/iOS/opencv2.framework” to Xcode project. (inXcode project. Build Phases > Link Binary with Libraries > Add opencv2.framework . recommend to use PostprocessBuildPlayer.)Unity5●“Op enCVForUnity/Plugins/iOS/libopencvforunity.a” – Select platform iOS inInspector.●“OpenCVForUnity/Plugins/iOS/opencv2.framework” – Select platform iOS inInspector.●Put the file that you want to use for Utils.getFilePath() in the“Aseets/StreamingAssets/”folder. (haarcascade_frontalface_alt.xml etc is for OpenCVForUnitySample.scene. Please copy only when necessary.)Win Standalone Setup ProcedureUnity4●Copy from “OpenCVForUnity/Plugins/x86/” to “Assets/Plugins/x86/” folder.●Copy from “OpenCVForUnity/Plugins/x86_64/”to “Assets/Plugins/x86_64/”folder.Unity5●“OpenCVForUnity/Plugins/x86/opencvforunity.dll” –Select platformEditor,Standalone and CPU x86 and OS Windows in Inspector.●“OpenCVForUnity/Plugins/x86_64/opencvforunity.dll” –Select platformEditor,Standalone and CPU x86_64 and OS Windows in Inspector.●Put the file that you want to use for Utils.getFilePath() in the“Aseets/StreamingAssets/”.(haarcascade_frontalface_alt.xml etc is for OpenCVForUnitySample.scene. Please copy only when necessary.)●If you use the “VideoCapture(string filename)”, require setup.1)Download "OpenCV for Windows Version2.4.11"(/downloads.html).2)Set Path to "opencv_ffmpeg2411.dll"if 32bit, "C:¥opencv¥build¥x86¥vc10¥bin¥".if 64bit, "C:¥opencv¥build¥x64¥vc10¥bin¥".Mac Standalone Setup ProcedureUnity4●Copy from “OpenCVForUnity/Plugins/opencvforunity.bundle” to“Assets/Plugins/” folder.Unity5●“OpenCVForUnity/Plugins/opencvforunity.bundle” –Select platformEditor,Standalone and CPU x86_64 and OS OSX in Inspector.●Put the file that you want to use for Utils.getFilePath() in the“Aseets/StreamingAssets/”.(haarcascade_frontalface_alt.xml etc is for OpenCVForUnitySample.scene. Please copy only when necessary.)Q & AQ1.“DllNotFoundException: opencvforunity” is displayed on the console when run the sample scene.A1.Plugin does not seem to be loaded correctly. Please check the setup procedure.Q2.“ArgumentException: The output Mat object has to be of the same size” is displayed on the console when run the sample scene.A2.After having set up Plugin, Plugin may work well when you reboot Unity.Q3."Level 'Texture2DtoMatSample' (-1) could not be loaded because it has not been added to the build settings." is displayed on the console when run the sample scene.A3.Please Add all of the “***.unity” in the “OpenCVForUnity” folder to [Build Settings] – [Scene In Build].Q4.In DetectFaceSample or WebCamTextureDetectFaceSample, red rectangle is not displayed around face.A4.you might have failed to read the "haarcascade_frontalface_alt.xml".Please confirm whether there is ”OpenCVForUnity/StreamingAssets”folder at the right position.Q5.Support Web platform?A5.Since the Unity Web Player does not support the native plugin, "OpenCV for Unity" does not support "WebPlayer Platform".Q6.Support WindowsStoreApps8.1 & WindowsPhone8.1.A6.If you want to try the Beta Version of “OpenCV for Untiy” based on “OpenCV3.0.0”(Support WindowsStoreApps8.1 & WindowsPhone8.1), unzip the OpenCVForUntiy3.0.0-beta.zip, please replace the “OpenCVForUnity” folder.“OpenCV for Untiy” based on “OpenCV3.0.0” s upport Unity5.not support Unity4.IMPORTANT: READ BEFORE DOWNLOADING, COPYING, INSTALLING OR USING.By downloading, copying, installing or using the software you agree to this license.If you do not agree to this license, do not download, install,copy or use the software.License AgreementFor Open Source Computer Vision LibraryCopyright (C) 2000-2008, Intel Corporation, all rights reserved.Copyright (C) 2008-2011, Willow Garage Inc., all rights reserved.Third party copyrights are property of their respective owners.Redistribution and use in source and binary forms, with or without modification,are permitted provided that the following conditions are met:* Redistributions of source code must retain the above copyright notice,this list of conditions and the following disclaimer.* Redistributions in binary form must reproduce the above copyright notice,this list of conditions and the following disclaimer in the documentationand/or other materials provided with the distribution.* The name of the copyright holders may not be used to endorse or promote products derived from this software without specific prior written permission.This software is provided by the copyright holders and contributors "as is" andany express or implied warranties, including, but not limited to, the implied warranties of merchantability and fitness for a particular purpose are disclaimed.In no event shall the Intel Corporation or contributors be liable for any direct, indirect, incidental, special, exemplary, or consequential damages(including, but not limited to, procurement of substitute goods or services;loss of use, data, or profits; or business interruption) however causedand on any theory of liability, whether in contract, strict liability,or tort (including negligence or otherwise) arising in any way out ofthe use of this software, even if advised of the possibility of such damage.。
opencv 使用手册

opencv 使用手册OpenCV(Open Source Computer Vision Library)是一个开源的计算机视觉库,提供了很多函数,这些函数非常高效地实现了计算机视觉算法。
OpenCV 使用 C/C++ 开发,同时也提供了 Python、Java、MATLAB 等其他语言的接口。
OpenCV 是跨平台的,可以在 Windows、Linux、Mac OS、Android、iOS 等操作系统上运行。
OpenCV 的应用领域非常广泛,包括图像拼接、图像降噪、产品质检、人机交互、人脸识别、动作识别、动作跟踪、无人驾驶等。
OpenCV 还提供了机器学习模块,可以使用正态贝叶斯、K最近邻、支持向量机、决策树、随机森林、人工神经网络等机器学习算法。
要使用 OpenCV,首先需要安装 OpenCV 库。
可以使用 pip 命令安装opencv-python 和 opencv-contrib-python。
安装完成后,可以通过以下命令导入 OpenCV 模块:```pythonimport cv2 as cv```然后可以调用 OpenCV 提供的各种函数来处理图像和视频。
例如,可以使用 `()` 函数读取图像,使用 `()` 函数显示图像,使用 `()` 函数等待用户按键,使用 `()` 函数关闭所有窗口。
以下是一个简单的示例代码,用于读取一张图片并显示出来:```pythonimport cv2 as cv读取图片img = ("./data/")显示图片("image", img)等待用户按键,按下 q 键退出while True:if (1000) & 0xFF == ord("q"):break()```以上是 OpenCV 的基本使用手册,更多详细信息和函数文档可以在OpenCV 官方网站上查看。
Opencv2.4.6自带文档中文笔记(core)

2.1(一)Mat矩阵中数据指针Mat.data是uchar类型指针,CV_8U系列可以通过计算指针位置快速地定位矩阵中的任意元素。
二维单通道元素可以用Mat::at(i, j)访问,i是行序号,j是列序号。
但对于多通道的非unsigned char类型矩阵来说,以上方法都不好(注:后来知道可以通过类型转换,用指针访问data数据,见后文)。
可以用Mat::ptr()来获得指向某行元素的指针,在通过行数与通道数计算相应点的指针。
参照OpenCV的Mat::at()函数,写了一个访问二维Mat矩阵的两个简单的小函数,没有边界检查。
#include <opencv2/core/core.hpp>template<typename ItemType>ItemType* getMatPointPtr(cv::Mat & src, int i , int j , int c = 0){ItemType* curRow = src.ptr<ItemType>(i);return curRow + j * src.channels() + c;}template<typename ItemType>ItemType getMatPoint(cv::Mat & src, int i , int j , int c = 0){ItemType* curRow = src.ptr<ItemType>(i);return *(curRow + j * src.channels() + c);}OpenCV中的Mat::at()代码有严格的边界检测,Mat::ptr()也有边界检测,但代码中没有检测j是否越界。
以上为推荐使用的情况,下边的不推荐使用。
可以通过转换指针类型,访问非uchar类型的Mat元素。
例如:图像是CV_64FC1格式,可以将Mat.data指针直接转换成double*类型:// imgMat is a image.double* pimg = (double*)(imgMat.data)也可以用C++中的显式转换符static_cast,不过要通过void*类型过渡:void* pvoid = static_cast<void*>(imgMat.data);double* pimg = static_cast<double*>(pvoid);这种方式在Debug模式下速度提升非常显著,但没有任何的边界检查和异常处理,使用时必须十分小心。
我的opencv2图像处理帮助文档(一)

《我的opencv2图像处理帮助文档》1、图像掩膜:用选定的图像、图形或物体,对待处理的图像(全部或局部)进行遮挡,来控制图像处理的区域或处理过程。
用于覆盖的特定图像或物体称为掩模或模板。
光学图像处理中,掩模可以足胶片、滤光片等。
数字图像处理中,掩模为二维矩阵数组,有时也用多值图像。
数字图像处理中的图像掩模主要用于:①提取感兴趣区,用预先制作的感兴趣区掩模与待处理图像相乘,得到感兴趣区图像,感兴趣区内图像值保持不变,而区外图像值都为0。
②屏蔽作用,用掩模对图像上某些区域作屏蔽,使其不参加处理或不参加处理参数的计算,或仅对屏蔽区作处理或统计。
③结构特征提取,用相似性变量或图像匹配方法检测和提取图像中与掩模相似的结构特征。
④特殊形状图像的制作。
2、类似Vec3b的数据类型:(1)vec是一个向量,就比如线性代数里面的a箭头(箭头写在a的上面)。
里面有4个元素<a1, a2, a3, a4>,其中的a1, a2, a3, a4是4个int类型的数值。
(2)vec是一个opencv的模板类;vec<int, n>就是用类型int和n将向量模板类vec 做一个实例化。
简单说,vec<int, n>就是一个向量类型,可以用来定义向量对象。
其中,第一个参数int表示vec中存储的数据是int类型;第二个参数n为整型值,表示每个vec对象中存储的是几个int值,即n维向量。
例如:vec<int, 2>表示是一个二维向量类,每个对象中存储两个int类型的值x,y。
(数学含义为:x+yi)而在opencv2中有一下定义:typedefVec<uchar, 3>Vec3b;3、怎么理解OpenCV2中的 p = srcImage.ptr<uchar>(i);例如程序:int i, j;uchar* p;for (i = 0; i <nRows; i++){p = srcImage.ptr<uchar>(i);for (j = 0; j <nCols; j++){p[j] = 255;}}解释:通过srcImage.ptr<uchar>(i)获取图像srcImage中第i行头指针,通过这个指针结合列的位置(就是代码中的j)可以轻松的操作图像i行j列。
opencv4函数手册

opencv4函数手册
OpenCV(Open Source Computer Vision Library)是一个开源的计算机视觉库,提供了丰富的图像处理和计算机视觉算法。
它支
持多种编程语言,包括C++、Python等,并且可以在多个操作系统
上运行。
关于OpenCV 4的函数手册,它包含了OpenCV库中各个函数的
详细说明和用法。
这些函数涵盖了图像处理、特征提取、物体识别、摄像机标定、图像变换等多个领域。
在OpenCV 4函数手册中,你可以找到以下内容:
1. 函数概述,对OpenCV库中的各个函数进行分类和概述,方
便用户快速了解函数的用途和功能。
2. 函数参数,详细说明每个函数的参数列表,包括输入参数、
输出参数和可选参数。
这些参数描述了函数的输入和输出数据类型、大小、格式等信息。
3. 函数返回值,说明函数的返回值类型和含义,帮助用户理解
函数的执行结果。
4. 函数示例,提供函数的使用示例代码,展示如何调用函数以及函数的具体用法。
示例代码通常包含了图像加载、处理、保存等步骤,帮助用户更好地理解函数的实际应用。
5. 相关函数,介绍与当前函数相关的其他函数,帮助用户了解函数之间的关联和依赖关系。
6. 注意事项,列出函数的一些注意事项和限制,帮助用户正确使用函数并避免常见错误。
通过OpenCV 4函数手册,你可以学习和了解OpenCV库中各个函数的功能和用法,从而在图像处理和计算机视觉任务中更加高效地使用OpenCV。
你可以通过OpenCV官方网站或者在线文档获取OpenCV 4函数手册的详细内容。
opencv 4计算机视觉应用程序编程手册

opencv 4计算机视觉应用程序编程手册OpenCV 4计算机视觉应用程序编程手册一、OpenCV 4简介与安装OpenCV(Open Source Computer Vision Library)是一款开源的计算机视觉库,广泛应用于图像处理、视频分析、特征提取、目标检测等领域。
OpenCV 4在性能和功能上均有显著提升,支持Python、C++等多种编程语言。
本手册将带领读者了解OpenCV 4的基本概念,并在各种平台上安装使用。
二、计算机视觉基础概念与原理计算机视觉是一门研究如何让计算机从图像或视频中获取有意义信息的科学。
其主要任务包括图像处理、特征提取、目标检测、目标跟踪等。
在本章节中,我们将学习计算机视觉的基本概念和原理,为后续的实际项目打下基础。
三、图像处理与分析图像处理是计算机视觉的核心任务之一,主要包括图像读取、显示、存储、滤波、边缘检测等操作。
在本章节中,我们将学习OpenCV 4中常用的图像处理函数,并了解其应用场景。
四、特征提取与匹配特征提取是计算机视觉中关键的一环,旨在从图像中提取具有代表性的特征点。
常见的特征提取算法有SIFT、SURF、ORB等。
特征匹配则是寻找两幅图像中对应的特征点,常用的方法有暴力匹配、FLANN等。
在本章节中,我们将学习这些算法的原理及使用方法。
五、目标检测与跟踪目标检测是在图像或视频中查找特定目标的过程,常用的算法有R-CNN、Fast R-CNN、Faster R-CNN、SSD、YOLO等。
目标跟踪则是跟踪目标在连续帧中的位置,常用的方法有TLD、KCF等。
在本章节中,我们将学习这些目标检测与跟踪算法的原理及实现。
六、3D建模与增强现实3D建模是将二维图像转换为三维模型的一种技术,常用的工具有Open3D、Maya等。
增强现实则是将虚拟物体叠加到真实场景中,常用的框架有ARCore、ARKit等。
在本章节中,我们将学习3D建模与增强现实的基本原理及应用。
OpenCV Java版教程说明书

About the T utorialOpenCV is a cross-platform library using which we can develop real-time computer vision applications. It mainly focuses on image processing, video capture and analysis including features like face detection and object detection. In this tutorial, we explain how you can use OpenCV in your applications.AudienceThis tutorial has been prepared for beginners to make them understand the basics of OpenCV library. We have used the Java programming language in all the examples, therefore you should have a basic exposure to Java in order to benefit from this tutorial. PrerequisitesFor this tutorial, it is assumed that the readers have a prior knowledge of Java programming language. In some of the programs of this tutorial, we have used JavaFX for GUI purpose. So, it is recommended that you go through our JavaFX tutorial before proceeding further - /javafx/.Copyright & Disclaimer© Copyright 2017 by Tutorials Point (I) Pvt. Ltd.All the content and graphics published in this e-book are the property of Tutorials Point (I) Pvt. Ltd. The user of this e-book is prohibited to reuse, retain, copy, distribute or republish any contents or a part of contents of this e-book in any manner without written consent of the publisher.We strive to update the contents of our website and tutorials as timely and as precisely as possible, however, the contents may contain inaccuracies or errors. Tutorials Point (I) Pvt. Ltd. provides no guarantee regarding the accuracy, timeliness or completeness of our website or its contents including this tutorial. If you discover any errors on our website or in this tutorial, please notify us at **************************T able of ContentsAbout the Tutorial (1)Audience (1)Prerequisites (1)Copyright & Disclaimer (1)Table of Contents (2)1.OpenCV – Overview (5)Computer Vision (5)Applications of Computer Vision (5)Features of OpenCV Library (6)OpenCV Library Modules (7)A Brief History of OpenCV (8)2.OpenCV – Environment (9)Installing OpenCV (9)Eclipse Installation (11)Setting the Path for Native Libraries (18)3.OpenCV — Storing Images (21)The Mat Class (21)Creating and Displaying the Matrix (23)Loading Image using JavaSE API (25)4.OpenCV – Reading Images (27)5.OpenCV ─ Writing an Image (29)6.OpenCV— GUI (31)Converting Mat to Buffered Image (31)Displaying Image using AWT/Swings (32)Displaying Image using JavaFX (34)TYPES OF IMAGES (38)7.OpenCV — The IMREAD_XXX Flag (39)8.OpenCV ─ Reading an Image as Grayscale (41)9.OpenCV ─ Reading Image as BGR (45)IMAGE CONVERSION (49)10.OpenCV ─ Colored Images to GrayScale (50)11.OpenCV ─ Colored Image to Binary (54)12.OpenCV ─ Grayscale to Binary (58)DRAWING FUNCTIONS (62)13.OpenCV – Drawing a Circle (63)14.OpenCV – Drawing a Line (67)15.OpenCV ─ Drawing a Rectangle (71)16.OpenCV – Drawing an Ellipse (75)17.OpenCV – Drawing Polylines (79)18.OpenCV – Drawing Convex Polylines (84)19.OpenCV—Drawing Arrowed Lines (88)20.OpenCV – Adding Text (92)BLUR OPERATIONS (96)21.OpenCV – Blur (Averaging) (97)22.OpenCV – Gaussian Blur (100)23.OpenCV – Median Blur (103)FILTERING (106)24.OpenCV – Bilateral Filter (107)25.OpenCV – Box Filter (110)26.OpenCV – SQRBox Filter (113)27.OpenCV – Filter2D (116)28.OpenCV—Dilation (119)29.OpenCV – Erosion (122)30.OpenCV ─ Morphological Operations (125)31.OpenCV ─ Image Pyramids (131)Pyramid Up (131)Pyramid Down (133)Mean Shift Filtering (136)THRESHOLDING (139)32.OpenCV – Simple Threshold (140)33.OpenCV – Adaptive Threshold (144)Other Types of Adaptive Thresholding (147)34.OpenCV ─ Adding Borders (148)SOBEL DERIVATIVES (153)35.OpenCV – Sobel Operator (154)36.OpenCV – Scharr Operator (157)More Scharr Derivatives (159)TRANSFORMATION OPERATIONS (160)37.OpenCV – Laplacian Transformation (161)38.OpenCV – Distance Transformation (164)CAMERA & FACE DETECTION (169)39.OpenCV – Using Camera (170)40.OpenCV ─ Face Detection in a Picture (175)41.OpenCV ─ Face Detection using Camera (179)GEOMETRIC TRANSFORMATIONS (184)42.OpenCV ─ Affine Translation (185)43.OpenCV – Rotation (188)44.OpenCV – Scaling (191)45.OpenCV – Color Maps (194)MISCELLANEOUS CONCEPTS (202)46.OpenCV – Canny Edge Detection (203)47.OpenCV – Hough Line Transform (206)48.OpenCV – Histogram Equalization (210)1.OpenCVOpenCV is a cross-platform library using which we can develop real-time computer vision applications. It mainly focuses on image processing, video capture and analysis including features like face detection and object detection.Let’s start the chapter by defining the term "Computer Vision".Computer VisionComputer Vision can be defined as a discipline that explains how to reconstruct, interrupt, and understand a 3D scene from its 2D images, in terms of the properties of the structure present in the scene. It deals with modeling and replicating human vision using computer software and hardware.Computer Vision overlaps significantly with the following fields:∙Image Processing: It focuses on image manipulation.∙Pattern Recognition: It explains various techniques to classify patterns.∙Photogrammetry:It is concerned with obtaining accurate measurements from images.Computer Vision Vs Image ProcessingImage processing deals with image-to-image transformation. The input and output of image processing are both images.Computer vision is the construction of explicit, meaningful descriptions of physical objects from their image. The output of computer vision is a description or an interpretation of structures in 3D scene.Applications of Computer VisionHere we have listed down some of major domains where Computer Vision is heavily used. Robotics Application∙Localization ─ Determine robot location automatically∙Navigation∙Obstacles avoidance∙Assembly (peg-in-hole, welding, painting)∙Manipulation (e.g. PUMA robot manipulator)∙Human Robot Interaction (HRI): Intelligent robotics to interact with and serve peopleMedicine Application∙Classification and detection (e.g. lesion or cells classification and tumor detection)∙2D/3D segmentation∙3D human organ reconstruction (MRI or ultrasound)∙Vision-guided robotics surgeryIndustrial Automation Application∙Industrial inspection (defect detection)∙Assembly∙Barcode and package label reading∙Object sorting∙Document understanding (e.g. OCR)Security Application∙Biometrics (iris, finger print, face recognition)∙Surveillance ─ Detecting certain suspicious activities or behaviorsTransportation Application∙Autonomous vehicle∙Safety, e.g., driver vigilance monitoringFeatures of OpenCV LibraryUsing OpenCV library, you can –∙Read and write images∙Capture and save videos∙Process images (filter, transform)∙Perform feature detection∙Detect specific objects such as faces, eyes, cars, in the videos or images.∙Analyze the video, i.e., estimate the motion in it, subtract the background, and track objects in it.OpenCV was originally developed in C++. In addition to it, Python and Java bindings were provided. OpenCV runs on various Operating Systems such as windows, Linux, OSx, FreeBSD, Net BSD, Open BSD, etc.This tutorial explains the concepts of OpenCV with examples using Java bindings.OpenCV Library ModulesFollowing are the main library modules of the OpenCV library.Core FunctionalityThis module covers the basic data structures such as Scalar, Point, Range, etc., that are used to build OpenCV applications. In addition to these, it also includes the multidimensional array Mat, which is used to store the images. In the Java library of OpenCV, this module is included as a package with the name org.opencv.core.Image ProcessingThis module covers various image processing operations such as image filtering, geometrical image transformations, color space conversion, histograms, etc. In the Java library of OpenCV, this module is included as a package with the name org.opencv.imgproc.VideoThis module covers the video analysis concepts such as motion estimation, background subtraction, and object tracking. In the Java library of OpenCV, this module is included as a package with the name org.opencv.video.Video I/OThis module explains the video capturing and video codecs using OpenCV library. In the Java library of OpenCV, this module is included as a package with the name org.opencv.videoio.calib3dThis module includes algorithms regarding basic multiple-view geometry algorithms, single and stereo camera calibration, object pose estimation, stereo correspondence and elements of 3D reconstruction. In the Java library of OpenCV, this module is included as a package with the name org.opencv.calib3d.features2dThis module includes the concepts of feature detection and description. In the Java library of OpenCV, this module is included as a package with the name org.opencv.features2d. ObjdetectThis module includes the detection of objects and instances of the predefined classes such as faces, eyes, mugs, people, cars, etc. In the Java library of OpenCV, this module is included as a package with the name org.opencv.objdetect.HighguiThis is an easy-to-use interface with simple UI capabilities. In the Java library of OpenCV, the features of this module is included in two different packages namely, org.opencv.imgcodecs and org.opencv.videoio.A Brief History of OpenCVOpenCV was initially an Intel research initiative to advise CPU-intensive applications. It was officially launched in 1999.∙In the year 2006, its first major version, OpenCV 1.0 was released.∙In October 2009, the second major version, OpenCV 2 was released.∙In August 2012, OpenCV was taken by a nonprofit organization .OpenCV In this chapter, you will learn how to install OpenCV and set up its environment in your system.First of all, you need to download OpenCV onto your system. Follow the steps given below. Step 1: Open the homepage of OpenCV by clicking the following link: / On clicking, you will see its homepage as shown below.2.Step 2: Now, click the Downloads link highlighted in the above screenshot. On clicking, you will be directed to the downloads page of OpenCV.Step 3: On clicking the highlighted link in the above screenshot, a file named opencv-3.1.0.exe will be downloaded. Extract this file to generate a folder opencv in your system, as shown in the following screenshot.Step 4:Open the folder OpenCV-> build ->java. Here you will find the jar file of OpenCV named opencv-310.jar. Save this file in a separate folder for further use.Eclipse InstallationAfter downloading the required JAR files, you have to embed these JAR files to your Eclipse environment. You can do this by setting the Build Path to these JAR files and by using pom.xml.Setting Build PathFollowing are the steps to set up OpenCV in Eclipse:Step 1: Ensure that you have installed Eclipse in your system. If not, download and install Eclipse in your system.Step 2: Open Eclipse, click on File, New, and Open a new project as shown in the following screenshot.Step 3: On selecting the project, you will get the New Project wizard. In this wizard, select Java project and proceed by clicking the Next button, as shown in the following screenshot.Step 4: On proceeding forward, you will be directed to the New Java Project wizard. Create a new project and click Next, as shown in the following screenshot.Step 5:After creating a new project, right-click on it. Select Build Path and click Configure Build Path… as shown in the following screenshot.Step 6: On clicking the Build Path option,you will be directed to the Java Build Path wizard.Click the Add External JARs button,as shown in the following screenshot.Step 7: Select the path where you have saved the file opencv-310.jar.Step 8: On clicking the Open button in the above screenshot, those files will be added to your library.Step 9: On clicking OK, you will successfully add the required JAR files to the current project and you can verify these added libraries by expanding the Referenced Libraries.Setting the Path for Native LibrariesIn addition to the JAR files, you need to set path for the native libraries (DLL files) of OpenCV.Location of DLL files: Open the installation folder of OpenCV and go to the sub-folder build -> java. Here you will find the two folders x64 (64 bit) and x86 (32 bit) which contain the dll files of OpenCV.Open the respective folder suitable for your operating system, then you can see the dll file, as shown in the following screenshot.Now, set the path for this file too by following the steps given below—Step 1: Once again, open the JavaBuildPath window. Here you can observe the added JAR file and the JRE System Library.Step 2: On expanding it, you will get the system libraries and Native library location, as highlighted in the following screenshot.OpenCV Step 3:Double-click on the Native library location. Here, you can see the Native Library Folder Configuration window as shown below—Here, click the button External Folder…and select the location of the dll file in your system.3.OpenCVTo capture an image, we use devices like cameras and scanners. These devices record numerical values of the image (Ex: pixel values). OpenCV is a library which processes the digital images, therefore we need to store these images for processing.The Mat class of OpenCV library is used to store the values of an image. It represents an n-dimensional array and is used to store image data of grayscale or color images, voxel volumes, vector fields, point clouds, tensors, histograms, etc.This class comprises of two data parts: the header and a pointer∙Header: Contains information like size, method used for storing, and the address of the matrix (constant in size).∙Pointer: Stores the pixel values of the image (Keeps on varying).The Mat ClassThe OpenCV Java library provides this class with the same name (Mat) within the package org.opencv.core.ConstructorsThe Mat class of OpenCV Java library has various constructors, using which you can construct the Mat object.Note:∙Array type. Use CV_8UC1, ..., CV_64FC4 to create 1-4 channel matrices, or CV_8UC(n), ..., CV_64FC(n) to create multi-channel (up to CV_CN_MAX channels) matrices.∙The type of the matrices were represented by various fields of the class CvType which belongs to the package org.opencv.core.Methods and DescriptionFollowing are some of the methods provided by the Mat class.In this section, we are going to discuss our first OpenCV example. We will see how to create and display a simple OpenCV matrix.Given below are the steps to be followed to create and display a matrix in OpenCV.Step 1: Load the OpenCV native libraryWhile writing Java code using OpenCV library, the first step you need to do is to load the native library of OpenCV using the loadLibrary(). Load the OpenCV native library as shown below.Step 2: Instantiate the Mat classInstantiate the Mat class using any of the functions mentioned in this chapter earlier.Step 3: Fill the matrix using the methodsYou can retrieve particular rows/columns of a matrix by passing index values to the methods row()/col().And, you can set values to these using any of the variants of the setTo() methods.ExampleYou can use the following program code to create and display a simple matrix in Java using OpenCV library.On executing the above program, you will get the following output.Loading Image using JavaSE APIThe BufferedImage class of the java.awt.image.BufferedImage package is used to store an image and the ImageIO class of the package import javax.imageio provides methods to read and write Images.ExampleYou can use the following program code to load and save images using JavaSE library.On executing the above program, you will get the following output.If you open the specified path, you can observe the saved image as follows—End of ebook previewIf you liked what you saw…Buy it from our store @ https://。
- 1、下载文档前请自行甄别文档内容的完整性,平台不提供额外的编辑、内容补充、找答案等附加服务。
- 2、"仅部分预览"的文档,不可在线预览部分如存在完整性等问题,可反馈申请退款(可完整预览的文档不适用该条件!)。
- 3、如文档侵犯您的权益,请联系客服反馈,我们会尽快为您处理(人工客服工作时间:9:00-18:30)。
矩阵/向量数据操作及线性代数运算(矩阵乘积、矩阵方程求解、特征值、 奇异值分解) Matrix and vector manipulation and linear algebra routines (products, solvers, eigenvalues, SVD).
支持多种动态数据结构(链表、队列、数据集、树、图) Various dynamic data structures (lists, queues, sets, trees, graphs).
5.2 2、访问矩阵元素 5.2.1 (1) 假设需要访问一个 2D 浮点型矩阵的第(i, j)个单元. 5.2.2 (2) 间接访问: 5.2.3 (3) 直接访问(假设矩阵数据按 4 字节行对齐): 5.2.4 (4) 直接访问(当数据的行对齐可能存在间隙时 possible alignment gaps): 5.2.5 (5) 对于初始化后的矩阵进行直接访问: o 5.3 3、矩阵/向量运算 5.3.1 (1) 矩阵之间的运算: 5.3.2 (2) 矩阵之间的元素级运算: 5.3.3 (3) 向量乘积: 5.3.4 (4) 单一矩阵的运算: 5.3.5 (5) 非齐次线性方程求解: 5.3.6 (6) 特征值与特征向量 (矩阵为方阵): 6 六、视频处理 o 6.1 1、从视频流中捕捉一帧画面 6.1.1 (1) OpenCV 支持从摄像头或视频文件(AVI 格 式)中捕捉帧画面. 6.1.2 (2) 初始化一个摄像头捕捉器: 6.1.3 (3) 初始化一个视频文件捕捉器: 6.1.4 (4) 捕捉一帧画面: 6.1.5 (5) 释放视频流捕捉器: o 6.2 2、获取/设置视频流信息 6.2.1 (1) 获取视频流设备信息: 6.2.2 (2) 获取帧图信息: 6.2.3 (3) 设置从视频文件抓取的第一帧画面的位置: o 6.3 3、保存视频文件 6.3.1 (1) 初始化视频编写器: 6.3.2 (2) 保持视频文件: 6.3.3 (3) 释放视频编写器:
结构分析(连通域/分支、轮廓处理、距离转换、图像矩、模板匹配、霍 夫变换、多项式逼近、曲线拟合、椭圆拟合、狄劳尼三角化)
Structural analysis (connected components, contour processing, distance transform, various moments, template matching, Hough transform, polygonal approximation, line fitting, ellipse fitting, Delaunay triangulation).
基本图像处理(去噪、边缘检测、角点检测、采样与插值、色彩变换、 形态学处理、直方图、图像金字塔结构) Basic image processing (filtering, edge detection, corner detection, sampling and interpolation, color conversion, morphological operations, histograms, image pyramids).
o
[编辑]
一、简介
[编辑]
1、OpenCV 的特点
[编辑] (1) 总体描述
OpenCV 是一个基于 C/C++语言的开源图像处理函数库 其代码都经过优化,可用于实时处理图像 具有良好的可移植性 可以进行图像/视频载入、保存和采集的常规操作 具有低级和高级的应用程序接口(API) 提供了面向 Intel IPP 高效多媒体函数库的接口,可针对你使用的 Intel CPU 优化代码,提高程序性能(译注:OpenCV 2.0 版的代码已显 着优化,无需 IPP 来提升性能,故 2.0 版不再提供 IPP 接口)
3.2.2 (2) 一般矩阵: 3.2.3 (3) 标量: o 3.3 3、其它结构类型 3.3.1 (1) 点: 3.3.2 (2) 矩形框大小(以像素为精度): 3.3.3 (3) 矩形框的偏置和大小: 4 四、图像处理 o 4.1 1、图像的内存分配与释放 4.1.1 (1) 分配内存给一幅新图像: 4.1.2 (2) 释放图像: 4.1.3 (3) 复制图像: 4.1.4 (4) 设置/获取感兴趣区域 ROI: 4.1.5 (5) 设置/获取感兴趣通道 COI: o 4.2 2、图像读写 4.2.1 (1) 从文件中读入图像: 4.2.2 (2) 保存图像: o 4.3 3、访问图像像素 4.3.1 (1) 假设你要访问第 k 通道、第 i 行、第 j 列的 像素。 4.3.2 (2) 间接访问: (通用,但效率低,可访问任意格 式的图像) 4.3.3 (3) 直接访问: (效率高,但容易出错) 4.3.4 (4) 基于指针的直接访问: (简单高效) 4.3.5 (5) 基于 c++ wrapper 的直接访问: (更简单高 效) o 4.4 4、图像转换 4.4.1 (1) 字节型图像的灰度-彩色转换: 4.4.2 (2) 彩色图像->灰度图像: 4.4.3 (3) 不同彩色空间之间的转换: o 4.5 5、绘图指令 4.5.1 (1) 绘制矩形: 4.5.2 (2) 绘制圆形: 4.5.3 (3) 绘制线段: 4.5.4 (4) 绘制一组线段: 4.5.5 (5) 绘制一组填充颜色的多边形: 4.5.6 (6) 文本标注: 5 五、矩阵处理 o 5.1 1、矩阵的内存分配与释放 5.1.1 (1) 总体上: 5.1.2 (2) 为新矩阵分配内存: 5.1.3 (3) 释放矩阵内存: 5.1.4 (4) 复制矩阵: 5.1.5 (5) 初始化矩阵: 5.1.6 (6) 初始化矩阵为单位矩阵:
运动分析(光流、动作分割、目标跟踪) Motion analysis (optical flow, motion segmentation, tracking).
目标识别(特征方法、HMM 模型) Object recognition (eigen-methods, HMM).
基本的 GUI(显示图像/视频、键盘/鼠标操作、滑动条) Basic GUI (display image/video, keyboard and mouse handling, scroll-bars).
搜索文档
搜索论坛
Open Source Computer Vision Library
论坛 商业 专题 讲座 例程 安装 常见问题 函数说明
OpenCV 编程简介(矩阵/图像/视频的 基本读写操作)
Wikipedia,自由的百科全书
Introduction to programming with OpenCV OpenCV 编程简介
摄像头定标(寻找和跟踪定标模式、参数定标、基本矩阵估计、单应矩 阵估计、立体视觉匹配) Camera calibration (finding and tracking calibration patterns, calibration, fundamental matrix estimation, homography estimation, stereo correspondence).
[编辑] (3) 书籍:
Open Source Computer Vision Library
by Gary R. Bradski, Vadim Pisarevsky, and Jean-Yves Bouguet, Springer, 1st ed. (June, 2006). chenyusiyuan: 补充以下书籍
翻译: chenyusiyuan
January 26, 2010 /chenyusiyuan/archive/2010/01/26/5259060.as px
摘要: 本文旨在帮助读者快速入门 OpenCV,而无需阅读冗长的参考手册。掌 握了 OpenCV 的以下基础知识后,有需要的话再查阅相关的参考手册。
[编辑] (2) 功能
图像数据操作(内存分配与释放,图像复制、设定和转换) Image data manipulation (allocation, release, copying, setting, conversion).
图像/视频的输入输出(支持文件或摄像头的输入,图像/视频文件的输 出) Immera based input, image/video file output).
[编辑]
2、有用的学习资源
[编辑] (1) 参考手册:
<opencv-root>/docs/index.htm (译注:在你的 OpenCV 安装目录 <opencv-root>内)
[编辑] (2) 网络资源:
官方网站: /technology/computing/opencv/ 软件下载: /projects/opencvlibrary/
作者: Gady Agam
Department of Computer Science January 27, 2006 Illinois Institute of Technology URL: /~agam/cs512/lect-notes/opencvintro/opencv-intro.html#SECTION00040000000000000000
目录
1 一、简介 o 1.1 1、OpenCV 的特点 1.1.1 (1) 总体描述 1.1.2 (2) 功能 1.1.3 (3) OpenCV 模块 o 1.2 2、有用的学习资源 1.2.1 (1) 参考手册: 1.2.2 (2) 网络资源: 1.2.3 (3) 书籍: 1.2.4 (4) 视频处理例程(在 <opencvroot>/samples/c/): 1.2.5 (5) 图像处理例程 (在 <opencvroot>/samples/c/): o 1.3 3、OpenCV 命名规则 1.3.1 (1) 函数名: 1.3.2 (2) 矩阵数据类型: 1.3.3 (3) 图像数据类型: 1.3.4 (4) 头文件: o 1.4 4、编译建议 1.4.1 (1) Linux: 1.4.2 (2) Windows: o 1.5 5、C 例程 2 二、GUI 指令 o 2.1 1、窗口管理 2.1.1 (1) 创建和定位一个新窗口: 2.1.2 (2) 载入图像: 2.1.3 (3) 显示图像: 2.1.4 (4) 关闭窗口: 2.1.5 (5) 改变窗口大小: o 2.2 2、输入处理 2.2.1 (1) 处理鼠标事件: 2.2.2 (2) 处理键盘事件: 2.2.3 (3) 处理滑动条事件: 3 三、OpenCV 的基本数据结构 o 3.1 1、图像数据结构 3.1.1 (1) IPL 图像: o 3.2 2、矩阵与向量 3.2.1 (1) 矩阵: