热门标签 | HotTags
当前位置:  开发笔记 > 编程语言 > 正文

MatinOpenCV英文文档

OpenCVC++n-dimensionaldensearrayclassTheclassMatrepresentsann-dimensionaldensenumericals

OpenCV C++ n-dimensional dense array class The class "Mat" represents an n-dimensional dense numerical single-channel or multi-channel array. It can be used to store real or complex-valued vectors and matrices, grayscale or color images, voxel volumes, vector fields, point clouds, tensors, histograms (though, very high-dimensional histograms may be better stored in a "SparseMat"). The data layout of the array M is defined by the array "M.step[]", so that the address of element (i_0,...,i_(M.dims-1)), where 0 <= i_k= M.step[i+1]" (in fact, "M.step[i] >= M.step[i+1]*M.size[i+1]"). This means that 2-dimensional matrices are stored row-by-row, 3-dimensional matrices are stored plane-by-plane, and so on. "M.step[M.dims-1]" is minimal and always equal to the element size "M.elemSize()". So, the data layout in "Mat" is fully compatible with "CvMat", "IplImage", and "CvMatND" types from OpenCV 1.x. It is also compatible with the majority of dense array types from the standard toolkits and SDKs, such as Numpy (ndarray), Win32 (independent device bitmaps), and others, that is, with any array that uses *steps* (or *strides*) to compute the position of a pixel. Due to this compatibility, it is possible to make a "Mat" header for user-allocated data and process it in-place using OpenCV functions. There are many different ways to create a "Mat" object. The most popular options are listed below: * Use the "create(nrows, ncols, type)" method or the similar "Mat(nrows, ncols, type[, fillValue])" constructor. A new array of the specified size and type is allocated. "type" has the same meaning as in the "cvCreateMat" method. For example, "CV_8UC1" means a 8-bit single-channel array, "CV_32FC2" means a 2-channel (complex) floating-point array, and so on. As noted in the introduction to this chapter, "create()" allocates only a new array when the shape or type of the current array are different from the specified ones. * Create a multi-dimensional array: It passes the number of dimensiOns=1 to the "Mat" constructor but the created array will be 2-dimensional with the number of columns set to 1. So, "Mat.dims" is always >= 2 (can also be 0 when the array is empty). * Use a copy constructor or assignment operator where there can be an array or expression on the right side (see below). As noted in the introduction, the array assignment is an O(1) operation because it only copies the header and increases the reference counter. The "Mat.clone()" method can be used to get a full (deep) copy of the array when you need it. * Construct a header for a part of another array. It can be a single row, single column, several rows, several columns, rectangular region in the array (called a *minor* in algebra) or a diagonal. Such operations are also O(1) because the new header references the same data. You can actually modify a part of the array using this feature, for example: Due to the additional "datastart" and "dataend" members, it is possible to compute a relative sub-array position in the main *container* array using "locateROI()": As in case of whole matrices, if you need a deep copy, use the "clone()" method of the extracted sub-matrices. * Make a header for user-allocated data. It can be useful to do the following: #. Process "foreign" data using OpenCV (for example, when you implement a DirectShow* filter or a processing module for "gstreamer", and so on). For example: #. Quickly initialize small matrices and/or get a super-fast element access. Partial yet very common cases of this *user-allocated data* case are conversions from "CvMat" and "IplImage" to "Mat". For this purpose, there are special constructors taking pointers to "CvMat" or "IplImage" and the optional flag indicating whether to copy the data or not. Backward conversion from "Mat" to "CvMat" or "IplImage" is provided via cast operators "Mat.operator CvMat() const" and "Mat.operator IplImage()". The operators do NOT copy the data. * Use MATLAB-style array initializers, "zeros(), ones(), eye()", for example: * Use a comma-separated initializer: With this approach, you first call a constructor of the "Mat_" class with the proper parameters, and then you just put "<<" operator followed by comma-separated values that can be constants, variables, expressions, and so on. Also, note the extra parentheses required to avoid compilation errors. Once the array is created, it is automatically managed via a reference-counting mechanism. If the array header is built on top of user-allocated data, you should handle the data by yourself. The array data is deallocated when no one points to it. If you want to release the data pointed by a array header before the array destructor is called, use "Mat.release()". The next important thing to learn about the array class is element access. This manual already described how to compute an address of each array element. Normally, you are not required to use the formula directly in the code. If you know the array element type (which can be retrieved using the method "Mat.type()"), you can access the element M_(ij) of a 2-dimensional array as: assuming that M is a double-precision floating-point array. There are several variants of the method "at" for a different number of dimensions. If you need to process a whole row of a 2D array, the most efficient way is to get the pointer to the row first, and then just use the plain C operator "[]" : Some operations, like the one above, do not actually depend on the array shape. They just process elements of an array one by one (or elements from multiple arrays that have the same coordinates, for example, array addition). Such operations are called *element-wise*. It makes sense to check whether all the input/output arrays are continuous, namely, have no gaps at the end of each row. If yes, process them as a long single row: In case of the continuous matrix, the outer loop body is executed just once. So, the overhead is smaller, which is especially noticeable in case of small matrices. Finally, there are STL-style iterators that are smart enough to skip gaps between successive rows: The matrix iterators are random-access iterators, so they can be passed to any STL algorithm, including "std.sort()".

Mat in OpenCV英文文档


推荐阅读
  • 本文介绍了在 Android 开发中如何实现像素 (px)、缩放独立像素 (sp) 和密度独立像素 (dp) 之间的相互转换。这些方法对于确保应用在不同屏幕尺寸和分辨率上的适配至关重要。 ... [详细]
  • 本文旨在介绍Three.js的基础概念及其应用场景。Three.js是一个基于WebGL的JavaScript库,用于在网页上创建和显示3D图形。文中将从Canvas的基本功能出发,探讨其局限性,并引出WebGL及Three.js的解决方案。 ... [详细]
  • 本文介绍了一个简单的Python函数,该函数能够接收一个日期作为输入,并返回这一天是星期几。此功能通过使用Python的datetime模块实现。 ... [详细]
  • 学习目的:1.了解android线程的使用2.了解主线程与子线程区别3.解析异步处理机制主线程与子线程:所谓主线程,在Windows窗体应用程序中一般指UI线程,这个是程序启动的时 ... [详细]
  • 在现代多线程编程中,Lock接口提供的灵活性和控制力超越了传统的synchronized关键字。Lock接口不仅使锁成为一个独立的对象,还提供了更细粒度的锁定机制,例如读写锁(ReadWriteLock)。本文将探讨如何利用ReentrantReadWriteLock提高并发性能。 ... [详细]
  • 无脚本 JSP 的 Web 页面设计
    探讨了Web页面设计人员是否需要掌握Java技能,以及他们如何快速学习表达式语言(EL)。虽然EL的应用前景尚不明朗,但本文将重点介绍如何通过JSP的include指令有效整合页面元素。 ... [详细]
  • 本文深入探讨了Java注解的基本概念及其在现代Java开发中的应用。文章不仅介绍了如何创建和使用自定义注解,还详细讲解了如何利用反射机制解析注解,以及Java内建注解的使用场景。 ... [详细]
  • 本文详细介绍了如何手动编写兼容IE的Ajax函数,以及探讨了跨域请求的实现方法和原理,包括JSONP和服务器端设置HTTP头部等技术。 ... [详细]
  • 题目概述:给定一个数组,计算其中所有连续子序列中平均值不低于给定值k的数量。通过将每个元素减去k并计算前缀和,问题转化为二维数点问题。此问题可以通过离线处理,利用树状数组来高效解决。 ... [详细]
  • 本文介绍了一种利用迭代法解决特定方程问题的方法,特别是当给定函数f(x)在区间[x1, x2]内连续且f(x1)0时,存在一个x~使得f(x~)=0。通过逐步细化搜索范围,可以高效地找到方程的根。 ... [详细]
  • 本文通过具体示例探讨了在 C++ 中使用 extern "C" 的重要性及其作用,特别是如何影响编译后的对象文件中的符号名称。 ... [详细]
  • 使用Inno Setup将EXE与JRE封装为Windows安装程序
    本文详细介绍了如何利用Inno Setup工具将EXE文件及Java运行环境(JRE)整合为适用于Windows操作系统的安装程序。我们将提供必要的软件下载链接,并逐步指导您完成整个打包过程。 ... [详细]
  • Linux环境下Memcached安装指南
    本文详细介绍如何在Linux虚拟机上安装Memcached,包括必要的依赖库安装,以及使用Xshell进行文件传输的具体步骤。 ... [详细]
  • 矩阵交织技术详解
    本文介绍了矩阵交织的工作原理及其在通信系统中的应用。交织技术通过对信息码元的重新排列,能够在不增加编码冗余度的情况下,提升系统的突发错误检测能力,从而增强整体性能。 ... [详细]
  • 微信小程序配置详解:pages、window、tabBar与调试模式
    本文详细介绍了如何在微信小程序中配置pages、window、tabBar以及启用调试模式,帮助开发者更好地理解和应用这些配置选项。 ... [详细]
author-avatar
历史本轻狂
这个家伙很懒,什么也没留下!
PHP1.CN | 中国最专业的PHP中文社区 | DevBox开发工具箱 | json解析格式化 |PHP资讯 | PHP教程 | 数据库技术 | 服务器技术 | 前端开发技术 | PHP框架 | 开发工具 | 在线工具
Copyright © 1998 - 2020 PHP1.CN. All Rights Reserved | 京公网安备 11010802041100号 | 京ICP备19059560号-4 | PHP1.CN 第一PHP社区 版权所有