热门标签 | 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英文文档


推荐阅读
  • CSS 布局:液态三栏混合宽度布局
    本文介绍了如何使用 CSS 实现液态的三栏布局,其中各栏具有不同的宽度设置。通过调整容器和内容区域的属性,可以实现灵活且响应式的网页设计。 ... [详细]
  • 深入理解OAuth认证机制
    本文介绍了OAuth认证协议的核心概念及其工作原理。OAuth是一种开放标准,旨在为第三方应用提供安全的用户资源访问授权,同时确保用户的账户信息(如用户名和密码)不会暴露给第三方。 ... [详细]
  • QUIC协议:快速UDP互联网连接
    QUIC(Quick UDP Internet Connections)是谷歌开发的一种旨在提高网络性能和安全性的传输层协议。它基于UDP,并结合了TLS级别的安全性,提供了更高效、更可靠的互联网通信方式。 ... [详细]
  • 国内BI工具迎战国际巨头Tableau,稳步崛起
    尽管商业智能(BI)工具在中国的普及程度尚不及国际市场,但近年来,随着本土企业的持续创新和市场推广,国内主流BI工具正逐渐崭露头角。面对国际品牌如Tableau的强大竞争,国内BI工具通过不断优化产品和技术,赢得了越来越多用户的认可。 ... [详细]
  • 本文详细分析了JSP(JavaServer Pages)技术的主要优点和缺点,帮助开发者更好地理解其适用场景及潜在挑战。JSP作为一种服务器端技术,广泛应用于Web开发中。 ... [详细]
  • Windows服务与数据库交互问题解析
    本文探讨了在Windows 10(64位)环境下开发的Windows服务,旨在定期向本地MS SQL Server (v.11)插入记录。尽管服务已成功安装并运行,但记录并未正确插入。我们将详细分析可能的原因及解决方案。 ... [详细]
  • 深入理解 Oracle 存储函数:计算员工年收入
    本文介绍如何使用 Oracle 存储函数查询特定员工的年收入。我们将详细解释存储函数的创建过程,并提供完整的代码示例。 ... [详细]
  • 本文将介绍如何编写一些有趣的VBScript脚本,这些脚本可以在朋友之间进行无害的恶作剧。通过简单的代码示例,帮助您了解VBScript的基本语法和功能。 ... [详细]
  • 本文总结了2018年的关键成就,包括职业变动、购车、考取驾照等重要事件,并分享了读书、工作、家庭和朋友方面的感悟。同时,展望2019年,制定了健康、软实力提升和技术学习的具体目标。 ... [详细]
  • 本文详细介绍如何使用Python进行配置文件的读写操作,涵盖常见的配置文件格式(如INI、JSON、TOML和YAML),并提供具体的代码示例。 ... [详细]
  • 在计算机技术的学习道路上,51CTO学院以其专业性和专注度给我留下了深刻印象。从2012年接触计算机到2014年开始系统学习网络技术和安全领域,51CTO学院始终是我信赖的学习平台。 ... [详细]
  • Linux 系统启动故障排除指南:MBR 和 GRUB 问题
    本文详细介绍了 Linux 系统启动过程中常见的 MBR 扇区和 GRUB 引导程序故障及其解决方案,涵盖从备份、模拟故障到恢复的具体步骤。 ... [详细]
  • 本文介绍了如何使用jQuery根据元素的类型(如复选框)和标签名(如段落)来获取DOM对象。这有助于更高效地操作网页中的特定元素。 ... [详细]
  • PHP 5.2.5 安装与配置指南
    本文详细介绍了 PHP 5.2.5 的安装和配置步骤,帮助开发者解决常见的环境配置问题,特别是上传图片时遇到的错误。通过本教程,您可以顺利搭建并优化 PHP 运行环境。 ... [详细]
  • 深入理解Cookie与Session会话管理
    本文详细介绍了如何通过HTTP响应和请求处理浏览器的Cookie信息,以及如何创建、设置和管理Cookie。同时探讨了会话跟踪技术中的Session机制,解释其原理及应用场景。 ... [详细]
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社区 版权所有