openCV library for Renesas RZ/A
Dependents: RZ_A2M_Mbed_samples
include/opencv2/core/mat.hpp@0:0e0631af0305, 2021-01-29 (annotated)
- Committer:
- RyoheiHagimoto
- Date:
- Fri Jan 29 04:53:38 2021 +0000
- Revision:
- 0:0e0631af0305
copied from https://github.com/d-kato/opencv-lib.
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
RyoheiHagimoto | 0:0e0631af0305 | 1 | /*M/////////////////////////////////////////////////////////////////////////////////////// |
RyoheiHagimoto | 0:0e0631af0305 | 2 | // |
RyoheiHagimoto | 0:0e0631af0305 | 3 | // IMPORTANT: READ BEFORE DOWNLOADING, COPYING, INSTALLING OR USING. |
RyoheiHagimoto | 0:0e0631af0305 | 4 | // |
RyoheiHagimoto | 0:0e0631af0305 | 5 | // By downloading, copying, installing or using the software you agree to this license. |
RyoheiHagimoto | 0:0e0631af0305 | 6 | // If you do not agree to this license, do not download, install, |
RyoheiHagimoto | 0:0e0631af0305 | 7 | // copy or use the software. |
RyoheiHagimoto | 0:0e0631af0305 | 8 | // |
RyoheiHagimoto | 0:0e0631af0305 | 9 | // |
RyoheiHagimoto | 0:0e0631af0305 | 10 | // License Agreement |
RyoheiHagimoto | 0:0e0631af0305 | 11 | // For Open Source Computer Vision Library |
RyoheiHagimoto | 0:0e0631af0305 | 12 | // |
RyoheiHagimoto | 0:0e0631af0305 | 13 | // Copyright (C) 2000-2008, Intel Corporation, all rights reserved. |
RyoheiHagimoto | 0:0e0631af0305 | 14 | // Copyright (C) 2009, Willow Garage Inc., all rights reserved. |
RyoheiHagimoto | 0:0e0631af0305 | 15 | // Copyright (C) 2013, OpenCV Foundation, all rights reserved. |
RyoheiHagimoto | 0:0e0631af0305 | 16 | // Third party copyrights are property of their respective owners. |
RyoheiHagimoto | 0:0e0631af0305 | 17 | // |
RyoheiHagimoto | 0:0e0631af0305 | 18 | // Redistribution and use in source and binary forms, with or without modification, |
RyoheiHagimoto | 0:0e0631af0305 | 19 | // are permitted provided that the following conditions are met: |
RyoheiHagimoto | 0:0e0631af0305 | 20 | // |
RyoheiHagimoto | 0:0e0631af0305 | 21 | // * Redistribution's of source code must retain the above copyright notice, |
RyoheiHagimoto | 0:0e0631af0305 | 22 | // this list of conditions and the following disclaimer. |
RyoheiHagimoto | 0:0e0631af0305 | 23 | // |
RyoheiHagimoto | 0:0e0631af0305 | 24 | // * Redistribution's in binary form must reproduce the above copyright notice, |
RyoheiHagimoto | 0:0e0631af0305 | 25 | // this list of conditions and the following disclaimer in the documentation |
RyoheiHagimoto | 0:0e0631af0305 | 26 | // and/or other materials provided with the distribution. |
RyoheiHagimoto | 0:0e0631af0305 | 27 | // |
RyoheiHagimoto | 0:0e0631af0305 | 28 | // * The name of the copyright holders may not be used to endorse or promote products |
RyoheiHagimoto | 0:0e0631af0305 | 29 | // derived from this software without specific prior written permission. |
RyoheiHagimoto | 0:0e0631af0305 | 30 | // |
RyoheiHagimoto | 0:0e0631af0305 | 31 | // This software is provided by the copyright holders and contributors "as is" and |
RyoheiHagimoto | 0:0e0631af0305 | 32 | // any express or implied warranties, including, but not limited to, the implied |
RyoheiHagimoto | 0:0e0631af0305 | 33 | // warranties of merchantability and fitness for a particular purpose are disclaimed. |
RyoheiHagimoto | 0:0e0631af0305 | 34 | // In no event shall the Intel Corporation or contributors be liable for any direct, |
RyoheiHagimoto | 0:0e0631af0305 | 35 | // indirect, incidental, special, exemplary, or consequential damages |
RyoheiHagimoto | 0:0e0631af0305 | 36 | // (including, but not limited to, procurement of substitute goods or services; |
RyoheiHagimoto | 0:0e0631af0305 | 37 | // loss of use, data, or profits; or business interruption) however caused |
RyoheiHagimoto | 0:0e0631af0305 | 38 | // and on any theory of liability, whether in contract, strict liability, |
RyoheiHagimoto | 0:0e0631af0305 | 39 | // or tort (including negligence or otherwise) arising in any way out of |
RyoheiHagimoto | 0:0e0631af0305 | 40 | // the use of this software, even if advised of the possibility of such damage. |
RyoheiHagimoto | 0:0e0631af0305 | 41 | // |
RyoheiHagimoto | 0:0e0631af0305 | 42 | //M*/ |
RyoheiHagimoto | 0:0e0631af0305 | 43 | |
RyoheiHagimoto | 0:0e0631af0305 | 44 | #ifndef OPENCV_CORE_MAT_HPP |
RyoheiHagimoto | 0:0e0631af0305 | 45 | #define OPENCV_CORE_MAT_HPP |
RyoheiHagimoto | 0:0e0631af0305 | 46 | |
RyoheiHagimoto | 0:0e0631af0305 | 47 | #ifndef __cplusplus |
RyoheiHagimoto | 0:0e0631af0305 | 48 | # error mat.hpp header must be compiled as C++ |
RyoheiHagimoto | 0:0e0631af0305 | 49 | #endif |
RyoheiHagimoto | 0:0e0631af0305 | 50 | |
RyoheiHagimoto | 0:0e0631af0305 | 51 | #include "opencv2/core/matx.hpp" |
RyoheiHagimoto | 0:0e0631af0305 | 52 | #include "opencv2/core/types.hpp" |
RyoheiHagimoto | 0:0e0631af0305 | 53 | |
RyoheiHagimoto | 0:0e0631af0305 | 54 | #include "opencv2/core/bufferpool.hpp" |
RyoheiHagimoto | 0:0e0631af0305 | 55 | |
RyoheiHagimoto | 0:0e0631af0305 | 56 | namespace cv |
RyoheiHagimoto | 0:0e0631af0305 | 57 | { |
RyoheiHagimoto | 0:0e0631af0305 | 58 | |
RyoheiHagimoto | 0:0e0631af0305 | 59 | //! @addtogroup core_basic |
RyoheiHagimoto | 0:0e0631af0305 | 60 | //! @{ |
RyoheiHagimoto | 0:0e0631af0305 | 61 | |
RyoheiHagimoto | 0:0e0631af0305 | 62 | enum { ACCESS_READ=1<<24, ACCESS_WRITE=1<<25, |
RyoheiHagimoto | 0:0e0631af0305 | 63 | ACCESS_RW=3<<24, ACCESS_MASK=ACCESS_RW, ACCESS_FAST=1<<26 }; |
RyoheiHagimoto | 0:0e0631af0305 | 64 | |
RyoheiHagimoto | 0:0e0631af0305 | 65 | class CV_EXPORTS _OutputArray; |
RyoheiHagimoto | 0:0e0631af0305 | 66 | |
RyoheiHagimoto | 0:0e0631af0305 | 67 | //////////////////////// Input/Output Array Arguments ///////////////////////////////// |
RyoheiHagimoto | 0:0e0631af0305 | 68 | |
RyoheiHagimoto | 0:0e0631af0305 | 69 | /** @brief This is the proxy class for passing read-only input arrays into OpenCV functions. |
RyoheiHagimoto | 0:0e0631af0305 | 70 | |
RyoheiHagimoto | 0:0e0631af0305 | 71 | It is defined as: |
RyoheiHagimoto | 0:0e0631af0305 | 72 | @code |
RyoheiHagimoto | 0:0e0631af0305 | 73 | typedef const _InputArray& InputArray; |
RyoheiHagimoto | 0:0e0631af0305 | 74 | @endcode |
RyoheiHagimoto | 0:0e0631af0305 | 75 | where _InputArray is a class that can be constructed from `Mat`, `Mat_<T>`, `Matx<T, m, n>`, |
RyoheiHagimoto | 0:0e0631af0305 | 76 | `std::vector<T>`, `std::vector<std::vector<T> >` or `std::vector<Mat>`. It can also be constructed |
RyoheiHagimoto | 0:0e0631af0305 | 77 | from a matrix expression. |
RyoheiHagimoto | 0:0e0631af0305 | 78 | |
RyoheiHagimoto | 0:0e0631af0305 | 79 | Since this is mostly implementation-level class, and its interface may change in future versions, we |
RyoheiHagimoto | 0:0e0631af0305 | 80 | do not describe it in details. There are a few key things, though, that should be kept in mind: |
RyoheiHagimoto | 0:0e0631af0305 | 81 | |
RyoheiHagimoto | 0:0e0631af0305 | 82 | - When you see in the reference manual or in OpenCV source code a function that takes |
RyoheiHagimoto | 0:0e0631af0305 | 83 | InputArray, it means that you can actually pass `Mat`, `Matx`, `vector<T>` etc. (see above the |
RyoheiHagimoto | 0:0e0631af0305 | 84 | complete list). |
RyoheiHagimoto | 0:0e0631af0305 | 85 | - Optional input arguments: If some of the input arrays may be empty, pass cv::noArray() (or |
RyoheiHagimoto | 0:0e0631af0305 | 86 | simply cv::Mat() as you probably did before). |
RyoheiHagimoto | 0:0e0631af0305 | 87 | - The class is designed solely for passing parameters. That is, normally you *should not* |
RyoheiHagimoto | 0:0e0631af0305 | 88 | declare class members, local and global variables of this type. |
RyoheiHagimoto | 0:0e0631af0305 | 89 | - If you want to design your own function or a class method that can operate of arrays of |
RyoheiHagimoto | 0:0e0631af0305 | 90 | multiple types, you can use InputArray (or OutputArray) for the respective parameters. Inside |
RyoheiHagimoto | 0:0e0631af0305 | 91 | a function you should use _InputArray::getMat() method to construct a matrix header for the |
RyoheiHagimoto | 0:0e0631af0305 | 92 | array (without copying data). _InputArray::kind() can be used to distinguish Mat from |
RyoheiHagimoto | 0:0e0631af0305 | 93 | `vector<>` etc., but normally it is not needed. |
RyoheiHagimoto | 0:0e0631af0305 | 94 | |
RyoheiHagimoto | 0:0e0631af0305 | 95 | Here is how you can use a function that takes InputArray : |
RyoheiHagimoto | 0:0e0631af0305 | 96 | @code |
RyoheiHagimoto | 0:0e0631af0305 | 97 | std::vector<Point2f> vec; |
RyoheiHagimoto | 0:0e0631af0305 | 98 | // points or a circle |
RyoheiHagimoto | 0:0e0631af0305 | 99 | for( int i = 0; i < 30; i++ ) |
RyoheiHagimoto | 0:0e0631af0305 | 100 | vec.push_back(Point2f((float)(100 + 30*cos(i*CV_PI*2/5)), |
RyoheiHagimoto | 0:0e0631af0305 | 101 | (float)(100 - 30*sin(i*CV_PI*2/5)))); |
RyoheiHagimoto | 0:0e0631af0305 | 102 | cv::transform(vec, vec, cv::Matx23f(0.707, -0.707, 10, 0.707, 0.707, 20)); |
RyoheiHagimoto | 0:0e0631af0305 | 103 | @endcode |
RyoheiHagimoto | 0:0e0631af0305 | 104 | That is, we form an STL vector containing points, and apply in-place affine transformation to the |
RyoheiHagimoto | 0:0e0631af0305 | 105 | vector using the 2x3 matrix created inline as `Matx<float, 2, 3>` instance. |
RyoheiHagimoto | 0:0e0631af0305 | 106 | |
RyoheiHagimoto | 0:0e0631af0305 | 107 | Here is how such a function can be implemented (for simplicity, we implement a very specific case of |
RyoheiHagimoto | 0:0e0631af0305 | 108 | it, according to the assertion statement inside) : |
RyoheiHagimoto | 0:0e0631af0305 | 109 | @code |
RyoheiHagimoto | 0:0e0631af0305 | 110 | void myAffineTransform(InputArray _src, OutputArray _dst, InputArray _m) |
RyoheiHagimoto | 0:0e0631af0305 | 111 | { |
RyoheiHagimoto | 0:0e0631af0305 | 112 | // get Mat headers for input arrays. This is O(1) operation, |
RyoheiHagimoto | 0:0e0631af0305 | 113 | // unless _src and/or _m are matrix expressions. |
RyoheiHagimoto | 0:0e0631af0305 | 114 | Mat src = _src.getMat(), m = _m.getMat(); |
RyoheiHagimoto | 0:0e0631af0305 | 115 | CV_Assert( src.type() == CV_32FC2 && m.type() == CV_32F && m.size() == Size(3, 2) ); |
RyoheiHagimoto | 0:0e0631af0305 | 116 | |
RyoheiHagimoto | 0:0e0631af0305 | 117 | // [re]create the output array so that it has the proper size and type. |
RyoheiHagimoto | 0:0e0631af0305 | 118 | // In case of Mat it calls Mat::create, in case of STL vector it calls vector::resize. |
RyoheiHagimoto | 0:0e0631af0305 | 119 | _dst.create(src.size(), src.type()); |
RyoheiHagimoto | 0:0e0631af0305 | 120 | Mat dst = _dst.getMat(); |
RyoheiHagimoto | 0:0e0631af0305 | 121 | |
RyoheiHagimoto | 0:0e0631af0305 | 122 | for( int i = 0; i < src.rows; i++ ) |
RyoheiHagimoto | 0:0e0631af0305 | 123 | for( int j = 0; j < src.cols; j++ ) |
RyoheiHagimoto | 0:0e0631af0305 | 124 | { |
RyoheiHagimoto | 0:0e0631af0305 | 125 | Point2f pt = src.at<Point2f>(i, j); |
RyoheiHagimoto | 0:0e0631af0305 | 126 | dst.at<Point2f>(i, j) = Point2f(m.at<float>(0, 0)*pt.x + |
RyoheiHagimoto | 0:0e0631af0305 | 127 | m.at<float>(0, 1)*pt.y + |
RyoheiHagimoto | 0:0e0631af0305 | 128 | m.at<float>(0, 2), |
RyoheiHagimoto | 0:0e0631af0305 | 129 | m.at<float>(1, 0)*pt.x + |
RyoheiHagimoto | 0:0e0631af0305 | 130 | m.at<float>(1, 1)*pt.y + |
RyoheiHagimoto | 0:0e0631af0305 | 131 | m.at<float>(1, 2)); |
RyoheiHagimoto | 0:0e0631af0305 | 132 | } |
RyoheiHagimoto | 0:0e0631af0305 | 133 | } |
RyoheiHagimoto | 0:0e0631af0305 | 134 | @endcode |
RyoheiHagimoto | 0:0e0631af0305 | 135 | There is another related type, InputArrayOfArrays, which is currently defined as a synonym for |
RyoheiHagimoto | 0:0e0631af0305 | 136 | InputArray: |
RyoheiHagimoto | 0:0e0631af0305 | 137 | @code |
RyoheiHagimoto | 0:0e0631af0305 | 138 | typedef InputArray InputArrayOfArrays; |
RyoheiHagimoto | 0:0e0631af0305 | 139 | @endcode |
RyoheiHagimoto | 0:0e0631af0305 | 140 | It denotes function arguments that are either vectors of vectors or vectors of matrices. A separate |
RyoheiHagimoto | 0:0e0631af0305 | 141 | synonym is needed to generate Python/Java etc. wrappers properly. At the function implementation |
RyoheiHagimoto | 0:0e0631af0305 | 142 | level their use is similar, but _InputArray::getMat(idx) should be used to get header for the |
RyoheiHagimoto | 0:0e0631af0305 | 143 | idx-th component of the outer vector and _InputArray::size().area() should be used to find the |
RyoheiHagimoto | 0:0e0631af0305 | 144 | number of components (vectors/matrices) of the outer vector. |
RyoheiHagimoto | 0:0e0631af0305 | 145 | */ |
RyoheiHagimoto | 0:0e0631af0305 | 146 | class CV_EXPORTS _InputArray |
RyoheiHagimoto | 0:0e0631af0305 | 147 | { |
RyoheiHagimoto | 0:0e0631af0305 | 148 | public: |
RyoheiHagimoto | 0:0e0631af0305 | 149 | enum { |
RyoheiHagimoto | 0:0e0631af0305 | 150 | KIND_SHIFT = 16, |
RyoheiHagimoto | 0:0e0631af0305 | 151 | FIXED_TYPE = 0x8000 << KIND_SHIFT, |
RyoheiHagimoto | 0:0e0631af0305 | 152 | FIXED_SIZE = 0x4000 << KIND_SHIFT, |
RyoheiHagimoto | 0:0e0631af0305 | 153 | KIND_MASK = 31 << KIND_SHIFT, |
RyoheiHagimoto | 0:0e0631af0305 | 154 | |
RyoheiHagimoto | 0:0e0631af0305 | 155 | NONE = 0 << KIND_SHIFT, |
RyoheiHagimoto | 0:0e0631af0305 | 156 | MAT = 1 << KIND_SHIFT, |
RyoheiHagimoto | 0:0e0631af0305 | 157 | MATX = 2 << KIND_SHIFT, |
RyoheiHagimoto | 0:0e0631af0305 | 158 | STD_VECTOR = 3 << KIND_SHIFT, |
RyoheiHagimoto | 0:0e0631af0305 | 159 | STD_VECTOR_VECTOR = 4 << KIND_SHIFT, |
RyoheiHagimoto | 0:0e0631af0305 | 160 | STD_VECTOR_MAT = 5 << KIND_SHIFT, |
RyoheiHagimoto | 0:0e0631af0305 | 161 | EXPR = 6 << KIND_SHIFT, |
RyoheiHagimoto | 0:0e0631af0305 | 162 | OPENGL_BUFFER = 7 << KIND_SHIFT, |
RyoheiHagimoto | 0:0e0631af0305 | 163 | CUDA_HOST_MEM = 8 << KIND_SHIFT, |
RyoheiHagimoto | 0:0e0631af0305 | 164 | CUDA_GPU_MAT = 9 << KIND_SHIFT, |
RyoheiHagimoto | 0:0e0631af0305 | 165 | UMAT =10 << KIND_SHIFT, |
RyoheiHagimoto | 0:0e0631af0305 | 166 | STD_VECTOR_UMAT =11 << KIND_SHIFT, |
RyoheiHagimoto | 0:0e0631af0305 | 167 | STD_BOOL_VECTOR =12 << KIND_SHIFT, |
RyoheiHagimoto | 0:0e0631af0305 | 168 | STD_VECTOR_CUDA_GPU_MAT = 13 << KIND_SHIFT |
RyoheiHagimoto | 0:0e0631af0305 | 169 | }; |
RyoheiHagimoto | 0:0e0631af0305 | 170 | |
RyoheiHagimoto | 0:0e0631af0305 | 171 | _InputArray(); |
RyoheiHagimoto | 0:0e0631af0305 | 172 | _InputArray(int _flags, void* _obj); |
RyoheiHagimoto | 0:0e0631af0305 | 173 | _InputArray(const Mat& m); |
RyoheiHagimoto | 0:0e0631af0305 | 174 | _InputArray(const MatExpr& expr); |
RyoheiHagimoto | 0:0e0631af0305 | 175 | _InputArray(const std::vector<Mat>& vec); |
RyoheiHagimoto | 0:0e0631af0305 | 176 | template<typename _Tp> _InputArray(const Mat_<_Tp>& m); |
RyoheiHagimoto | 0:0e0631af0305 | 177 | template<typename _Tp> _InputArray(const std::vector<_Tp>& vec); |
RyoheiHagimoto | 0:0e0631af0305 | 178 | _InputArray(const std::vector<bool>& vec); |
RyoheiHagimoto | 0:0e0631af0305 | 179 | template<typename _Tp> _InputArray(const std::vector<std::vector<_Tp> >& vec); |
RyoheiHagimoto | 0:0e0631af0305 | 180 | template<typename _Tp> _InputArray(const std::vector<Mat_<_Tp> >& vec); |
RyoheiHagimoto | 0:0e0631af0305 | 181 | template<typename _Tp> _InputArray(const _Tp* vec, int n); |
RyoheiHagimoto | 0:0e0631af0305 | 182 | template<typename _Tp, int m, int n> _InputArray(const Matx<_Tp, m, n>& matx); |
RyoheiHagimoto | 0:0e0631af0305 | 183 | _InputArray(const double& val); |
RyoheiHagimoto | 0:0e0631af0305 | 184 | _InputArray(const cuda::GpuMat& d_mat); |
RyoheiHagimoto | 0:0e0631af0305 | 185 | _InputArray(const std::vector<cuda::GpuMat>& d_mat_array); |
RyoheiHagimoto | 0:0e0631af0305 | 186 | _InputArray(const ogl::Buffer& buf); |
RyoheiHagimoto | 0:0e0631af0305 | 187 | _InputArray(const cuda::HostMem& cuda_mem); |
RyoheiHagimoto | 0:0e0631af0305 | 188 | template<typename _Tp> _InputArray(const cudev::GpuMat_<_Tp>& m); |
RyoheiHagimoto | 0:0e0631af0305 | 189 | _InputArray(const UMat& um); |
RyoheiHagimoto | 0:0e0631af0305 | 190 | _InputArray(const std::vector<UMat>& umv); |
RyoheiHagimoto | 0:0e0631af0305 | 191 | |
RyoheiHagimoto | 0:0e0631af0305 | 192 | Mat getMat(int idx=-1) const; |
RyoheiHagimoto | 0:0e0631af0305 | 193 | Mat getMat_(int idx=-1) const; |
RyoheiHagimoto | 0:0e0631af0305 | 194 | UMat getUMat(int idx=-1) const; |
RyoheiHagimoto | 0:0e0631af0305 | 195 | void getMatVector(std::vector<Mat>& mv) const; |
RyoheiHagimoto | 0:0e0631af0305 | 196 | void getUMatVector(std::vector<UMat>& umv) const; |
RyoheiHagimoto | 0:0e0631af0305 | 197 | void getGpuMatVector(std::vector<cuda::GpuMat>& gpumv) const; |
RyoheiHagimoto | 0:0e0631af0305 | 198 | cuda::GpuMat getGpuMat() const; |
RyoheiHagimoto | 0:0e0631af0305 | 199 | ogl::Buffer getOGlBuffer() const; |
RyoheiHagimoto | 0:0e0631af0305 | 200 | |
RyoheiHagimoto | 0:0e0631af0305 | 201 | int getFlags() const; |
RyoheiHagimoto | 0:0e0631af0305 | 202 | void* getObj() const; |
RyoheiHagimoto | 0:0e0631af0305 | 203 | Size getSz() const; |
RyoheiHagimoto | 0:0e0631af0305 | 204 | |
RyoheiHagimoto | 0:0e0631af0305 | 205 | int kind() const; |
RyoheiHagimoto | 0:0e0631af0305 | 206 | int dims(int i=-1) const; |
RyoheiHagimoto | 0:0e0631af0305 | 207 | int cols(int i=-1) const; |
RyoheiHagimoto | 0:0e0631af0305 | 208 | int rows(int i=-1) const; |
RyoheiHagimoto | 0:0e0631af0305 | 209 | Size size(int i=-1) const; |
RyoheiHagimoto | 0:0e0631af0305 | 210 | int sizend(int* sz, int i=-1) const; |
RyoheiHagimoto | 0:0e0631af0305 | 211 | bool sameSize(const _InputArray& arr) const; |
RyoheiHagimoto | 0:0e0631af0305 | 212 | size_t total(int i=-1) const; |
RyoheiHagimoto | 0:0e0631af0305 | 213 | int type(int i=-1) const; |
RyoheiHagimoto | 0:0e0631af0305 | 214 | int depth(int i=-1) const; |
RyoheiHagimoto | 0:0e0631af0305 | 215 | int channels(int i=-1) const; |
RyoheiHagimoto | 0:0e0631af0305 | 216 | bool isContinuous(int i=-1) const; |
RyoheiHagimoto | 0:0e0631af0305 | 217 | bool isSubmatrix(int i=-1) const; |
RyoheiHagimoto | 0:0e0631af0305 | 218 | bool empty() const; |
RyoheiHagimoto | 0:0e0631af0305 | 219 | void copyTo(const _OutputArray& arr) const; |
RyoheiHagimoto | 0:0e0631af0305 | 220 | void copyTo(const _OutputArray& arr, const _InputArray & mask) const; |
RyoheiHagimoto | 0:0e0631af0305 | 221 | size_t offset(int i=-1) const; |
RyoheiHagimoto | 0:0e0631af0305 | 222 | size_t step(int i=-1) const; |
RyoheiHagimoto | 0:0e0631af0305 | 223 | bool isMat() const; |
RyoheiHagimoto | 0:0e0631af0305 | 224 | bool isUMat() const; |
RyoheiHagimoto | 0:0e0631af0305 | 225 | bool isMatVector() const; |
RyoheiHagimoto | 0:0e0631af0305 | 226 | bool isUMatVector() const; |
RyoheiHagimoto | 0:0e0631af0305 | 227 | bool isMatx() const; |
RyoheiHagimoto | 0:0e0631af0305 | 228 | bool isVector() const; |
RyoheiHagimoto | 0:0e0631af0305 | 229 | bool isGpuMatVector() const; |
RyoheiHagimoto | 0:0e0631af0305 | 230 | ~_InputArray(); |
RyoheiHagimoto | 0:0e0631af0305 | 231 | |
RyoheiHagimoto | 0:0e0631af0305 | 232 | protected: |
RyoheiHagimoto | 0:0e0631af0305 | 233 | int flags; |
RyoheiHagimoto | 0:0e0631af0305 | 234 | void* obj; |
RyoheiHagimoto | 0:0e0631af0305 | 235 | Size sz; |
RyoheiHagimoto | 0:0e0631af0305 | 236 | |
RyoheiHagimoto | 0:0e0631af0305 | 237 | void init(int _flags, const void* _obj); |
RyoheiHagimoto | 0:0e0631af0305 | 238 | void init(int _flags, const void* _obj, Size _sz); |
RyoheiHagimoto | 0:0e0631af0305 | 239 | }; |
RyoheiHagimoto | 0:0e0631af0305 | 240 | |
RyoheiHagimoto | 0:0e0631af0305 | 241 | |
RyoheiHagimoto | 0:0e0631af0305 | 242 | /** @brief This type is very similar to InputArray except that it is used for input/output and output function |
RyoheiHagimoto | 0:0e0631af0305 | 243 | parameters. |
RyoheiHagimoto | 0:0e0631af0305 | 244 | |
RyoheiHagimoto | 0:0e0631af0305 | 245 | Just like with InputArray, OpenCV users should not care about OutputArray, they just pass `Mat`, |
RyoheiHagimoto | 0:0e0631af0305 | 246 | `vector<T>` etc. to the functions. The same limitation as for `InputArray`: *Do not explicitly |
RyoheiHagimoto | 0:0e0631af0305 | 247 | create OutputArray instances* applies here too. |
RyoheiHagimoto | 0:0e0631af0305 | 248 | |
RyoheiHagimoto | 0:0e0631af0305 | 249 | If you want to make your function polymorphic (i.e. accept different arrays as output parameters), |
RyoheiHagimoto | 0:0e0631af0305 | 250 | it is also not very difficult. Take the sample above as the reference. Note that |
RyoheiHagimoto | 0:0e0631af0305 | 251 | _OutputArray::create() needs to be called before _OutputArray::getMat(). This way you guarantee |
RyoheiHagimoto | 0:0e0631af0305 | 252 | that the output array is properly allocated. |
RyoheiHagimoto | 0:0e0631af0305 | 253 | |
RyoheiHagimoto | 0:0e0631af0305 | 254 | Optional output parameters. If you do not need certain output array to be computed and returned to |
RyoheiHagimoto | 0:0e0631af0305 | 255 | you, pass cv::noArray(), just like you would in the case of optional input array. At the |
RyoheiHagimoto | 0:0e0631af0305 | 256 | implementation level, use _OutputArray::needed() to check if certain output array needs to be |
RyoheiHagimoto | 0:0e0631af0305 | 257 | computed or not. |
RyoheiHagimoto | 0:0e0631af0305 | 258 | |
RyoheiHagimoto | 0:0e0631af0305 | 259 | There are several synonyms for OutputArray that are used to assist automatic Python/Java/... wrapper |
RyoheiHagimoto | 0:0e0631af0305 | 260 | generators: |
RyoheiHagimoto | 0:0e0631af0305 | 261 | @code |
RyoheiHagimoto | 0:0e0631af0305 | 262 | typedef OutputArray OutputArrayOfArrays; |
RyoheiHagimoto | 0:0e0631af0305 | 263 | typedef OutputArray InputOutputArray; |
RyoheiHagimoto | 0:0e0631af0305 | 264 | typedef OutputArray InputOutputArrayOfArrays; |
RyoheiHagimoto | 0:0e0631af0305 | 265 | @endcode |
RyoheiHagimoto | 0:0e0631af0305 | 266 | */ |
RyoheiHagimoto | 0:0e0631af0305 | 267 | class CV_EXPORTS _OutputArray : public _InputArray |
RyoheiHagimoto | 0:0e0631af0305 | 268 | { |
RyoheiHagimoto | 0:0e0631af0305 | 269 | public: |
RyoheiHagimoto | 0:0e0631af0305 | 270 | enum |
RyoheiHagimoto | 0:0e0631af0305 | 271 | { |
RyoheiHagimoto | 0:0e0631af0305 | 272 | DEPTH_MASK_8U = 1 << CV_8U, |
RyoheiHagimoto | 0:0e0631af0305 | 273 | DEPTH_MASK_8S = 1 << CV_8S, |
RyoheiHagimoto | 0:0e0631af0305 | 274 | DEPTH_MASK_16U = 1 << CV_16U, |
RyoheiHagimoto | 0:0e0631af0305 | 275 | DEPTH_MASK_16S = 1 << CV_16S, |
RyoheiHagimoto | 0:0e0631af0305 | 276 | DEPTH_MASK_32S = 1 << CV_32S, |
RyoheiHagimoto | 0:0e0631af0305 | 277 | DEPTH_MASK_32F = 1 << CV_32F, |
RyoheiHagimoto | 0:0e0631af0305 | 278 | DEPTH_MASK_64F = 1 << CV_64F, |
RyoheiHagimoto | 0:0e0631af0305 | 279 | DEPTH_MASK_ALL = (DEPTH_MASK_64F<<1)-1, |
RyoheiHagimoto | 0:0e0631af0305 | 280 | DEPTH_MASK_ALL_BUT_8S = DEPTH_MASK_ALL & ~DEPTH_MASK_8S, |
RyoheiHagimoto | 0:0e0631af0305 | 281 | DEPTH_MASK_FLT = DEPTH_MASK_32F + DEPTH_MASK_64F |
RyoheiHagimoto | 0:0e0631af0305 | 282 | }; |
RyoheiHagimoto | 0:0e0631af0305 | 283 | |
RyoheiHagimoto | 0:0e0631af0305 | 284 | _OutputArray(); |
RyoheiHagimoto | 0:0e0631af0305 | 285 | _OutputArray(int _flags, void* _obj); |
RyoheiHagimoto | 0:0e0631af0305 | 286 | _OutputArray(Mat& m); |
RyoheiHagimoto | 0:0e0631af0305 | 287 | _OutputArray(std::vector<Mat>& vec); |
RyoheiHagimoto | 0:0e0631af0305 | 288 | _OutputArray(cuda::GpuMat& d_mat); |
RyoheiHagimoto | 0:0e0631af0305 | 289 | _OutputArray(std::vector<cuda::GpuMat>& d_mat); |
RyoheiHagimoto | 0:0e0631af0305 | 290 | _OutputArray(ogl::Buffer& buf); |
RyoheiHagimoto | 0:0e0631af0305 | 291 | _OutputArray(cuda::HostMem& cuda_mem); |
RyoheiHagimoto | 0:0e0631af0305 | 292 | template<typename _Tp> _OutputArray(cudev::GpuMat_<_Tp>& m); |
RyoheiHagimoto | 0:0e0631af0305 | 293 | template<typename _Tp> _OutputArray(std::vector<_Tp>& vec); |
RyoheiHagimoto | 0:0e0631af0305 | 294 | _OutputArray(std::vector<bool>& vec); |
RyoheiHagimoto | 0:0e0631af0305 | 295 | template<typename _Tp> _OutputArray(std::vector<std::vector<_Tp> >& vec); |
RyoheiHagimoto | 0:0e0631af0305 | 296 | template<typename _Tp> _OutputArray(std::vector<Mat_<_Tp> >& vec); |
RyoheiHagimoto | 0:0e0631af0305 | 297 | template<typename _Tp> _OutputArray(Mat_<_Tp>& m); |
RyoheiHagimoto | 0:0e0631af0305 | 298 | template<typename _Tp> _OutputArray(_Tp* vec, int n); |
RyoheiHagimoto | 0:0e0631af0305 | 299 | template<typename _Tp, int m, int n> _OutputArray(Matx<_Tp, m, n>& matx); |
RyoheiHagimoto | 0:0e0631af0305 | 300 | _OutputArray(UMat& m); |
RyoheiHagimoto | 0:0e0631af0305 | 301 | _OutputArray(std::vector<UMat>& vec); |
RyoheiHagimoto | 0:0e0631af0305 | 302 | |
RyoheiHagimoto | 0:0e0631af0305 | 303 | _OutputArray(const Mat& m); |
RyoheiHagimoto | 0:0e0631af0305 | 304 | _OutputArray(const std::vector<Mat>& vec); |
RyoheiHagimoto | 0:0e0631af0305 | 305 | _OutputArray(const cuda::GpuMat& d_mat); |
RyoheiHagimoto | 0:0e0631af0305 | 306 | _OutputArray(const std::vector<cuda::GpuMat>& d_mat); |
RyoheiHagimoto | 0:0e0631af0305 | 307 | _OutputArray(const ogl::Buffer& buf); |
RyoheiHagimoto | 0:0e0631af0305 | 308 | _OutputArray(const cuda::HostMem& cuda_mem); |
RyoheiHagimoto | 0:0e0631af0305 | 309 | template<typename _Tp> _OutputArray(const cudev::GpuMat_<_Tp>& m); |
RyoheiHagimoto | 0:0e0631af0305 | 310 | template<typename _Tp> _OutputArray(const std::vector<_Tp>& vec); |
RyoheiHagimoto | 0:0e0631af0305 | 311 | template<typename _Tp> _OutputArray(const std::vector<std::vector<_Tp> >& vec); |
RyoheiHagimoto | 0:0e0631af0305 | 312 | template<typename _Tp> _OutputArray(const std::vector<Mat_<_Tp> >& vec); |
RyoheiHagimoto | 0:0e0631af0305 | 313 | template<typename _Tp> _OutputArray(const Mat_<_Tp>& m); |
RyoheiHagimoto | 0:0e0631af0305 | 314 | template<typename _Tp> _OutputArray(const _Tp* vec, int n); |
RyoheiHagimoto | 0:0e0631af0305 | 315 | template<typename _Tp, int m, int n> _OutputArray(const Matx<_Tp, m, n>& matx); |
RyoheiHagimoto | 0:0e0631af0305 | 316 | _OutputArray(const UMat& m); |
RyoheiHagimoto | 0:0e0631af0305 | 317 | _OutputArray(const std::vector<UMat>& vec); |
RyoheiHagimoto | 0:0e0631af0305 | 318 | |
RyoheiHagimoto | 0:0e0631af0305 | 319 | bool fixedSize() const; |
RyoheiHagimoto | 0:0e0631af0305 | 320 | bool fixedType() const; |
RyoheiHagimoto | 0:0e0631af0305 | 321 | bool needed() const; |
RyoheiHagimoto | 0:0e0631af0305 | 322 | Mat& getMatRef(int i=-1) const; |
RyoheiHagimoto | 0:0e0631af0305 | 323 | UMat& getUMatRef(int i=-1) const; |
RyoheiHagimoto | 0:0e0631af0305 | 324 | cuda::GpuMat& getGpuMatRef() const; |
RyoheiHagimoto | 0:0e0631af0305 | 325 | std::vector<cuda::GpuMat>& getGpuMatVecRef() const; |
RyoheiHagimoto | 0:0e0631af0305 | 326 | ogl::Buffer& getOGlBufferRef() const; |
RyoheiHagimoto | 0:0e0631af0305 | 327 | cuda::HostMem& getHostMemRef() const; |
RyoheiHagimoto | 0:0e0631af0305 | 328 | void create(Size sz, int type, int i=-1, bool allowTransposed=false, int fixedDepthMask=0) const; |
RyoheiHagimoto | 0:0e0631af0305 | 329 | void create(int rows, int cols, int type, int i=-1, bool allowTransposed=false, int fixedDepthMask=0) const; |
RyoheiHagimoto | 0:0e0631af0305 | 330 | void create(int dims, const int* size, int type, int i=-1, bool allowTransposed=false, int fixedDepthMask=0) const; |
RyoheiHagimoto | 0:0e0631af0305 | 331 | void createSameSize(const _InputArray& arr, int mtype) const; |
RyoheiHagimoto | 0:0e0631af0305 | 332 | void release() const; |
RyoheiHagimoto | 0:0e0631af0305 | 333 | void clear() const; |
RyoheiHagimoto | 0:0e0631af0305 | 334 | void setTo(const _InputArray& value, const _InputArray & mask = _InputArray()) const; |
RyoheiHagimoto | 0:0e0631af0305 | 335 | |
RyoheiHagimoto | 0:0e0631af0305 | 336 | void assign(const UMat& u) const; |
RyoheiHagimoto | 0:0e0631af0305 | 337 | void assign(const Mat& m) const; |
RyoheiHagimoto | 0:0e0631af0305 | 338 | }; |
RyoheiHagimoto | 0:0e0631af0305 | 339 | |
RyoheiHagimoto | 0:0e0631af0305 | 340 | |
RyoheiHagimoto | 0:0e0631af0305 | 341 | class CV_EXPORTS _InputOutputArray : public _OutputArray |
RyoheiHagimoto | 0:0e0631af0305 | 342 | { |
RyoheiHagimoto | 0:0e0631af0305 | 343 | public: |
RyoheiHagimoto | 0:0e0631af0305 | 344 | _InputOutputArray(); |
RyoheiHagimoto | 0:0e0631af0305 | 345 | _InputOutputArray(int _flags, void* _obj); |
RyoheiHagimoto | 0:0e0631af0305 | 346 | _InputOutputArray(Mat& m); |
RyoheiHagimoto | 0:0e0631af0305 | 347 | _InputOutputArray(std::vector<Mat>& vec); |
RyoheiHagimoto | 0:0e0631af0305 | 348 | _InputOutputArray(cuda::GpuMat& d_mat); |
RyoheiHagimoto | 0:0e0631af0305 | 349 | _InputOutputArray(ogl::Buffer& buf); |
RyoheiHagimoto | 0:0e0631af0305 | 350 | _InputOutputArray(cuda::HostMem& cuda_mem); |
RyoheiHagimoto | 0:0e0631af0305 | 351 | template<typename _Tp> _InputOutputArray(cudev::GpuMat_<_Tp>& m); |
RyoheiHagimoto | 0:0e0631af0305 | 352 | template<typename _Tp> _InputOutputArray(std::vector<_Tp>& vec); |
RyoheiHagimoto | 0:0e0631af0305 | 353 | _InputOutputArray(std::vector<bool>& vec); |
RyoheiHagimoto | 0:0e0631af0305 | 354 | template<typename _Tp> _InputOutputArray(std::vector<std::vector<_Tp> >& vec); |
RyoheiHagimoto | 0:0e0631af0305 | 355 | template<typename _Tp> _InputOutputArray(std::vector<Mat_<_Tp> >& vec); |
RyoheiHagimoto | 0:0e0631af0305 | 356 | template<typename _Tp> _InputOutputArray(Mat_<_Tp>& m); |
RyoheiHagimoto | 0:0e0631af0305 | 357 | template<typename _Tp> _InputOutputArray(_Tp* vec, int n); |
RyoheiHagimoto | 0:0e0631af0305 | 358 | template<typename _Tp, int m, int n> _InputOutputArray(Matx<_Tp, m, n>& matx); |
RyoheiHagimoto | 0:0e0631af0305 | 359 | _InputOutputArray(UMat& m); |
RyoheiHagimoto | 0:0e0631af0305 | 360 | _InputOutputArray(std::vector<UMat>& vec); |
RyoheiHagimoto | 0:0e0631af0305 | 361 | |
RyoheiHagimoto | 0:0e0631af0305 | 362 | _InputOutputArray(const Mat& m); |
RyoheiHagimoto | 0:0e0631af0305 | 363 | _InputOutputArray(const std::vector<Mat>& vec); |
RyoheiHagimoto | 0:0e0631af0305 | 364 | _InputOutputArray(const cuda::GpuMat& d_mat); |
RyoheiHagimoto | 0:0e0631af0305 | 365 | _InputOutputArray(const std::vector<cuda::GpuMat>& d_mat); |
RyoheiHagimoto | 0:0e0631af0305 | 366 | _InputOutputArray(const ogl::Buffer& buf); |
RyoheiHagimoto | 0:0e0631af0305 | 367 | _InputOutputArray(const cuda::HostMem& cuda_mem); |
RyoheiHagimoto | 0:0e0631af0305 | 368 | template<typename _Tp> _InputOutputArray(const cudev::GpuMat_<_Tp>& m); |
RyoheiHagimoto | 0:0e0631af0305 | 369 | template<typename _Tp> _InputOutputArray(const std::vector<_Tp>& vec); |
RyoheiHagimoto | 0:0e0631af0305 | 370 | template<typename _Tp> _InputOutputArray(const std::vector<std::vector<_Tp> >& vec); |
RyoheiHagimoto | 0:0e0631af0305 | 371 | template<typename _Tp> _InputOutputArray(const std::vector<Mat_<_Tp> >& vec); |
RyoheiHagimoto | 0:0e0631af0305 | 372 | template<typename _Tp> _InputOutputArray(const Mat_<_Tp>& m); |
RyoheiHagimoto | 0:0e0631af0305 | 373 | template<typename _Tp> _InputOutputArray(const _Tp* vec, int n); |
RyoheiHagimoto | 0:0e0631af0305 | 374 | template<typename _Tp, int m, int n> _InputOutputArray(const Matx<_Tp, m, n>& matx); |
RyoheiHagimoto | 0:0e0631af0305 | 375 | _InputOutputArray(const UMat& m); |
RyoheiHagimoto | 0:0e0631af0305 | 376 | _InputOutputArray(const std::vector<UMat>& vec); |
RyoheiHagimoto | 0:0e0631af0305 | 377 | }; |
RyoheiHagimoto | 0:0e0631af0305 | 378 | |
RyoheiHagimoto | 0:0e0631af0305 | 379 | typedef const _InputArray& InputArray; |
RyoheiHagimoto | 0:0e0631af0305 | 380 | typedef InputArray InputArrayOfArrays; |
RyoheiHagimoto | 0:0e0631af0305 | 381 | typedef const _OutputArray& OutputArray; |
RyoheiHagimoto | 0:0e0631af0305 | 382 | typedef OutputArray OutputArrayOfArrays; |
RyoheiHagimoto | 0:0e0631af0305 | 383 | typedef const _InputOutputArray& InputOutputArray; |
RyoheiHagimoto | 0:0e0631af0305 | 384 | typedef InputOutputArray InputOutputArrayOfArrays; |
RyoheiHagimoto | 0:0e0631af0305 | 385 | |
RyoheiHagimoto | 0:0e0631af0305 | 386 | CV_EXPORTS InputOutputArray noArray(); |
RyoheiHagimoto | 0:0e0631af0305 | 387 | |
RyoheiHagimoto | 0:0e0631af0305 | 388 | /////////////////////////////////// MatAllocator ////////////////////////////////////// |
RyoheiHagimoto | 0:0e0631af0305 | 389 | |
RyoheiHagimoto | 0:0e0631af0305 | 390 | //! Usage flags for allocator |
RyoheiHagimoto | 0:0e0631af0305 | 391 | enum UMatUsageFlags |
RyoheiHagimoto | 0:0e0631af0305 | 392 | { |
RyoheiHagimoto | 0:0e0631af0305 | 393 | USAGE_DEFAULT = 0, |
RyoheiHagimoto | 0:0e0631af0305 | 394 | |
RyoheiHagimoto | 0:0e0631af0305 | 395 | // buffer allocation policy is platform and usage specific |
RyoheiHagimoto | 0:0e0631af0305 | 396 | USAGE_ALLOCATE_HOST_MEMORY = 1 << 0, |
RyoheiHagimoto | 0:0e0631af0305 | 397 | USAGE_ALLOCATE_DEVICE_MEMORY = 1 << 1, |
RyoheiHagimoto | 0:0e0631af0305 | 398 | USAGE_ALLOCATE_SHARED_MEMORY = 1 << 2, // It is not equal to: USAGE_ALLOCATE_HOST_MEMORY | USAGE_ALLOCATE_DEVICE_MEMORY |
RyoheiHagimoto | 0:0e0631af0305 | 399 | |
RyoheiHagimoto | 0:0e0631af0305 | 400 | __UMAT_USAGE_FLAGS_32BIT = 0x7fffffff // Binary compatibility hint |
RyoheiHagimoto | 0:0e0631af0305 | 401 | }; |
RyoheiHagimoto | 0:0e0631af0305 | 402 | |
RyoheiHagimoto | 0:0e0631af0305 | 403 | struct CV_EXPORTS UMatData; |
RyoheiHagimoto | 0:0e0631af0305 | 404 | |
RyoheiHagimoto | 0:0e0631af0305 | 405 | /** @brief Custom array allocator |
RyoheiHagimoto | 0:0e0631af0305 | 406 | */ |
RyoheiHagimoto | 0:0e0631af0305 | 407 | class CV_EXPORTS MatAllocator |
RyoheiHagimoto | 0:0e0631af0305 | 408 | { |
RyoheiHagimoto | 0:0e0631af0305 | 409 | public: |
RyoheiHagimoto | 0:0e0631af0305 | 410 | MatAllocator() {} |
RyoheiHagimoto | 0:0e0631af0305 | 411 | virtual ~MatAllocator() {} |
RyoheiHagimoto | 0:0e0631af0305 | 412 | |
RyoheiHagimoto | 0:0e0631af0305 | 413 | // let's comment it off for now to detect and fix all the uses of allocator |
RyoheiHagimoto | 0:0e0631af0305 | 414 | //virtual void allocate(int dims, const int* sizes, int type, int*& refcount, |
RyoheiHagimoto | 0:0e0631af0305 | 415 | // uchar*& datastart, uchar*& data, size_t* step) = 0; |
RyoheiHagimoto | 0:0e0631af0305 | 416 | //virtual void deallocate(int* refcount, uchar* datastart, uchar* data) = 0; |
RyoheiHagimoto | 0:0e0631af0305 | 417 | virtual UMatData* allocate(int dims, const int* sizes, int type, |
RyoheiHagimoto | 0:0e0631af0305 | 418 | void* data, size_t* step, int flags, UMatUsageFlags usageFlags) const = 0; |
RyoheiHagimoto | 0:0e0631af0305 | 419 | virtual bool allocate(UMatData* data, int accessflags, UMatUsageFlags usageFlags) const = 0; |
RyoheiHagimoto | 0:0e0631af0305 | 420 | virtual void deallocate(UMatData* data) const = 0; |
RyoheiHagimoto | 0:0e0631af0305 | 421 | virtual void map(UMatData* data, int accessflags) const; |
RyoheiHagimoto | 0:0e0631af0305 | 422 | virtual void unmap(UMatData* data) const; |
RyoheiHagimoto | 0:0e0631af0305 | 423 | virtual void download(UMatData* data, void* dst, int dims, const size_t sz[], |
RyoheiHagimoto | 0:0e0631af0305 | 424 | const size_t srcofs[], const size_t srcstep[], |
RyoheiHagimoto | 0:0e0631af0305 | 425 | const size_t dststep[]) const; |
RyoheiHagimoto | 0:0e0631af0305 | 426 | virtual void upload(UMatData* data, const void* src, int dims, const size_t sz[], |
RyoheiHagimoto | 0:0e0631af0305 | 427 | const size_t dstofs[], const size_t dststep[], |
RyoheiHagimoto | 0:0e0631af0305 | 428 | const size_t srcstep[]) const; |
RyoheiHagimoto | 0:0e0631af0305 | 429 | virtual void copy(UMatData* srcdata, UMatData* dstdata, int dims, const size_t sz[], |
RyoheiHagimoto | 0:0e0631af0305 | 430 | const size_t srcofs[], const size_t srcstep[], |
RyoheiHagimoto | 0:0e0631af0305 | 431 | const size_t dstofs[], const size_t dststep[], bool sync) const; |
RyoheiHagimoto | 0:0e0631af0305 | 432 | |
RyoheiHagimoto | 0:0e0631af0305 | 433 | // default implementation returns DummyBufferPoolController |
RyoheiHagimoto | 0:0e0631af0305 | 434 | virtual BufferPoolController* getBufferPoolController(const char* id = NULL) const; |
RyoheiHagimoto | 0:0e0631af0305 | 435 | }; |
RyoheiHagimoto | 0:0e0631af0305 | 436 | |
RyoheiHagimoto | 0:0e0631af0305 | 437 | |
RyoheiHagimoto | 0:0e0631af0305 | 438 | //////////////////////////////// MatCommaInitializer ////////////////////////////////// |
RyoheiHagimoto | 0:0e0631af0305 | 439 | |
RyoheiHagimoto | 0:0e0631af0305 | 440 | /** @brief Comma-separated Matrix Initializer |
RyoheiHagimoto | 0:0e0631af0305 | 441 | |
RyoheiHagimoto | 0:0e0631af0305 | 442 | The class instances are usually not created explicitly. |
RyoheiHagimoto | 0:0e0631af0305 | 443 | Instead, they are created on "matrix << firstValue" operator. |
RyoheiHagimoto | 0:0e0631af0305 | 444 | |
RyoheiHagimoto | 0:0e0631af0305 | 445 | The sample below initializes 2x2 rotation matrix: |
RyoheiHagimoto | 0:0e0631af0305 | 446 | |
RyoheiHagimoto | 0:0e0631af0305 | 447 | \code |
RyoheiHagimoto | 0:0e0631af0305 | 448 | double angle = 30, a = cos(angle*CV_PI/180), b = sin(angle*CV_PI/180); |
RyoheiHagimoto | 0:0e0631af0305 | 449 | Mat R = (Mat_<double>(2,2) << a, -b, b, a); |
RyoheiHagimoto | 0:0e0631af0305 | 450 | \endcode |
RyoheiHagimoto | 0:0e0631af0305 | 451 | */ |
RyoheiHagimoto | 0:0e0631af0305 | 452 | template<typename _Tp> class MatCommaInitializer_ |
RyoheiHagimoto | 0:0e0631af0305 | 453 | { |
RyoheiHagimoto | 0:0e0631af0305 | 454 | public: |
RyoheiHagimoto | 0:0e0631af0305 | 455 | //! the constructor, created by "matrix << firstValue" operator, where matrix is cv::Mat |
RyoheiHagimoto | 0:0e0631af0305 | 456 | MatCommaInitializer_(Mat_<_Tp>* _m); |
RyoheiHagimoto | 0:0e0631af0305 | 457 | //! the operator that takes the next value and put it to the matrix |
RyoheiHagimoto | 0:0e0631af0305 | 458 | template<typename T2> MatCommaInitializer_<_Tp>& operator , (T2 v); |
RyoheiHagimoto | 0:0e0631af0305 | 459 | //! another form of conversion operator |
RyoheiHagimoto | 0:0e0631af0305 | 460 | operator Mat_<_Tp>() const; |
RyoheiHagimoto | 0:0e0631af0305 | 461 | protected: |
RyoheiHagimoto | 0:0e0631af0305 | 462 | MatIterator_<_Tp> it; |
RyoheiHagimoto | 0:0e0631af0305 | 463 | }; |
RyoheiHagimoto | 0:0e0631af0305 | 464 | |
RyoheiHagimoto | 0:0e0631af0305 | 465 | |
RyoheiHagimoto | 0:0e0631af0305 | 466 | /////////////////////////////////////// Mat /////////////////////////////////////////// |
RyoheiHagimoto | 0:0e0631af0305 | 467 | |
RyoheiHagimoto | 0:0e0631af0305 | 468 | // note that umatdata might be allocated together |
RyoheiHagimoto | 0:0e0631af0305 | 469 | // with the matrix data, not as a separate object. |
RyoheiHagimoto | 0:0e0631af0305 | 470 | // therefore, it does not have constructor or destructor; |
RyoheiHagimoto | 0:0e0631af0305 | 471 | // it should be explicitly initialized using init(). |
RyoheiHagimoto | 0:0e0631af0305 | 472 | struct CV_EXPORTS UMatData |
RyoheiHagimoto | 0:0e0631af0305 | 473 | { |
RyoheiHagimoto | 0:0e0631af0305 | 474 | enum { COPY_ON_MAP=1, HOST_COPY_OBSOLETE=2, |
RyoheiHagimoto | 0:0e0631af0305 | 475 | DEVICE_COPY_OBSOLETE=4, TEMP_UMAT=8, TEMP_COPIED_UMAT=24, |
RyoheiHagimoto | 0:0e0631af0305 | 476 | USER_ALLOCATED=32, DEVICE_MEM_MAPPED=64}; |
RyoheiHagimoto | 0:0e0631af0305 | 477 | UMatData(const MatAllocator* allocator); |
RyoheiHagimoto | 0:0e0631af0305 | 478 | ~UMatData(); |
RyoheiHagimoto | 0:0e0631af0305 | 479 | |
RyoheiHagimoto | 0:0e0631af0305 | 480 | // provide atomic access to the structure |
RyoheiHagimoto | 0:0e0631af0305 | 481 | void lock(); |
RyoheiHagimoto | 0:0e0631af0305 | 482 | void unlock(); |
RyoheiHagimoto | 0:0e0631af0305 | 483 | |
RyoheiHagimoto | 0:0e0631af0305 | 484 | bool hostCopyObsolete() const; |
RyoheiHagimoto | 0:0e0631af0305 | 485 | bool deviceCopyObsolete() const; |
RyoheiHagimoto | 0:0e0631af0305 | 486 | bool deviceMemMapped() const; |
RyoheiHagimoto | 0:0e0631af0305 | 487 | bool copyOnMap() const; |
RyoheiHagimoto | 0:0e0631af0305 | 488 | bool tempUMat() const; |
RyoheiHagimoto | 0:0e0631af0305 | 489 | bool tempCopiedUMat() const; |
RyoheiHagimoto | 0:0e0631af0305 | 490 | void markHostCopyObsolete(bool flag); |
RyoheiHagimoto | 0:0e0631af0305 | 491 | void markDeviceCopyObsolete(bool flag); |
RyoheiHagimoto | 0:0e0631af0305 | 492 | void markDeviceMemMapped(bool flag); |
RyoheiHagimoto | 0:0e0631af0305 | 493 | |
RyoheiHagimoto | 0:0e0631af0305 | 494 | const MatAllocator* prevAllocator; |
RyoheiHagimoto | 0:0e0631af0305 | 495 | const MatAllocator* currAllocator; |
RyoheiHagimoto | 0:0e0631af0305 | 496 | int urefcount; |
RyoheiHagimoto | 0:0e0631af0305 | 497 | int refcount; |
RyoheiHagimoto | 0:0e0631af0305 | 498 | uchar* data; |
RyoheiHagimoto | 0:0e0631af0305 | 499 | uchar* origdata; |
RyoheiHagimoto | 0:0e0631af0305 | 500 | size_t size; |
RyoheiHagimoto | 0:0e0631af0305 | 501 | |
RyoheiHagimoto | 0:0e0631af0305 | 502 | int flags; |
RyoheiHagimoto | 0:0e0631af0305 | 503 | void* handle; |
RyoheiHagimoto | 0:0e0631af0305 | 504 | void* userdata; |
RyoheiHagimoto | 0:0e0631af0305 | 505 | int allocatorFlags_; |
RyoheiHagimoto | 0:0e0631af0305 | 506 | int mapcount; |
RyoheiHagimoto | 0:0e0631af0305 | 507 | UMatData* originalUMatData; |
RyoheiHagimoto | 0:0e0631af0305 | 508 | }; |
RyoheiHagimoto | 0:0e0631af0305 | 509 | |
RyoheiHagimoto | 0:0e0631af0305 | 510 | |
RyoheiHagimoto | 0:0e0631af0305 | 511 | struct CV_EXPORTS UMatDataAutoLock |
RyoheiHagimoto | 0:0e0631af0305 | 512 | { |
RyoheiHagimoto | 0:0e0631af0305 | 513 | explicit UMatDataAutoLock(UMatData* u); |
RyoheiHagimoto | 0:0e0631af0305 | 514 | ~UMatDataAutoLock(); |
RyoheiHagimoto | 0:0e0631af0305 | 515 | UMatData* u; |
RyoheiHagimoto | 0:0e0631af0305 | 516 | }; |
RyoheiHagimoto | 0:0e0631af0305 | 517 | |
RyoheiHagimoto | 0:0e0631af0305 | 518 | |
RyoheiHagimoto | 0:0e0631af0305 | 519 | struct CV_EXPORTS MatSize |
RyoheiHagimoto | 0:0e0631af0305 | 520 | { |
RyoheiHagimoto | 0:0e0631af0305 | 521 | explicit MatSize(int* _p); |
RyoheiHagimoto | 0:0e0631af0305 | 522 | Size operator()() const; |
RyoheiHagimoto | 0:0e0631af0305 | 523 | const int& operator[](int i) const; |
RyoheiHagimoto | 0:0e0631af0305 | 524 | int& operator[](int i); |
RyoheiHagimoto | 0:0e0631af0305 | 525 | operator const int*() const; |
RyoheiHagimoto | 0:0e0631af0305 | 526 | bool operator == (const MatSize& sz) const; |
RyoheiHagimoto | 0:0e0631af0305 | 527 | bool operator != (const MatSize& sz) const; |
RyoheiHagimoto | 0:0e0631af0305 | 528 | |
RyoheiHagimoto | 0:0e0631af0305 | 529 | int* p; |
RyoheiHagimoto | 0:0e0631af0305 | 530 | }; |
RyoheiHagimoto | 0:0e0631af0305 | 531 | |
RyoheiHagimoto | 0:0e0631af0305 | 532 | struct CV_EXPORTS MatStep |
RyoheiHagimoto | 0:0e0631af0305 | 533 | { |
RyoheiHagimoto | 0:0e0631af0305 | 534 | MatStep(); |
RyoheiHagimoto | 0:0e0631af0305 | 535 | explicit MatStep(size_t s); |
RyoheiHagimoto | 0:0e0631af0305 | 536 | const size_t& operator[](int i) const; |
RyoheiHagimoto | 0:0e0631af0305 | 537 | size_t& operator[](int i); |
RyoheiHagimoto | 0:0e0631af0305 | 538 | operator size_t() const; |
RyoheiHagimoto | 0:0e0631af0305 | 539 | MatStep& operator = (size_t s); |
RyoheiHagimoto | 0:0e0631af0305 | 540 | |
RyoheiHagimoto | 0:0e0631af0305 | 541 | size_t* p; |
RyoheiHagimoto | 0:0e0631af0305 | 542 | size_t buf[2]; |
RyoheiHagimoto | 0:0e0631af0305 | 543 | protected: |
RyoheiHagimoto | 0:0e0631af0305 | 544 | MatStep& operator = (const MatStep&); |
RyoheiHagimoto | 0:0e0631af0305 | 545 | }; |
RyoheiHagimoto | 0:0e0631af0305 | 546 | |
RyoheiHagimoto | 0:0e0631af0305 | 547 | /** @example cout_mat.cpp |
RyoheiHagimoto | 0:0e0631af0305 | 548 | An example demonstrating the serial out capabilities of cv::Mat |
RyoheiHagimoto | 0:0e0631af0305 | 549 | */ |
RyoheiHagimoto | 0:0e0631af0305 | 550 | |
RyoheiHagimoto | 0:0e0631af0305 | 551 | /** @brief n-dimensional dense array class |
RyoheiHagimoto | 0:0e0631af0305 | 552 | |
RyoheiHagimoto | 0:0e0631af0305 | 553 | The class Mat represents an n-dimensional dense numerical single-channel or multi-channel array. It |
RyoheiHagimoto | 0:0e0631af0305 | 554 | can be used to store real or complex-valued vectors and matrices, grayscale or color images, voxel |
RyoheiHagimoto | 0:0e0631af0305 | 555 | volumes, vector fields, point clouds, tensors, histograms (though, very high-dimensional histograms |
RyoheiHagimoto | 0:0e0631af0305 | 556 | may be better stored in a SparseMat ). The data layout of the array `M` is defined by the array |
RyoheiHagimoto | 0:0e0631af0305 | 557 | `M.step[]`, so that the address of element \f$(i_0,...,i_{M.dims-1})\f$, where \f$0\leq i_k<M.size[k]\f$, is |
RyoheiHagimoto | 0:0e0631af0305 | 558 | computed as: |
RyoheiHagimoto | 0:0e0631af0305 | 559 | \f[addr(M_{i_0,...,i_{M.dims-1}}) = M.data + M.step[0]*i_0 + M.step[1]*i_1 + ... + M.step[M.dims-1]*i_{M.dims-1}\f] |
RyoheiHagimoto | 0:0e0631af0305 | 560 | In case of a 2-dimensional array, the above formula is reduced to: |
RyoheiHagimoto | 0:0e0631af0305 | 561 | \f[addr(M_{i,j}) = M.data + M.step[0]*i + M.step[1]*j\f] |
RyoheiHagimoto | 0:0e0631af0305 | 562 | Note that `M.step[i] >= M.step[i+1]` (in fact, `M.step[i] >= M.step[i+1]*M.size[i+1]` ). This means |
RyoheiHagimoto | 0:0e0631af0305 | 563 | that 2-dimensional matrices are stored row-by-row, 3-dimensional matrices are stored plane-by-plane, |
RyoheiHagimoto | 0:0e0631af0305 | 564 | and so on. M.step[M.dims-1] is minimal and always equal to the element size M.elemSize() . |
RyoheiHagimoto | 0:0e0631af0305 | 565 | |
RyoheiHagimoto | 0:0e0631af0305 | 566 | So, the data layout in Mat is fully compatible with CvMat, IplImage, and CvMatND types from OpenCV |
RyoheiHagimoto | 0:0e0631af0305 | 567 | 1.x. It is also compatible with the majority of dense array types from the standard toolkits and |
RyoheiHagimoto | 0:0e0631af0305 | 568 | SDKs, such as Numpy (ndarray), Win32 (independent device bitmaps), and others, that is, with any |
RyoheiHagimoto | 0:0e0631af0305 | 569 | array that uses *steps* (or *strides*) to compute the position of a pixel. Due to this |
RyoheiHagimoto | 0:0e0631af0305 | 570 | compatibility, it is possible to make a Mat header for user-allocated data and process it in-place |
RyoheiHagimoto | 0:0e0631af0305 | 571 | using OpenCV functions. |
RyoheiHagimoto | 0:0e0631af0305 | 572 | |
RyoheiHagimoto | 0:0e0631af0305 | 573 | There are many different ways to create a Mat object. The most popular options are listed below: |
RyoheiHagimoto | 0:0e0631af0305 | 574 | |
RyoheiHagimoto | 0:0e0631af0305 | 575 | - Use the create(nrows, ncols, type) method or the similar Mat(nrows, ncols, type[, fillValue]) |
RyoheiHagimoto | 0:0e0631af0305 | 576 | constructor. A new array of the specified size and type is allocated. type has the same meaning as |
RyoheiHagimoto | 0:0e0631af0305 | 577 | in the cvCreateMat method. For example, CV_8UC1 means a 8-bit single-channel array, CV_32FC2 |
RyoheiHagimoto | 0:0e0631af0305 | 578 | means a 2-channel (complex) floating-point array, and so on. |
RyoheiHagimoto | 0:0e0631af0305 | 579 | @code |
RyoheiHagimoto | 0:0e0631af0305 | 580 | // make a 7x7 complex matrix filled with 1+3j. |
RyoheiHagimoto | 0:0e0631af0305 | 581 | Mat M(7,7,CV_32FC2,Scalar(1,3)); |
RyoheiHagimoto | 0:0e0631af0305 | 582 | // and now turn M to a 100x60 15-channel 8-bit matrix. |
RyoheiHagimoto | 0:0e0631af0305 | 583 | // The old content will be deallocated |
RyoheiHagimoto | 0:0e0631af0305 | 584 | M.create(100,60,CV_8UC(15)); |
RyoheiHagimoto | 0:0e0631af0305 | 585 | @endcode |
RyoheiHagimoto | 0:0e0631af0305 | 586 | As noted in the introduction to this chapter, create() allocates only a new array when the shape |
RyoheiHagimoto | 0:0e0631af0305 | 587 | or type of the current array are different from the specified ones. |
RyoheiHagimoto | 0:0e0631af0305 | 588 | |
RyoheiHagimoto | 0:0e0631af0305 | 589 | - Create a multi-dimensional array: |
RyoheiHagimoto | 0:0e0631af0305 | 590 | @code |
RyoheiHagimoto | 0:0e0631af0305 | 591 | // create a 100x100x100 8-bit array |
RyoheiHagimoto | 0:0e0631af0305 | 592 | int sz[] = {100, 100, 100}; |
RyoheiHagimoto | 0:0e0631af0305 | 593 | Mat bigCube(3, sz, CV_8U, Scalar::all(0)); |
RyoheiHagimoto | 0:0e0631af0305 | 594 | @endcode |
RyoheiHagimoto | 0:0e0631af0305 | 595 | It passes the number of dimensions =1 to the Mat constructor but the created array will be |
RyoheiHagimoto | 0:0e0631af0305 | 596 | 2-dimensional with the number of columns set to 1. So, Mat::dims is always \>= 2 (can also be 0 |
RyoheiHagimoto | 0:0e0631af0305 | 597 | when the array is empty). |
RyoheiHagimoto | 0:0e0631af0305 | 598 | |
RyoheiHagimoto | 0:0e0631af0305 | 599 | - Use a copy constructor or assignment operator where there can be an array or expression on the |
RyoheiHagimoto | 0:0e0631af0305 | 600 | right side (see below). As noted in the introduction, the array assignment is an O(1) operation |
RyoheiHagimoto | 0:0e0631af0305 | 601 | because it only copies the header and increases the reference counter. The Mat::clone() method can |
RyoheiHagimoto | 0:0e0631af0305 | 602 | be used to get a full (deep) copy of the array when you need it. |
RyoheiHagimoto | 0:0e0631af0305 | 603 | |
RyoheiHagimoto | 0:0e0631af0305 | 604 | - Construct a header for a part of another array. It can be a single row, single column, several |
RyoheiHagimoto | 0:0e0631af0305 | 605 | rows, several columns, rectangular region in the array (called a *minor* in algebra) or a |
RyoheiHagimoto | 0:0e0631af0305 | 606 | diagonal. Such operations are also O(1) because the new header references the same data. You can |
RyoheiHagimoto | 0:0e0631af0305 | 607 | actually modify a part of the array using this feature, for example: |
RyoheiHagimoto | 0:0e0631af0305 | 608 | @code |
RyoheiHagimoto | 0:0e0631af0305 | 609 | // add the 5-th row, multiplied by 3 to the 3rd row |
RyoheiHagimoto | 0:0e0631af0305 | 610 | M.row(3) = M.row(3) + M.row(5)*3; |
RyoheiHagimoto | 0:0e0631af0305 | 611 | // now copy the 7-th column to the 1-st column |
RyoheiHagimoto | 0:0e0631af0305 | 612 | // M.col(1) = M.col(7); // this will not work |
RyoheiHagimoto | 0:0e0631af0305 | 613 | Mat M1 = M.col(1); |
RyoheiHagimoto | 0:0e0631af0305 | 614 | M.col(7).copyTo(M1); |
RyoheiHagimoto | 0:0e0631af0305 | 615 | // create a new 320x240 image |
RyoheiHagimoto | 0:0e0631af0305 | 616 | Mat img(Size(320,240),CV_8UC3); |
RyoheiHagimoto | 0:0e0631af0305 | 617 | // select a ROI |
RyoheiHagimoto | 0:0e0631af0305 | 618 | Mat roi(img, Rect(10,10,100,100)); |
RyoheiHagimoto | 0:0e0631af0305 | 619 | // fill the ROI with (0,255,0) (which is green in RGB space); |
RyoheiHagimoto | 0:0e0631af0305 | 620 | // the original 320x240 image will be modified |
RyoheiHagimoto | 0:0e0631af0305 | 621 | roi = Scalar(0,255,0); |
RyoheiHagimoto | 0:0e0631af0305 | 622 | @endcode |
RyoheiHagimoto | 0:0e0631af0305 | 623 | Due to the additional datastart and dataend members, it is possible to compute a relative |
RyoheiHagimoto | 0:0e0631af0305 | 624 | sub-array position in the main *container* array using locateROI(): |
RyoheiHagimoto | 0:0e0631af0305 | 625 | @code |
RyoheiHagimoto | 0:0e0631af0305 | 626 | Mat A = Mat::eye(10, 10, CV_32S); |
RyoheiHagimoto | 0:0e0631af0305 | 627 | // extracts A columns, 1 (inclusive) to 3 (exclusive). |
RyoheiHagimoto | 0:0e0631af0305 | 628 | Mat B = A(Range::all(), Range(1, 3)); |
RyoheiHagimoto | 0:0e0631af0305 | 629 | // extracts B rows, 5 (inclusive) to 9 (exclusive). |
RyoheiHagimoto | 0:0e0631af0305 | 630 | // that is, C \~ A(Range(5, 9), Range(1, 3)) |
RyoheiHagimoto | 0:0e0631af0305 | 631 | Mat C = B(Range(5, 9), Range::all()); |
RyoheiHagimoto | 0:0e0631af0305 | 632 | Size size; Point ofs; |
RyoheiHagimoto | 0:0e0631af0305 | 633 | C.locateROI(size, ofs); |
RyoheiHagimoto | 0:0e0631af0305 | 634 | // size will be (width=10,height=10) and the ofs will be (x=1, y=5) |
RyoheiHagimoto | 0:0e0631af0305 | 635 | @endcode |
RyoheiHagimoto | 0:0e0631af0305 | 636 | As in case of whole matrices, if you need a deep copy, use the `clone()` method of the extracted |
RyoheiHagimoto | 0:0e0631af0305 | 637 | sub-matrices. |
RyoheiHagimoto | 0:0e0631af0305 | 638 | |
RyoheiHagimoto | 0:0e0631af0305 | 639 | - Make a header for user-allocated data. It can be useful to do the following: |
RyoheiHagimoto | 0:0e0631af0305 | 640 | -# Process "foreign" data using OpenCV (for example, when you implement a DirectShow\* filter or |
RyoheiHagimoto | 0:0e0631af0305 | 641 | a processing module for gstreamer, and so on). For example: |
RyoheiHagimoto | 0:0e0631af0305 | 642 | @code |
RyoheiHagimoto | 0:0e0631af0305 | 643 | void process_video_frame(const unsigned char* pixels, |
RyoheiHagimoto | 0:0e0631af0305 | 644 | int width, int height, int step) |
RyoheiHagimoto | 0:0e0631af0305 | 645 | { |
RyoheiHagimoto | 0:0e0631af0305 | 646 | Mat img(height, width, CV_8UC3, pixels, step); |
RyoheiHagimoto | 0:0e0631af0305 | 647 | GaussianBlur(img, img, Size(7,7), 1.5, 1.5); |
RyoheiHagimoto | 0:0e0631af0305 | 648 | } |
RyoheiHagimoto | 0:0e0631af0305 | 649 | @endcode |
RyoheiHagimoto | 0:0e0631af0305 | 650 | -# Quickly initialize small matrices and/or get a super-fast element access. |
RyoheiHagimoto | 0:0e0631af0305 | 651 | @code |
RyoheiHagimoto | 0:0e0631af0305 | 652 | double m[3][3] = {{a, b, c}, {d, e, f}, {g, h, i}}; |
RyoheiHagimoto | 0:0e0631af0305 | 653 | Mat M = Mat(3, 3, CV_64F, m).inv(); |
RyoheiHagimoto | 0:0e0631af0305 | 654 | @endcode |
RyoheiHagimoto | 0:0e0631af0305 | 655 | . |
RyoheiHagimoto | 0:0e0631af0305 | 656 | Partial yet very common cases of this *user-allocated data* case are conversions from CvMat and |
RyoheiHagimoto | 0:0e0631af0305 | 657 | IplImage to Mat. For this purpose, there is function cv::cvarrToMat taking pointers to CvMat or |
RyoheiHagimoto | 0:0e0631af0305 | 658 | IplImage and the optional flag indicating whether to copy the data or not. |
RyoheiHagimoto | 0:0e0631af0305 | 659 | @snippet samples/cpp/image.cpp iplimage |
RyoheiHagimoto | 0:0e0631af0305 | 660 | |
RyoheiHagimoto | 0:0e0631af0305 | 661 | - Use MATLAB-style array initializers, zeros(), ones(), eye(), for example: |
RyoheiHagimoto | 0:0e0631af0305 | 662 | @code |
RyoheiHagimoto | 0:0e0631af0305 | 663 | // create a double-precision identity martix and add it to M. |
RyoheiHagimoto | 0:0e0631af0305 | 664 | M += Mat::eye(M.rows, M.cols, CV_64F); |
RyoheiHagimoto | 0:0e0631af0305 | 665 | @endcode |
RyoheiHagimoto | 0:0e0631af0305 | 666 | |
RyoheiHagimoto | 0:0e0631af0305 | 667 | - Use a comma-separated initializer: |
RyoheiHagimoto | 0:0e0631af0305 | 668 | @code |
RyoheiHagimoto | 0:0e0631af0305 | 669 | // create a 3x3 double-precision identity matrix |
RyoheiHagimoto | 0:0e0631af0305 | 670 | Mat M = (Mat_<double>(3,3) << 1, 0, 0, 0, 1, 0, 0, 0, 1); |
RyoheiHagimoto | 0:0e0631af0305 | 671 | @endcode |
RyoheiHagimoto | 0:0e0631af0305 | 672 | With this approach, you first call a constructor of the Mat class with the proper parameters, and |
RyoheiHagimoto | 0:0e0631af0305 | 673 | then you just put `<< operator` followed by comma-separated values that can be constants, |
RyoheiHagimoto | 0:0e0631af0305 | 674 | variables, expressions, and so on. Also, note the extra parentheses required to avoid compilation |
RyoheiHagimoto | 0:0e0631af0305 | 675 | errors. |
RyoheiHagimoto | 0:0e0631af0305 | 676 | |
RyoheiHagimoto | 0:0e0631af0305 | 677 | Once the array is created, it is automatically managed via a reference-counting mechanism. If the |
RyoheiHagimoto | 0:0e0631af0305 | 678 | array header is built on top of user-allocated data, you should handle the data by yourself. The |
RyoheiHagimoto | 0:0e0631af0305 | 679 | array data is deallocated when no one points to it. If you want to release the data pointed by a |
RyoheiHagimoto | 0:0e0631af0305 | 680 | array header before the array destructor is called, use Mat::release(). |
RyoheiHagimoto | 0:0e0631af0305 | 681 | |
RyoheiHagimoto | 0:0e0631af0305 | 682 | The next important thing to learn about the array class is element access. This manual already |
RyoheiHagimoto | 0:0e0631af0305 | 683 | described how to compute an address of each array element. Normally, you are not required to use the |
RyoheiHagimoto | 0:0e0631af0305 | 684 | formula directly in the code. If you know the array element type (which can be retrieved using the |
RyoheiHagimoto | 0:0e0631af0305 | 685 | method Mat::type() ), you can access the element \f$M_{ij}\f$ of a 2-dimensional array as: |
RyoheiHagimoto | 0:0e0631af0305 | 686 | @code |
RyoheiHagimoto | 0:0e0631af0305 | 687 | M.at<double>(i,j) += 1.f; |
RyoheiHagimoto | 0:0e0631af0305 | 688 | @endcode |
RyoheiHagimoto | 0:0e0631af0305 | 689 | assuming that `M` is a double-precision floating-point array. There are several variants of the method |
RyoheiHagimoto | 0:0e0631af0305 | 690 | at for a different number of dimensions. |
RyoheiHagimoto | 0:0e0631af0305 | 691 | |
RyoheiHagimoto | 0:0e0631af0305 | 692 | If you need to process a whole row of a 2D array, the most efficient way is to get the pointer to |
RyoheiHagimoto | 0:0e0631af0305 | 693 | the row first, and then just use the plain C operator [] : |
RyoheiHagimoto | 0:0e0631af0305 | 694 | @code |
RyoheiHagimoto | 0:0e0631af0305 | 695 | // compute sum of positive matrix elements |
RyoheiHagimoto | 0:0e0631af0305 | 696 | // (assuming that M isa double-precision matrix) |
RyoheiHagimoto | 0:0e0631af0305 | 697 | double sum=0; |
RyoheiHagimoto | 0:0e0631af0305 | 698 | for(int i = 0; i < M.rows; i++) |
RyoheiHagimoto | 0:0e0631af0305 | 699 | { |
RyoheiHagimoto | 0:0e0631af0305 | 700 | const double* Mi = M.ptr<double>(i); |
RyoheiHagimoto | 0:0e0631af0305 | 701 | for(int j = 0; j < M.cols; j++) |
RyoheiHagimoto | 0:0e0631af0305 | 702 | sum += std::max(Mi[j], 0.); |
RyoheiHagimoto | 0:0e0631af0305 | 703 | } |
RyoheiHagimoto | 0:0e0631af0305 | 704 | @endcode |
RyoheiHagimoto | 0:0e0631af0305 | 705 | Some operations, like the one above, do not actually depend on the array shape. They just process |
RyoheiHagimoto | 0:0e0631af0305 | 706 | elements of an array one by one (or elements from multiple arrays that have the same coordinates, |
RyoheiHagimoto | 0:0e0631af0305 | 707 | for example, array addition). Such operations are called *element-wise*. It makes sense to check |
RyoheiHagimoto | 0:0e0631af0305 | 708 | whether all the input/output arrays are continuous, namely, have no gaps at the end of each row. If |
RyoheiHagimoto | 0:0e0631af0305 | 709 | yes, process them as a long single row: |
RyoheiHagimoto | 0:0e0631af0305 | 710 | @code |
RyoheiHagimoto | 0:0e0631af0305 | 711 | // compute the sum of positive matrix elements, optimized variant |
RyoheiHagimoto | 0:0e0631af0305 | 712 | double sum=0; |
RyoheiHagimoto | 0:0e0631af0305 | 713 | int cols = M.cols, rows = M.rows; |
RyoheiHagimoto | 0:0e0631af0305 | 714 | if(M.isContinuous()) |
RyoheiHagimoto | 0:0e0631af0305 | 715 | { |
RyoheiHagimoto | 0:0e0631af0305 | 716 | cols *= rows; |
RyoheiHagimoto | 0:0e0631af0305 | 717 | rows = 1; |
RyoheiHagimoto | 0:0e0631af0305 | 718 | } |
RyoheiHagimoto | 0:0e0631af0305 | 719 | for(int i = 0; i < rows; i++) |
RyoheiHagimoto | 0:0e0631af0305 | 720 | { |
RyoheiHagimoto | 0:0e0631af0305 | 721 | const double* Mi = M.ptr<double>(i); |
RyoheiHagimoto | 0:0e0631af0305 | 722 | for(int j = 0; j < cols; j++) |
RyoheiHagimoto | 0:0e0631af0305 | 723 | sum += std::max(Mi[j], 0.); |
RyoheiHagimoto | 0:0e0631af0305 | 724 | } |
RyoheiHagimoto | 0:0e0631af0305 | 725 | @endcode |
RyoheiHagimoto | 0:0e0631af0305 | 726 | In case of the continuous matrix, the outer loop body is executed just once. So, the overhead is |
RyoheiHagimoto | 0:0e0631af0305 | 727 | smaller, which is especially noticeable in case of small matrices. |
RyoheiHagimoto | 0:0e0631af0305 | 728 | |
RyoheiHagimoto | 0:0e0631af0305 | 729 | Finally, there are STL-style iterators that are smart enough to skip gaps between successive rows: |
RyoheiHagimoto | 0:0e0631af0305 | 730 | @code |
RyoheiHagimoto | 0:0e0631af0305 | 731 | // compute sum of positive matrix elements, iterator-based variant |
RyoheiHagimoto | 0:0e0631af0305 | 732 | double sum=0; |
RyoheiHagimoto | 0:0e0631af0305 | 733 | MatConstIterator_<double> it = M.begin<double>(), it_end = M.end<double>(); |
RyoheiHagimoto | 0:0e0631af0305 | 734 | for(; it != it_end; ++it) |
RyoheiHagimoto | 0:0e0631af0305 | 735 | sum += std::max(*it, 0.); |
RyoheiHagimoto | 0:0e0631af0305 | 736 | @endcode |
RyoheiHagimoto | 0:0e0631af0305 | 737 | The matrix iterators are random-access iterators, so they can be passed to any STL algorithm, |
RyoheiHagimoto | 0:0e0631af0305 | 738 | including std::sort(). |
RyoheiHagimoto | 0:0e0631af0305 | 739 | */ |
RyoheiHagimoto | 0:0e0631af0305 | 740 | class CV_EXPORTS Mat |
RyoheiHagimoto | 0:0e0631af0305 | 741 | { |
RyoheiHagimoto | 0:0e0631af0305 | 742 | public: |
RyoheiHagimoto | 0:0e0631af0305 | 743 | /** |
RyoheiHagimoto | 0:0e0631af0305 | 744 | These are various constructors that form a matrix. As noted in the AutomaticAllocation, often |
RyoheiHagimoto | 0:0e0631af0305 | 745 | the default constructor is enough, and the proper matrix will be allocated by an OpenCV function. |
RyoheiHagimoto | 0:0e0631af0305 | 746 | The constructed matrix can further be assigned to another matrix or matrix expression or can be |
RyoheiHagimoto | 0:0e0631af0305 | 747 | allocated with Mat::create . In the former case, the old content is de-referenced. |
RyoheiHagimoto | 0:0e0631af0305 | 748 | */ |
RyoheiHagimoto | 0:0e0631af0305 | 749 | Mat(); |
RyoheiHagimoto | 0:0e0631af0305 | 750 | |
RyoheiHagimoto | 0:0e0631af0305 | 751 | /** @overload |
RyoheiHagimoto | 0:0e0631af0305 | 752 | @param rows Number of rows in a 2D array. |
RyoheiHagimoto | 0:0e0631af0305 | 753 | @param cols Number of columns in a 2D array. |
RyoheiHagimoto | 0:0e0631af0305 | 754 | @param type Array type. Use CV_8UC1, ..., CV_64FC4 to create 1-4 channel matrices, or |
RyoheiHagimoto | 0:0e0631af0305 | 755 | CV_8UC(n), ..., CV_64FC(n) to create multi-channel (up to CV_CN_MAX channels) matrices. |
RyoheiHagimoto | 0:0e0631af0305 | 756 | */ |
RyoheiHagimoto | 0:0e0631af0305 | 757 | Mat(int rows, int cols, int type); |
RyoheiHagimoto | 0:0e0631af0305 | 758 | |
RyoheiHagimoto | 0:0e0631af0305 | 759 | /** @overload |
RyoheiHagimoto | 0:0e0631af0305 | 760 | @param size 2D array size: Size(cols, rows) . In the Size() constructor, the number of rows and the |
RyoheiHagimoto | 0:0e0631af0305 | 761 | number of columns go in the reverse order. |
RyoheiHagimoto | 0:0e0631af0305 | 762 | @param type Array type. Use CV_8UC1, ..., CV_64FC4 to create 1-4 channel matrices, or |
RyoheiHagimoto | 0:0e0631af0305 | 763 | CV_8UC(n), ..., CV_64FC(n) to create multi-channel (up to CV_CN_MAX channels) matrices. |
RyoheiHagimoto | 0:0e0631af0305 | 764 | */ |
RyoheiHagimoto | 0:0e0631af0305 | 765 | Mat(Size size, int type); |
RyoheiHagimoto | 0:0e0631af0305 | 766 | |
RyoheiHagimoto | 0:0e0631af0305 | 767 | /** @overload |
RyoheiHagimoto | 0:0e0631af0305 | 768 | @param rows Number of rows in a 2D array. |
RyoheiHagimoto | 0:0e0631af0305 | 769 | @param cols Number of columns in a 2D array. |
RyoheiHagimoto | 0:0e0631af0305 | 770 | @param type Array type. Use CV_8UC1, ..., CV_64FC4 to create 1-4 channel matrices, or |
RyoheiHagimoto | 0:0e0631af0305 | 771 | CV_8UC(n), ..., CV_64FC(n) to create multi-channel (up to CV_CN_MAX channels) matrices. |
RyoheiHagimoto | 0:0e0631af0305 | 772 | @param s An optional value to initialize each matrix element with. To set all the matrix elements to |
RyoheiHagimoto | 0:0e0631af0305 | 773 | the particular value after the construction, use the assignment operator |
RyoheiHagimoto | 0:0e0631af0305 | 774 | Mat::operator=(const Scalar& value) . |
RyoheiHagimoto | 0:0e0631af0305 | 775 | */ |
RyoheiHagimoto | 0:0e0631af0305 | 776 | Mat(int rows, int cols, int type, const Scalar& s); |
RyoheiHagimoto | 0:0e0631af0305 | 777 | |
RyoheiHagimoto | 0:0e0631af0305 | 778 | /** @overload |
RyoheiHagimoto | 0:0e0631af0305 | 779 | @param size 2D array size: Size(cols, rows) . In the Size() constructor, the number of rows and the |
RyoheiHagimoto | 0:0e0631af0305 | 780 | number of columns go in the reverse order. |
RyoheiHagimoto | 0:0e0631af0305 | 781 | @param type Array type. Use CV_8UC1, ..., CV_64FC4 to create 1-4 channel matrices, or |
RyoheiHagimoto | 0:0e0631af0305 | 782 | CV_8UC(n), ..., CV_64FC(n) to create multi-channel (up to CV_CN_MAX channels) matrices. |
RyoheiHagimoto | 0:0e0631af0305 | 783 | @param s An optional value to initialize each matrix element with. To set all the matrix elements to |
RyoheiHagimoto | 0:0e0631af0305 | 784 | the particular value after the construction, use the assignment operator |
RyoheiHagimoto | 0:0e0631af0305 | 785 | Mat::operator=(const Scalar& value) . |
RyoheiHagimoto | 0:0e0631af0305 | 786 | */ |
RyoheiHagimoto | 0:0e0631af0305 | 787 | Mat(Size size, int type, const Scalar& s); |
RyoheiHagimoto | 0:0e0631af0305 | 788 | |
RyoheiHagimoto | 0:0e0631af0305 | 789 | /** @overload |
RyoheiHagimoto | 0:0e0631af0305 | 790 | @param ndims Array dimensionality. |
RyoheiHagimoto | 0:0e0631af0305 | 791 | @param sizes Array of integers specifying an n-dimensional array shape. |
RyoheiHagimoto | 0:0e0631af0305 | 792 | @param type Array type. Use CV_8UC1, ..., CV_64FC4 to create 1-4 channel matrices, or |
RyoheiHagimoto | 0:0e0631af0305 | 793 | CV_8UC(n), ..., CV_64FC(n) to create multi-channel (up to CV_CN_MAX channels) matrices. |
RyoheiHagimoto | 0:0e0631af0305 | 794 | */ |
RyoheiHagimoto | 0:0e0631af0305 | 795 | Mat(int ndims, const int* sizes, int type); |
RyoheiHagimoto | 0:0e0631af0305 | 796 | |
RyoheiHagimoto | 0:0e0631af0305 | 797 | /** @overload |
RyoheiHagimoto | 0:0e0631af0305 | 798 | @param sizes Array of integers specifying an n-dimensional array shape. |
RyoheiHagimoto | 0:0e0631af0305 | 799 | @param type Array type. Use CV_8UC1, ..., CV_64FC4 to create 1-4 channel matrices, or |
RyoheiHagimoto | 0:0e0631af0305 | 800 | CV_8UC(n), ..., CV_64FC(n) to create multi-channel (up to CV_CN_MAX channels) matrices. |
RyoheiHagimoto | 0:0e0631af0305 | 801 | */ |
RyoheiHagimoto | 0:0e0631af0305 | 802 | Mat(const std::vector<int>& sizes, int type); |
RyoheiHagimoto | 0:0e0631af0305 | 803 | |
RyoheiHagimoto | 0:0e0631af0305 | 804 | /** @overload |
RyoheiHagimoto | 0:0e0631af0305 | 805 | @param ndims Array dimensionality. |
RyoheiHagimoto | 0:0e0631af0305 | 806 | @param sizes Array of integers specifying an n-dimensional array shape. |
RyoheiHagimoto | 0:0e0631af0305 | 807 | @param type Array type. Use CV_8UC1, ..., CV_64FC4 to create 1-4 channel matrices, or |
RyoheiHagimoto | 0:0e0631af0305 | 808 | CV_8UC(n), ..., CV_64FC(n) to create multi-channel (up to CV_CN_MAX channels) matrices. |
RyoheiHagimoto | 0:0e0631af0305 | 809 | @param s An optional value to initialize each matrix element with. To set all the matrix elements to |
RyoheiHagimoto | 0:0e0631af0305 | 810 | the particular value after the construction, use the assignment operator |
RyoheiHagimoto | 0:0e0631af0305 | 811 | Mat::operator=(const Scalar& value) . |
RyoheiHagimoto | 0:0e0631af0305 | 812 | */ |
RyoheiHagimoto | 0:0e0631af0305 | 813 | Mat(int ndims, const int* sizes, int type, const Scalar& s); |
RyoheiHagimoto | 0:0e0631af0305 | 814 | |
RyoheiHagimoto | 0:0e0631af0305 | 815 | /** @overload |
RyoheiHagimoto | 0:0e0631af0305 | 816 | @param sizes Array of integers specifying an n-dimensional array shape. |
RyoheiHagimoto | 0:0e0631af0305 | 817 | @param type Array type. Use CV_8UC1, ..., CV_64FC4 to create 1-4 channel matrices, or |
RyoheiHagimoto | 0:0e0631af0305 | 818 | CV_8UC(n), ..., CV_64FC(n) to create multi-channel (up to CV_CN_MAX channels) matrices. |
RyoheiHagimoto | 0:0e0631af0305 | 819 | @param s An optional value to initialize each matrix element with. To set all the matrix elements to |
RyoheiHagimoto | 0:0e0631af0305 | 820 | the particular value after the construction, use the assignment operator |
RyoheiHagimoto | 0:0e0631af0305 | 821 | Mat::operator=(const Scalar& value) . |
RyoheiHagimoto | 0:0e0631af0305 | 822 | */ |
RyoheiHagimoto | 0:0e0631af0305 | 823 | Mat(const std::vector<int>& sizes, int type, const Scalar& s); |
RyoheiHagimoto | 0:0e0631af0305 | 824 | |
RyoheiHagimoto | 0:0e0631af0305 | 825 | |
RyoheiHagimoto | 0:0e0631af0305 | 826 | /** @overload |
RyoheiHagimoto | 0:0e0631af0305 | 827 | @param m Array that (as a whole or partly) is assigned to the constructed matrix. No data is copied |
RyoheiHagimoto | 0:0e0631af0305 | 828 | by these constructors. Instead, the header pointing to m data or its sub-array is constructed and |
RyoheiHagimoto | 0:0e0631af0305 | 829 | associated with it. The reference counter, if any, is incremented. So, when you modify the matrix |
RyoheiHagimoto | 0:0e0631af0305 | 830 | formed using such a constructor, you also modify the corresponding elements of m . If you want to |
RyoheiHagimoto | 0:0e0631af0305 | 831 | have an independent copy of the sub-array, use Mat::clone() . |
RyoheiHagimoto | 0:0e0631af0305 | 832 | */ |
RyoheiHagimoto | 0:0e0631af0305 | 833 | Mat(const Mat& m); |
RyoheiHagimoto | 0:0e0631af0305 | 834 | |
RyoheiHagimoto | 0:0e0631af0305 | 835 | /** @overload |
RyoheiHagimoto | 0:0e0631af0305 | 836 | @param rows Number of rows in a 2D array. |
RyoheiHagimoto | 0:0e0631af0305 | 837 | @param cols Number of columns in a 2D array. |
RyoheiHagimoto | 0:0e0631af0305 | 838 | @param type Array type. Use CV_8UC1, ..., CV_64FC4 to create 1-4 channel matrices, or |
RyoheiHagimoto | 0:0e0631af0305 | 839 | CV_8UC(n), ..., CV_64FC(n) to create multi-channel (up to CV_CN_MAX channels) matrices. |
RyoheiHagimoto | 0:0e0631af0305 | 840 | @param data Pointer to the user data. Matrix constructors that take data and step parameters do not |
RyoheiHagimoto | 0:0e0631af0305 | 841 | allocate matrix data. Instead, they just initialize the matrix header that points to the specified |
RyoheiHagimoto | 0:0e0631af0305 | 842 | data, which means that no data is copied. This operation is very efficient and can be used to |
RyoheiHagimoto | 0:0e0631af0305 | 843 | process external data using OpenCV functions. The external data is not automatically deallocated, so |
RyoheiHagimoto | 0:0e0631af0305 | 844 | you should take care of it. |
RyoheiHagimoto | 0:0e0631af0305 | 845 | @param step Number of bytes each matrix row occupies. The value should include the padding bytes at |
RyoheiHagimoto | 0:0e0631af0305 | 846 | the end of each row, if any. If the parameter is missing (set to AUTO_STEP ), no padding is assumed |
RyoheiHagimoto | 0:0e0631af0305 | 847 | and the actual step is calculated as cols*elemSize(). See Mat::elemSize. |
RyoheiHagimoto | 0:0e0631af0305 | 848 | */ |
RyoheiHagimoto | 0:0e0631af0305 | 849 | Mat(int rows, int cols, int type, void* data, size_t step=AUTO_STEP); |
RyoheiHagimoto | 0:0e0631af0305 | 850 | |
RyoheiHagimoto | 0:0e0631af0305 | 851 | /** @overload |
RyoheiHagimoto | 0:0e0631af0305 | 852 | @param size 2D array size: Size(cols, rows) . In the Size() constructor, the number of rows and the |
RyoheiHagimoto | 0:0e0631af0305 | 853 | number of columns go in the reverse order. |
RyoheiHagimoto | 0:0e0631af0305 | 854 | @param type Array type. Use CV_8UC1, ..., CV_64FC4 to create 1-4 channel matrices, or |
RyoheiHagimoto | 0:0e0631af0305 | 855 | CV_8UC(n), ..., CV_64FC(n) to create multi-channel (up to CV_CN_MAX channels) matrices. |
RyoheiHagimoto | 0:0e0631af0305 | 856 | @param data Pointer to the user data. Matrix constructors that take data and step parameters do not |
RyoheiHagimoto | 0:0e0631af0305 | 857 | allocate matrix data. Instead, they just initialize the matrix header that points to the specified |
RyoheiHagimoto | 0:0e0631af0305 | 858 | data, which means that no data is copied. This operation is very efficient and can be used to |
RyoheiHagimoto | 0:0e0631af0305 | 859 | process external data using OpenCV functions. The external data is not automatically deallocated, so |
RyoheiHagimoto | 0:0e0631af0305 | 860 | you should take care of it. |
RyoheiHagimoto | 0:0e0631af0305 | 861 | @param step Number of bytes each matrix row occupies. The value should include the padding bytes at |
RyoheiHagimoto | 0:0e0631af0305 | 862 | the end of each row, if any. If the parameter is missing (set to AUTO_STEP ), no padding is assumed |
RyoheiHagimoto | 0:0e0631af0305 | 863 | and the actual step is calculated as cols*elemSize(). See Mat::elemSize. |
RyoheiHagimoto | 0:0e0631af0305 | 864 | */ |
RyoheiHagimoto | 0:0e0631af0305 | 865 | Mat(Size size, int type, void* data, size_t step=AUTO_STEP); |
RyoheiHagimoto | 0:0e0631af0305 | 866 | |
RyoheiHagimoto | 0:0e0631af0305 | 867 | /** @overload |
RyoheiHagimoto | 0:0e0631af0305 | 868 | @param ndims Array dimensionality. |
RyoheiHagimoto | 0:0e0631af0305 | 869 | @param sizes Array of integers specifying an n-dimensional array shape. |
RyoheiHagimoto | 0:0e0631af0305 | 870 | @param type Array type. Use CV_8UC1, ..., CV_64FC4 to create 1-4 channel matrices, or |
RyoheiHagimoto | 0:0e0631af0305 | 871 | CV_8UC(n), ..., CV_64FC(n) to create multi-channel (up to CV_CN_MAX channels) matrices. |
RyoheiHagimoto | 0:0e0631af0305 | 872 | @param data Pointer to the user data. Matrix constructors that take data and step parameters do not |
RyoheiHagimoto | 0:0e0631af0305 | 873 | allocate matrix data. Instead, they just initialize the matrix header that points to the specified |
RyoheiHagimoto | 0:0e0631af0305 | 874 | data, which means that no data is copied. This operation is very efficient and can be used to |
RyoheiHagimoto | 0:0e0631af0305 | 875 | process external data using OpenCV functions. The external data is not automatically deallocated, so |
RyoheiHagimoto | 0:0e0631af0305 | 876 | you should take care of it. |
RyoheiHagimoto | 0:0e0631af0305 | 877 | @param steps Array of ndims-1 steps in case of a multi-dimensional array (the last step is always |
RyoheiHagimoto | 0:0e0631af0305 | 878 | set to the element size). If not specified, the matrix is assumed to be continuous. |
RyoheiHagimoto | 0:0e0631af0305 | 879 | */ |
RyoheiHagimoto | 0:0e0631af0305 | 880 | Mat(int ndims, const int* sizes, int type, void* data, const size_t* steps=0); |
RyoheiHagimoto | 0:0e0631af0305 | 881 | |
RyoheiHagimoto | 0:0e0631af0305 | 882 | /** @overload |
RyoheiHagimoto | 0:0e0631af0305 | 883 | @param sizes Array of integers specifying an n-dimensional array shape. |
RyoheiHagimoto | 0:0e0631af0305 | 884 | @param type Array type. Use CV_8UC1, ..., CV_64FC4 to create 1-4 channel matrices, or |
RyoheiHagimoto | 0:0e0631af0305 | 885 | CV_8UC(n), ..., CV_64FC(n) to create multi-channel (up to CV_CN_MAX channels) matrices. |
RyoheiHagimoto | 0:0e0631af0305 | 886 | @param data Pointer to the user data. Matrix constructors that take data and step parameters do not |
RyoheiHagimoto | 0:0e0631af0305 | 887 | allocate matrix data. Instead, they just initialize the matrix header that points to the specified |
RyoheiHagimoto | 0:0e0631af0305 | 888 | data, which means that no data is copied. This operation is very efficient and can be used to |
RyoheiHagimoto | 0:0e0631af0305 | 889 | process external data using OpenCV functions. The external data is not automatically deallocated, so |
RyoheiHagimoto | 0:0e0631af0305 | 890 | you should take care of it. |
RyoheiHagimoto | 0:0e0631af0305 | 891 | @param steps Array of ndims-1 steps in case of a multi-dimensional array (the last step is always |
RyoheiHagimoto | 0:0e0631af0305 | 892 | set to the element size). If not specified, the matrix is assumed to be continuous. |
RyoheiHagimoto | 0:0e0631af0305 | 893 | */ |
RyoheiHagimoto | 0:0e0631af0305 | 894 | Mat(const std::vector<int>& sizes, int type, void* data, const size_t* steps=0); |
RyoheiHagimoto | 0:0e0631af0305 | 895 | |
RyoheiHagimoto | 0:0e0631af0305 | 896 | /** @overload |
RyoheiHagimoto | 0:0e0631af0305 | 897 | @param m Array that (as a whole or partly) is assigned to the constructed matrix. No data is copied |
RyoheiHagimoto | 0:0e0631af0305 | 898 | by these constructors. Instead, the header pointing to m data or its sub-array is constructed and |
RyoheiHagimoto | 0:0e0631af0305 | 899 | associated with it. The reference counter, if any, is incremented. So, when you modify the matrix |
RyoheiHagimoto | 0:0e0631af0305 | 900 | formed using such a constructor, you also modify the corresponding elements of m . If you want to |
RyoheiHagimoto | 0:0e0631af0305 | 901 | have an independent copy of the sub-array, use Mat::clone() . |
RyoheiHagimoto | 0:0e0631af0305 | 902 | @param rowRange Range of the m rows to take. As usual, the range start is inclusive and the range |
RyoheiHagimoto | 0:0e0631af0305 | 903 | end is exclusive. Use Range::all() to take all the rows. |
RyoheiHagimoto | 0:0e0631af0305 | 904 | @param colRange Range of the m columns to take. Use Range::all() to take all the columns. |
RyoheiHagimoto | 0:0e0631af0305 | 905 | */ |
RyoheiHagimoto | 0:0e0631af0305 | 906 | Mat(const Mat& m, const Range& rowRange, const Range& colRange=Range::all()); |
RyoheiHagimoto | 0:0e0631af0305 | 907 | |
RyoheiHagimoto | 0:0e0631af0305 | 908 | /** @overload |
RyoheiHagimoto | 0:0e0631af0305 | 909 | @param m Array that (as a whole or partly) is assigned to the constructed matrix. No data is copied |
RyoheiHagimoto | 0:0e0631af0305 | 910 | by these constructors. Instead, the header pointing to m data or its sub-array is constructed and |
RyoheiHagimoto | 0:0e0631af0305 | 911 | associated with it. The reference counter, if any, is incremented. So, when you modify the matrix |
RyoheiHagimoto | 0:0e0631af0305 | 912 | formed using such a constructor, you also modify the corresponding elements of m . If you want to |
RyoheiHagimoto | 0:0e0631af0305 | 913 | have an independent copy of the sub-array, use Mat::clone() . |
RyoheiHagimoto | 0:0e0631af0305 | 914 | @param roi Region of interest. |
RyoheiHagimoto | 0:0e0631af0305 | 915 | */ |
RyoheiHagimoto | 0:0e0631af0305 | 916 | Mat(const Mat& m, const Rect& roi); |
RyoheiHagimoto | 0:0e0631af0305 | 917 | |
RyoheiHagimoto | 0:0e0631af0305 | 918 | /** @overload |
RyoheiHagimoto | 0:0e0631af0305 | 919 | @param m Array that (as a whole or partly) is assigned to the constructed matrix. No data is copied |
RyoheiHagimoto | 0:0e0631af0305 | 920 | by these constructors. Instead, the header pointing to m data or its sub-array is constructed and |
RyoheiHagimoto | 0:0e0631af0305 | 921 | associated with it. The reference counter, if any, is incremented. So, when you modify the matrix |
RyoheiHagimoto | 0:0e0631af0305 | 922 | formed using such a constructor, you also modify the corresponding elements of m . If you want to |
RyoheiHagimoto | 0:0e0631af0305 | 923 | have an independent copy of the sub-array, use Mat::clone() . |
RyoheiHagimoto | 0:0e0631af0305 | 924 | @param ranges Array of selected ranges of m along each dimensionality. |
RyoheiHagimoto | 0:0e0631af0305 | 925 | */ |
RyoheiHagimoto | 0:0e0631af0305 | 926 | Mat(const Mat& m, const Range* ranges); |
RyoheiHagimoto | 0:0e0631af0305 | 927 | |
RyoheiHagimoto | 0:0e0631af0305 | 928 | /** @overload |
RyoheiHagimoto | 0:0e0631af0305 | 929 | @param m Array that (as a whole or partly) is assigned to the constructed matrix. No data is copied |
RyoheiHagimoto | 0:0e0631af0305 | 930 | by these constructors. Instead, the header pointing to m data or its sub-array is constructed and |
RyoheiHagimoto | 0:0e0631af0305 | 931 | associated with it. The reference counter, if any, is incremented. So, when you modify the matrix |
RyoheiHagimoto | 0:0e0631af0305 | 932 | formed using such a constructor, you also modify the corresponding elements of m . If you want to |
RyoheiHagimoto | 0:0e0631af0305 | 933 | have an independent copy of the sub-array, use Mat::clone() . |
RyoheiHagimoto | 0:0e0631af0305 | 934 | @param ranges Array of selected ranges of m along each dimensionality. |
RyoheiHagimoto | 0:0e0631af0305 | 935 | */ |
RyoheiHagimoto | 0:0e0631af0305 | 936 | Mat(const Mat& m, const std::vector<Range>& ranges); |
RyoheiHagimoto | 0:0e0631af0305 | 937 | |
RyoheiHagimoto | 0:0e0631af0305 | 938 | /** @overload |
RyoheiHagimoto | 0:0e0631af0305 | 939 | @param vec STL vector whose elements form the matrix. The matrix has a single column and the number |
RyoheiHagimoto | 0:0e0631af0305 | 940 | of rows equal to the number of vector elements. Type of the matrix matches the type of vector |
RyoheiHagimoto | 0:0e0631af0305 | 941 | elements. The constructor can handle arbitrary types, for which there is a properly declared |
RyoheiHagimoto | 0:0e0631af0305 | 942 | DataType . This means that the vector elements must be primitive numbers or uni-type numerical |
RyoheiHagimoto | 0:0e0631af0305 | 943 | tuples of numbers. Mixed-type structures are not supported. The corresponding constructor is |
RyoheiHagimoto | 0:0e0631af0305 | 944 | explicit. Since STL vectors are not automatically converted to Mat instances, you should write |
RyoheiHagimoto | 0:0e0631af0305 | 945 | Mat(vec) explicitly. Unless you copy the data into the matrix ( copyData=true ), no new elements |
RyoheiHagimoto | 0:0e0631af0305 | 946 | will be added to the vector because it can potentially yield vector data reallocation, and, thus, |
RyoheiHagimoto | 0:0e0631af0305 | 947 | the matrix data pointer will be invalid. |
RyoheiHagimoto | 0:0e0631af0305 | 948 | @param copyData Flag to specify whether the underlying data of the STL vector should be copied |
RyoheiHagimoto | 0:0e0631af0305 | 949 | to (true) or shared with (false) the newly constructed matrix. When the data is copied, the |
RyoheiHagimoto | 0:0e0631af0305 | 950 | allocated buffer is managed using Mat reference counting mechanism. While the data is shared, |
RyoheiHagimoto | 0:0e0631af0305 | 951 | the reference counter is NULL, and you should not deallocate the data until the matrix is not |
RyoheiHagimoto | 0:0e0631af0305 | 952 | destructed. |
RyoheiHagimoto | 0:0e0631af0305 | 953 | */ |
RyoheiHagimoto | 0:0e0631af0305 | 954 | template<typename _Tp> explicit Mat(const std::vector<_Tp>& vec, bool copyData=false); |
RyoheiHagimoto | 0:0e0631af0305 | 955 | |
RyoheiHagimoto | 0:0e0631af0305 | 956 | /** @overload |
RyoheiHagimoto | 0:0e0631af0305 | 957 | */ |
RyoheiHagimoto | 0:0e0631af0305 | 958 | template<typename _Tp, int n> explicit Mat(const Vec<_Tp, n>& vec, bool copyData=true); |
RyoheiHagimoto | 0:0e0631af0305 | 959 | |
RyoheiHagimoto | 0:0e0631af0305 | 960 | /** @overload |
RyoheiHagimoto | 0:0e0631af0305 | 961 | */ |
RyoheiHagimoto | 0:0e0631af0305 | 962 | template<typename _Tp, int m, int n> explicit Mat(const Matx<_Tp, m, n>& mtx, bool copyData=true); |
RyoheiHagimoto | 0:0e0631af0305 | 963 | |
RyoheiHagimoto | 0:0e0631af0305 | 964 | /** @overload |
RyoheiHagimoto | 0:0e0631af0305 | 965 | */ |
RyoheiHagimoto | 0:0e0631af0305 | 966 | template<typename _Tp> explicit Mat(const Point_<_Tp>& pt, bool copyData=true); |
RyoheiHagimoto | 0:0e0631af0305 | 967 | |
RyoheiHagimoto | 0:0e0631af0305 | 968 | /** @overload |
RyoheiHagimoto | 0:0e0631af0305 | 969 | */ |
RyoheiHagimoto | 0:0e0631af0305 | 970 | template<typename _Tp> explicit Mat(const Point3_<_Tp>& pt, bool copyData=true); |
RyoheiHagimoto | 0:0e0631af0305 | 971 | |
RyoheiHagimoto | 0:0e0631af0305 | 972 | /** @overload |
RyoheiHagimoto | 0:0e0631af0305 | 973 | */ |
RyoheiHagimoto | 0:0e0631af0305 | 974 | template<typename _Tp> explicit Mat(const MatCommaInitializer_<_Tp>& commaInitializer); |
RyoheiHagimoto | 0:0e0631af0305 | 975 | |
RyoheiHagimoto | 0:0e0631af0305 | 976 | //! download data from GpuMat |
RyoheiHagimoto | 0:0e0631af0305 | 977 | explicit Mat(const cuda::GpuMat& m); |
RyoheiHagimoto | 0:0e0631af0305 | 978 | |
RyoheiHagimoto | 0:0e0631af0305 | 979 | //! destructor - calls release() |
RyoheiHagimoto | 0:0e0631af0305 | 980 | ~Mat(); |
RyoheiHagimoto | 0:0e0631af0305 | 981 | |
RyoheiHagimoto | 0:0e0631af0305 | 982 | /** @brief assignment operators |
RyoheiHagimoto | 0:0e0631af0305 | 983 | |
RyoheiHagimoto | 0:0e0631af0305 | 984 | These are available assignment operators. Since they all are very different, make sure to read the |
RyoheiHagimoto | 0:0e0631af0305 | 985 | operator parameters description. |
RyoheiHagimoto | 0:0e0631af0305 | 986 | @param m Assigned, right-hand-side matrix. Matrix assignment is an O(1) operation. This means that |
RyoheiHagimoto | 0:0e0631af0305 | 987 | no data is copied but the data is shared and the reference counter, if any, is incremented. Before |
RyoheiHagimoto | 0:0e0631af0305 | 988 | assigning new data, the old data is de-referenced via Mat::release . |
RyoheiHagimoto | 0:0e0631af0305 | 989 | */ |
RyoheiHagimoto | 0:0e0631af0305 | 990 | Mat& operator = (const Mat& m); |
RyoheiHagimoto | 0:0e0631af0305 | 991 | |
RyoheiHagimoto | 0:0e0631af0305 | 992 | /** @overload |
RyoheiHagimoto | 0:0e0631af0305 | 993 | @param expr Assigned matrix expression object. As opposite to the first form of the assignment |
RyoheiHagimoto | 0:0e0631af0305 | 994 | operation, the second form can reuse already allocated matrix if it has the right size and type to |
RyoheiHagimoto | 0:0e0631af0305 | 995 | fit the matrix expression result. It is automatically handled by the real function that the matrix |
RyoheiHagimoto | 0:0e0631af0305 | 996 | expressions is expanded to. For example, C=A+B is expanded to add(A, B, C), and add takes care of |
RyoheiHagimoto | 0:0e0631af0305 | 997 | automatic C reallocation. |
RyoheiHagimoto | 0:0e0631af0305 | 998 | */ |
RyoheiHagimoto | 0:0e0631af0305 | 999 | Mat& operator = (const MatExpr& expr); |
RyoheiHagimoto | 0:0e0631af0305 | 1000 | |
RyoheiHagimoto | 0:0e0631af0305 | 1001 | //! retrieve UMat from Mat |
RyoheiHagimoto | 0:0e0631af0305 | 1002 | UMat getUMat(int accessFlags, UMatUsageFlags usageFlags = USAGE_DEFAULT) const; |
RyoheiHagimoto | 0:0e0631af0305 | 1003 | |
RyoheiHagimoto | 0:0e0631af0305 | 1004 | /** @brief Creates a matrix header for the specified matrix row. |
RyoheiHagimoto | 0:0e0631af0305 | 1005 | |
RyoheiHagimoto | 0:0e0631af0305 | 1006 | The method makes a new header for the specified matrix row and returns it. This is an O(1) |
RyoheiHagimoto | 0:0e0631af0305 | 1007 | operation, regardless of the matrix size. The underlying data of the new matrix is shared with the |
RyoheiHagimoto | 0:0e0631af0305 | 1008 | original matrix. Here is the example of one of the classical basic matrix processing operations, |
RyoheiHagimoto | 0:0e0631af0305 | 1009 | axpy, used by LU and many other algorithms: |
RyoheiHagimoto | 0:0e0631af0305 | 1010 | @code |
RyoheiHagimoto | 0:0e0631af0305 | 1011 | inline void matrix_axpy(Mat& A, int i, int j, double alpha) |
RyoheiHagimoto | 0:0e0631af0305 | 1012 | { |
RyoheiHagimoto | 0:0e0631af0305 | 1013 | A.row(i) += A.row(j)*alpha; |
RyoheiHagimoto | 0:0e0631af0305 | 1014 | } |
RyoheiHagimoto | 0:0e0631af0305 | 1015 | @endcode |
RyoheiHagimoto | 0:0e0631af0305 | 1016 | @note In the current implementation, the following code does not work as expected: |
RyoheiHagimoto | 0:0e0631af0305 | 1017 | @code |
RyoheiHagimoto | 0:0e0631af0305 | 1018 | Mat A; |
RyoheiHagimoto | 0:0e0631af0305 | 1019 | ... |
RyoheiHagimoto | 0:0e0631af0305 | 1020 | A.row(i) = A.row(j); // will not work |
RyoheiHagimoto | 0:0e0631af0305 | 1021 | @endcode |
RyoheiHagimoto | 0:0e0631af0305 | 1022 | This happens because A.row(i) forms a temporary header that is further assigned to another header. |
RyoheiHagimoto | 0:0e0631af0305 | 1023 | Remember that each of these operations is O(1), that is, no data is copied. Thus, the above |
RyoheiHagimoto | 0:0e0631af0305 | 1024 | assignment is not true if you may have expected the j-th row to be copied to the i-th row. To |
RyoheiHagimoto | 0:0e0631af0305 | 1025 | achieve that, you should either turn this simple assignment into an expression or use the |
RyoheiHagimoto | 0:0e0631af0305 | 1026 | Mat::copyTo method: |
RyoheiHagimoto | 0:0e0631af0305 | 1027 | @code |
RyoheiHagimoto | 0:0e0631af0305 | 1028 | Mat A; |
RyoheiHagimoto | 0:0e0631af0305 | 1029 | ... |
RyoheiHagimoto | 0:0e0631af0305 | 1030 | // works, but looks a bit obscure. |
RyoheiHagimoto | 0:0e0631af0305 | 1031 | A.row(i) = A.row(j) + 0; |
RyoheiHagimoto | 0:0e0631af0305 | 1032 | // this is a bit longer, but the recommended method. |
RyoheiHagimoto | 0:0e0631af0305 | 1033 | A.row(j).copyTo(A.row(i)); |
RyoheiHagimoto | 0:0e0631af0305 | 1034 | @endcode |
RyoheiHagimoto | 0:0e0631af0305 | 1035 | @param y A 0-based row index. |
RyoheiHagimoto | 0:0e0631af0305 | 1036 | */ |
RyoheiHagimoto | 0:0e0631af0305 | 1037 | Mat row(int y) const; |
RyoheiHagimoto | 0:0e0631af0305 | 1038 | |
RyoheiHagimoto | 0:0e0631af0305 | 1039 | /** @brief Creates a matrix header for the specified matrix column. |
RyoheiHagimoto | 0:0e0631af0305 | 1040 | |
RyoheiHagimoto | 0:0e0631af0305 | 1041 | The method makes a new header for the specified matrix column and returns it. This is an O(1) |
RyoheiHagimoto | 0:0e0631af0305 | 1042 | operation, regardless of the matrix size. The underlying data of the new matrix is shared with the |
RyoheiHagimoto | 0:0e0631af0305 | 1043 | original matrix. See also the Mat::row description. |
RyoheiHagimoto | 0:0e0631af0305 | 1044 | @param x A 0-based column index. |
RyoheiHagimoto | 0:0e0631af0305 | 1045 | */ |
RyoheiHagimoto | 0:0e0631af0305 | 1046 | Mat col(int x) const; |
RyoheiHagimoto | 0:0e0631af0305 | 1047 | |
RyoheiHagimoto | 0:0e0631af0305 | 1048 | /** @brief Creates a matrix header for the specified row span. |
RyoheiHagimoto | 0:0e0631af0305 | 1049 | |
RyoheiHagimoto | 0:0e0631af0305 | 1050 | The method makes a new header for the specified row span of the matrix. Similarly to Mat::row and |
RyoheiHagimoto | 0:0e0631af0305 | 1051 | Mat::col , this is an O(1) operation. |
RyoheiHagimoto | 0:0e0631af0305 | 1052 | @param startrow An inclusive 0-based start index of the row span. |
RyoheiHagimoto | 0:0e0631af0305 | 1053 | @param endrow An exclusive 0-based ending index of the row span. |
RyoheiHagimoto | 0:0e0631af0305 | 1054 | */ |
RyoheiHagimoto | 0:0e0631af0305 | 1055 | Mat rowRange(int startrow, int endrow) const; |
RyoheiHagimoto | 0:0e0631af0305 | 1056 | |
RyoheiHagimoto | 0:0e0631af0305 | 1057 | /** @overload |
RyoheiHagimoto | 0:0e0631af0305 | 1058 | @param r Range structure containing both the start and the end indices. |
RyoheiHagimoto | 0:0e0631af0305 | 1059 | */ |
RyoheiHagimoto | 0:0e0631af0305 | 1060 | Mat rowRange(const Range& r) const; |
RyoheiHagimoto | 0:0e0631af0305 | 1061 | |
RyoheiHagimoto | 0:0e0631af0305 | 1062 | /** @brief Creates a matrix header for the specified column span. |
RyoheiHagimoto | 0:0e0631af0305 | 1063 | |
RyoheiHagimoto | 0:0e0631af0305 | 1064 | The method makes a new header for the specified column span of the matrix. Similarly to Mat::row and |
RyoheiHagimoto | 0:0e0631af0305 | 1065 | Mat::col , this is an O(1) operation. |
RyoheiHagimoto | 0:0e0631af0305 | 1066 | @param startcol An inclusive 0-based start index of the column span. |
RyoheiHagimoto | 0:0e0631af0305 | 1067 | @param endcol An exclusive 0-based ending index of the column span. |
RyoheiHagimoto | 0:0e0631af0305 | 1068 | */ |
RyoheiHagimoto | 0:0e0631af0305 | 1069 | Mat colRange(int startcol, int endcol) const; |
RyoheiHagimoto | 0:0e0631af0305 | 1070 | |
RyoheiHagimoto | 0:0e0631af0305 | 1071 | /** @overload |
RyoheiHagimoto | 0:0e0631af0305 | 1072 | @param r Range structure containing both the start and the end indices. |
RyoheiHagimoto | 0:0e0631af0305 | 1073 | */ |
RyoheiHagimoto | 0:0e0631af0305 | 1074 | Mat colRange(const Range& r) const; |
RyoheiHagimoto | 0:0e0631af0305 | 1075 | |
RyoheiHagimoto | 0:0e0631af0305 | 1076 | /** @brief Extracts a diagonal from a matrix |
RyoheiHagimoto | 0:0e0631af0305 | 1077 | |
RyoheiHagimoto | 0:0e0631af0305 | 1078 | The method makes a new header for the specified matrix diagonal. The new matrix is represented as a |
RyoheiHagimoto | 0:0e0631af0305 | 1079 | single-column matrix. Similarly to Mat::row and Mat::col, this is an O(1) operation. |
RyoheiHagimoto | 0:0e0631af0305 | 1080 | @param d index of the diagonal, with the following values: |
RyoheiHagimoto | 0:0e0631af0305 | 1081 | - `d=0` is the main diagonal. |
RyoheiHagimoto | 0:0e0631af0305 | 1082 | - `d>0` is a diagonal from the lower half. For example, d=1 means the diagonal is set |
RyoheiHagimoto | 0:0e0631af0305 | 1083 | immediately below the main one. |
RyoheiHagimoto | 0:0e0631af0305 | 1084 | - `d<0` is a diagonal from the upper half. For example, d=-1 means the diagonal is set |
RyoheiHagimoto | 0:0e0631af0305 | 1085 | immediately above the main one. |
RyoheiHagimoto | 0:0e0631af0305 | 1086 | */ |
RyoheiHagimoto | 0:0e0631af0305 | 1087 | Mat diag(int d=0) const; |
RyoheiHagimoto | 0:0e0631af0305 | 1088 | |
RyoheiHagimoto | 0:0e0631af0305 | 1089 | /** @brief creates a diagonal matrix |
RyoheiHagimoto | 0:0e0631af0305 | 1090 | |
RyoheiHagimoto | 0:0e0631af0305 | 1091 | The method creates a square diagonal matrix from specified main diagonal. |
RyoheiHagimoto | 0:0e0631af0305 | 1092 | @param d One-dimensional matrix that represents the main diagonal. |
RyoheiHagimoto | 0:0e0631af0305 | 1093 | */ |
RyoheiHagimoto | 0:0e0631af0305 | 1094 | static Mat diag(const Mat& d); |
RyoheiHagimoto | 0:0e0631af0305 | 1095 | |
RyoheiHagimoto | 0:0e0631af0305 | 1096 | /** @brief Creates a full copy of the array and the underlying data. |
RyoheiHagimoto | 0:0e0631af0305 | 1097 | |
RyoheiHagimoto | 0:0e0631af0305 | 1098 | The method creates a full copy of the array. The original step[] is not taken into account. So, the |
RyoheiHagimoto | 0:0e0631af0305 | 1099 | array copy is a continuous array occupying total()*elemSize() bytes. |
RyoheiHagimoto | 0:0e0631af0305 | 1100 | */ |
RyoheiHagimoto | 0:0e0631af0305 | 1101 | Mat clone() const; |
RyoheiHagimoto | 0:0e0631af0305 | 1102 | |
RyoheiHagimoto | 0:0e0631af0305 | 1103 | /** @brief Copies the matrix to another one. |
RyoheiHagimoto | 0:0e0631af0305 | 1104 | |
RyoheiHagimoto | 0:0e0631af0305 | 1105 | The method copies the matrix data to another matrix. Before copying the data, the method invokes : |
RyoheiHagimoto | 0:0e0631af0305 | 1106 | @code |
RyoheiHagimoto | 0:0e0631af0305 | 1107 | m.create(this->size(), this->type()); |
RyoheiHagimoto | 0:0e0631af0305 | 1108 | @endcode |
RyoheiHagimoto | 0:0e0631af0305 | 1109 | so that the destination matrix is reallocated if needed. While m.copyTo(m); works flawlessly, the |
RyoheiHagimoto | 0:0e0631af0305 | 1110 | function does not handle the case of a partial overlap between the source and the destination |
RyoheiHagimoto | 0:0e0631af0305 | 1111 | matrices. |
RyoheiHagimoto | 0:0e0631af0305 | 1112 | |
RyoheiHagimoto | 0:0e0631af0305 | 1113 | When the operation mask is specified, if the Mat::create call shown above reallocates the matrix, |
RyoheiHagimoto | 0:0e0631af0305 | 1114 | the newly allocated matrix is initialized with all zeros before copying the data. |
RyoheiHagimoto | 0:0e0631af0305 | 1115 | @param m Destination matrix. If it does not have a proper size or type before the operation, it is |
RyoheiHagimoto | 0:0e0631af0305 | 1116 | reallocated. |
RyoheiHagimoto | 0:0e0631af0305 | 1117 | */ |
RyoheiHagimoto | 0:0e0631af0305 | 1118 | void copyTo( OutputArray m ) const; |
RyoheiHagimoto | 0:0e0631af0305 | 1119 | |
RyoheiHagimoto | 0:0e0631af0305 | 1120 | /** @overload |
RyoheiHagimoto | 0:0e0631af0305 | 1121 | @param m Destination matrix. If it does not have a proper size or type before the operation, it is |
RyoheiHagimoto | 0:0e0631af0305 | 1122 | reallocated. |
RyoheiHagimoto | 0:0e0631af0305 | 1123 | @param mask Operation mask. Its non-zero elements indicate which matrix elements need to be copied. |
RyoheiHagimoto | 0:0e0631af0305 | 1124 | The mask has to be of type CV_8U and can have 1 or multiple channels. |
RyoheiHagimoto | 0:0e0631af0305 | 1125 | */ |
RyoheiHagimoto | 0:0e0631af0305 | 1126 | void copyTo( OutputArray m, InputArray mask ) const; |
RyoheiHagimoto | 0:0e0631af0305 | 1127 | |
RyoheiHagimoto | 0:0e0631af0305 | 1128 | /** @brief Converts an array to another data type with optional scaling. |
RyoheiHagimoto | 0:0e0631af0305 | 1129 | |
RyoheiHagimoto | 0:0e0631af0305 | 1130 | The method converts source pixel values to the target data type. saturate_cast\<\> is applied at |
RyoheiHagimoto | 0:0e0631af0305 | 1131 | the end to avoid possible overflows: |
RyoheiHagimoto | 0:0e0631af0305 | 1132 | |
RyoheiHagimoto | 0:0e0631af0305 | 1133 | \f[m(x,y) = saturate \_ cast<rType>( \alpha (*this)(x,y) + \beta )\f] |
RyoheiHagimoto | 0:0e0631af0305 | 1134 | @param m output matrix; if it does not have a proper size or type before the operation, it is |
RyoheiHagimoto | 0:0e0631af0305 | 1135 | reallocated. |
RyoheiHagimoto | 0:0e0631af0305 | 1136 | @param rtype desired output matrix type or, rather, the depth since the number of channels are the |
RyoheiHagimoto | 0:0e0631af0305 | 1137 | same as the input has; if rtype is negative, the output matrix will have the same type as the input. |
RyoheiHagimoto | 0:0e0631af0305 | 1138 | @param alpha optional scale factor. |
RyoheiHagimoto | 0:0e0631af0305 | 1139 | @param beta optional delta added to the scaled values. |
RyoheiHagimoto | 0:0e0631af0305 | 1140 | */ |
RyoheiHagimoto | 0:0e0631af0305 | 1141 | void convertTo( OutputArray m, int rtype, double alpha=1, double beta=0 ) const; |
RyoheiHagimoto | 0:0e0631af0305 | 1142 | |
RyoheiHagimoto | 0:0e0631af0305 | 1143 | /** @brief Provides a functional form of convertTo. |
RyoheiHagimoto | 0:0e0631af0305 | 1144 | |
RyoheiHagimoto | 0:0e0631af0305 | 1145 | This is an internally used method called by the @ref MatrixExpressions engine. |
RyoheiHagimoto | 0:0e0631af0305 | 1146 | @param m Destination array. |
RyoheiHagimoto | 0:0e0631af0305 | 1147 | @param type Desired destination array depth (or -1 if it should be the same as the source type). |
RyoheiHagimoto | 0:0e0631af0305 | 1148 | */ |
RyoheiHagimoto | 0:0e0631af0305 | 1149 | void assignTo( Mat& m, int type=-1 ) const; |
RyoheiHagimoto | 0:0e0631af0305 | 1150 | |
RyoheiHagimoto | 0:0e0631af0305 | 1151 | /** @brief Sets all or some of the array elements to the specified value. |
RyoheiHagimoto | 0:0e0631af0305 | 1152 | @param s Assigned scalar converted to the actual array type. |
RyoheiHagimoto | 0:0e0631af0305 | 1153 | */ |
RyoheiHagimoto | 0:0e0631af0305 | 1154 | Mat& operator = (const Scalar& s); |
RyoheiHagimoto | 0:0e0631af0305 | 1155 | |
RyoheiHagimoto | 0:0e0631af0305 | 1156 | /** @brief Sets all or some of the array elements to the specified value. |
RyoheiHagimoto | 0:0e0631af0305 | 1157 | |
RyoheiHagimoto | 0:0e0631af0305 | 1158 | This is an advanced variant of the Mat::operator=(const Scalar& s) operator. |
RyoheiHagimoto | 0:0e0631af0305 | 1159 | @param value Assigned scalar converted to the actual array type. |
RyoheiHagimoto | 0:0e0631af0305 | 1160 | @param mask Operation mask of the same size as \*this. |
RyoheiHagimoto | 0:0e0631af0305 | 1161 | */ |
RyoheiHagimoto | 0:0e0631af0305 | 1162 | Mat& setTo(InputArray value, InputArray mask=noArray()); |
RyoheiHagimoto | 0:0e0631af0305 | 1163 | |
RyoheiHagimoto | 0:0e0631af0305 | 1164 | /** @brief Changes the shape and/or the number of channels of a 2D matrix without copying the data. |
RyoheiHagimoto | 0:0e0631af0305 | 1165 | |
RyoheiHagimoto | 0:0e0631af0305 | 1166 | The method makes a new matrix header for \*this elements. The new matrix may have a different size |
RyoheiHagimoto | 0:0e0631af0305 | 1167 | and/or different number of channels. Any combination is possible if: |
RyoheiHagimoto | 0:0e0631af0305 | 1168 | - No extra elements are included into the new matrix and no elements are excluded. Consequently, |
RyoheiHagimoto | 0:0e0631af0305 | 1169 | the product rows\*cols\*channels() must stay the same after the transformation. |
RyoheiHagimoto | 0:0e0631af0305 | 1170 | - No data is copied. That is, this is an O(1) operation. Consequently, if you change the number of |
RyoheiHagimoto | 0:0e0631af0305 | 1171 | rows, or the operation changes the indices of elements row in some other way, the matrix must be |
RyoheiHagimoto | 0:0e0631af0305 | 1172 | continuous. See Mat::isContinuous . |
RyoheiHagimoto | 0:0e0631af0305 | 1173 | |
RyoheiHagimoto | 0:0e0631af0305 | 1174 | For example, if there is a set of 3D points stored as an STL vector, and you want to represent the |
RyoheiHagimoto | 0:0e0631af0305 | 1175 | points as a 3xN matrix, do the following: |
RyoheiHagimoto | 0:0e0631af0305 | 1176 | @code |
RyoheiHagimoto | 0:0e0631af0305 | 1177 | std::vector<Point3f> vec; |
RyoheiHagimoto | 0:0e0631af0305 | 1178 | ... |
RyoheiHagimoto | 0:0e0631af0305 | 1179 | Mat pointMat = Mat(vec). // convert vector to Mat, O(1) operation |
RyoheiHagimoto | 0:0e0631af0305 | 1180 | reshape(1). // make Nx3 1-channel matrix out of Nx1 3-channel. |
RyoheiHagimoto | 0:0e0631af0305 | 1181 | // Also, an O(1) operation |
RyoheiHagimoto | 0:0e0631af0305 | 1182 | t(); // finally, transpose the Nx3 matrix. |
RyoheiHagimoto | 0:0e0631af0305 | 1183 | // This involves copying all the elements |
RyoheiHagimoto | 0:0e0631af0305 | 1184 | @endcode |
RyoheiHagimoto | 0:0e0631af0305 | 1185 | @param cn New number of channels. If the parameter is 0, the number of channels remains the same. |
RyoheiHagimoto | 0:0e0631af0305 | 1186 | @param rows New number of rows. If the parameter is 0, the number of rows remains the same. |
RyoheiHagimoto | 0:0e0631af0305 | 1187 | */ |
RyoheiHagimoto | 0:0e0631af0305 | 1188 | Mat reshape(int cn, int rows=0) const; |
RyoheiHagimoto | 0:0e0631af0305 | 1189 | |
RyoheiHagimoto | 0:0e0631af0305 | 1190 | /** @overload */ |
RyoheiHagimoto | 0:0e0631af0305 | 1191 | Mat reshape(int cn, int newndims, const int* newsz) const; |
RyoheiHagimoto | 0:0e0631af0305 | 1192 | |
RyoheiHagimoto | 0:0e0631af0305 | 1193 | /** @brief Transposes a matrix. |
RyoheiHagimoto | 0:0e0631af0305 | 1194 | |
RyoheiHagimoto | 0:0e0631af0305 | 1195 | The method performs matrix transposition by means of matrix expressions. It does not perform the |
RyoheiHagimoto | 0:0e0631af0305 | 1196 | actual transposition but returns a temporary matrix transposition object that can be further used as |
RyoheiHagimoto | 0:0e0631af0305 | 1197 | a part of more complex matrix expressions or can be assigned to a matrix: |
RyoheiHagimoto | 0:0e0631af0305 | 1198 | @code |
RyoheiHagimoto | 0:0e0631af0305 | 1199 | Mat A1 = A + Mat::eye(A.size(), A.type())*lambda; |
RyoheiHagimoto | 0:0e0631af0305 | 1200 | Mat C = A1.t()*A1; // compute (A + lambda*I)^t * (A + lamda*I) |
RyoheiHagimoto | 0:0e0631af0305 | 1201 | @endcode |
RyoheiHagimoto | 0:0e0631af0305 | 1202 | */ |
RyoheiHagimoto | 0:0e0631af0305 | 1203 | MatExpr t() const; |
RyoheiHagimoto | 0:0e0631af0305 | 1204 | |
RyoheiHagimoto | 0:0e0631af0305 | 1205 | /** @brief Inverses a matrix. |
RyoheiHagimoto | 0:0e0631af0305 | 1206 | |
RyoheiHagimoto | 0:0e0631af0305 | 1207 | The method performs a matrix inversion by means of matrix expressions. This means that a temporary |
RyoheiHagimoto | 0:0e0631af0305 | 1208 | matrix inversion object is returned by the method and can be used further as a part of more complex |
RyoheiHagimoto | 0:0e0631af0305 | 1209 | matrix expressions or can be assigned to a matrix. |
RyoheiHagimoto | 0:0e0631af0305 | 1210 | @param method Matrix inversion method. One of cv::DecompTypes |
RyoheiHagimoto | 0:0e0631af0305 | 1211 | */ |
RyoheiHagimoto | 0:0e0631af0305 | 1212 | MatExpr inv(int method=DECOMP_LU) const; |
RyoheiHagimoto | 0:0e0631af0305 | 1213 | |
RyoheiHagimoto | 0:0e0631af0305 | 1214 | /** @brief Performs an element-wise multiplication or division of the two matrices. |
RyoheiHagimoto | 0:0e0631af0305 | 1215 | |
RyoheiHagimoto | 0:0e0631af0305 | 1216 | The method returns a temporary object encoding per-element array multiplication, with optional |
RyoheiHagimoto | 0:0e0631af0305 | 1217 | scale. Note that this is not a matrix multiplication that corresponds to a simpler "\*" operator. |
RyoheiHagimoto | 0:0e0631af0305 | 1218 | |
RyoheiHagimoto | 0:0e0631af0305 | 1219 | Example: |
RyoheiHagimoto | 0:0e0631af0305 | 1220 | @code |
RyoheiHagimoto | 0:0e0631af0305 | 1221 | Mat C = A.mul(5/B); // equivalent to divide(A, B, C, 5) |
RyoheiHagimoto | 0:0e0631af0305 | 1222 | @endcode |
RyoheiHagimoto | 0:0e0631af0305 | 1223 | @param m Another array of the same type and the same size as \*this, or a matrix expression. |
RyoheiHagimoto | 0:0e0631af0305 | 1224 | @param scale Optional scale factor. |
RyoheiHagimoto | 0:0e0631af0305 | 1225 | */ |
RyoheiHagimoto | 0:0e0631af0305 | 1226 | MatExpr mul(InputArray m, double scale=1) const; |
RyoheiHagimoto | 0:0e0631af0305 | 1227 | |
RyoheiHagimoto | 0:0e0631af0305 | 1228 | /** @brief Computes a cross-product of two 3-element vectors. |
RyoheiHagimoto | 0:0e0631af0305 | 1229 | |
RyoheiHagimoto | 0:0e0631af0305 | 1230 | The method computes a cross-product of two 3-element vectors. The vectors must be 3-element |
RyoheiHagimoto | 0:0e0631af0305 | 1231 | floating-point vectors of the same shape and size. The result is another 3-element vector of the |
RyoheiHagimoto | 0:0e0631af0305 | 1232 | same shape and type as operands. |
RyoheiHagimoto | 0:0e0631af0305 | 1233 | @param m Another cross-product operand. |
RyoheiHagimoto | 0:0e0631af0305 | 1234 | */ |
RyoheiHagimoto | 0:0e0631af0305 | 1235 | Mat cross(InputArray m) const; |
RyoheiHagimoto | 0:0e0631af0305 | 1236 | |
RyoheiHagimoto | 0:0e0631af0305 | 1237 | /** @brief Computes a dot-product of two vectors. |
RyoheiHagimoto | 0:0e0631af0305 | 1238 | |
RyoheiHagimoto | 0:0e0631af0305 | 1239 | The method computes a dot-product of two matrices. If the matrices are not single-column or |
RyoheiHagimoto | 0:0e0631af0305 | 1240 | single-row vectors, the top-to-bottom left-to-right scan ordering is used to treat them as 1D |
RyoheiHagimoto | 0:0e0631af0305 | 1241 | vectors. The vectors must have the same size and type. If the matrices have more than one channel, |
RyoheiHagimoto | 0:0e0631af0305 | 1242 | the dot products from all the channels are summed together. |
RyoheiHagimoto | 0:0e0631af0305 | 1243 | @param m another dot-product operand. |
RyoheiHagimoto | 0:0e0631af0305 | 1244 | */ |
RyoheiHagimoto | 0:0e0631af0305 | 1245 | double dot(InputArray m) const; |
RyoheiHagimoto | 0:0e0631af0305 | 1246 | |
RyoheiHagimoto | 0:0e0631af0305 | 1247 | /** @brief Returns a zero array of the specified size and type. |
RyoheiHagimoto | 0:0e0631af0305 | 1248 | |
RyoheiHagimoto | 0:0e0631af0305 | 1249 | The method returns a Matlab-style zero array initializer. It can be used to quickly form a constant |
RyoheiHagimoto | 0:0e0631af0305 | 1250 | array as a function parameter, part of a matrix expression, or as a matrix initializer. : |
RyoheiHagimoto | 0:0e0631af0305 | 1251 | @code |
RyoheiHagimoto | 0:0e0631af0305 | 1252 | Mat A; |
RyoheiHagimoto | 0:0e0631af0305 | 1253 | A = Mat::zeros(3, 3, CV_32F); |
RyoheiHagimoto | 0:0e0631af0305 | 1254 | @endcode |
RyoheiHagimoto | 0:0e0631af0305 | 1255 | In the example above, a new matrix is allocated only if A is not a 3x3 floating-point matrix. |
RyoheiHagimoto | 0:0e0631af0305 | 1256 | Otherwise, the existing matrix A is filled with zeros. |
RyoheiHagimoto | 0:0e0631af0305 | 1257 | @param rows Number of rows. |
RyoheiHagimoto | 0:0e0631af0305 | 1258 | @param cols Number of columns. |
RyoheiHagimoto | 0:0e0631af0305 | 1259 | @param type Created matrix type. |
RyoheiHagimoto | 0:0e0631af0305 | 1260 | */ |
RyoheiHagimoto | 0:0e0631af0305 | 1261 | static MatExpr zeros(int rows, int cols, int type); |
RyoheiHagimoto | 0:0e0631af0305 | 1262 | |
RyoheiHagimoto | 0:0e0631af0305 | 1263 | /** @overload |
RyoheiHagimoto | 0:0e0631af0305 | 1264 | @param size Alternative to the matrix size specification Size(cols, rows) . |
RyoheiHagimoto | 0:0e0631af0305 | 1265 | @param type Created matrix type. |
RyoheiHagimoto | 0:0e0631af0305 | 1266 | */ |
RyoheiHagimoto | 0:0e0631af0305 | 1267 | static MatExpr zeros(Size size, int type); |
RyoheiHagimoto | 0:0e0631af0305 | 1268 | |
RyoheiHagimoto | 0:0e0631af0305 | 1269 | /** @overload |
RyoheiHagimoto | 0:0e0631af0305 | 1270 | @param ndims Array dimensionality. |
RyoheiHagimoto | 0:0e0631af0305 | 1271 | @param sz Array of integers specifying the array shape. |
RyoheiHagimoto | 0:0e0631af0305 | 1272 | @param type Created matrix type. |
RyoheiHagimoto | 0:0e0631af0305 | 1273 | */ |
RyoheiHagimoto | 0:0e0631af0305 | 1274 | static MatExpr zeros(int ndims, const int* sz, int type); |
RyoheiHagimoto | 0:0e0631af0305 | 1275 | |
RyoheiHagimoto | 0:0e0631af0305 | 1276 | /** @brief Returns an array of all 1's of the specified size and type. |
RyoheiHagimoto | 0:0e0631af0305 | 1277 | |
RyoheiHagimoto | 0:0e0631af0305 | 1278 | The method returns a Matlab-style 1's array initializer, similarly to Mat::zeros. Note that using |
RyoheiHagimoto | 0:0e0631af0305 | 1279 | this method you can initialize an array with an arbitrary value, using the following Matlab idiom: |
RyoheiHagimoto | 0:0e0631af0305 | 1280 | @code |
RyoheiHagimoto | 0:0e0631af0305 | 1281 | Mat A = Mat::ones(100, 100, CV_8U)*3; // make 100x100 matrix filled with 3. |
RyoheiHagimoto | 0:0e0631af0305 | 1282 | @endcode |
RyoheiHagimoto | 0:0e0631af0305 | 1283 | The above operation does not form a 100x100 matrix of 1's and then multiply it by 3. Instead, it |
RyoheiHagimoto | 0:0e0631af0305 | 1284 | just remembers the scale factor (3 in this case) and use it when actually invoking the matrix |
RyoheiHagimoto | 0:0e0631af0305 | 1285 | initializer. |
RyoheiHagimoto | 0:0e0631af0305 | 1286 | @param rows Number of rows. |
RyoheiHagimoto | 0:0e0631af0305 | 1287 | @param cols Number of columns. |
RyoheiHagimoto | 0:0e0631af0305 | 1288 | @param type Created matrix type. |
RyoheiHagimoto | 0:0e0631af0305 | 1289 | */ |
RyoheiHagimoto | 0:0e0631af0305 | 1290 | static MatExpr ones(int rows, int cols, int type); |
RyoheiHagimoto | 0:0e0631af0305 | 1291 | |
RyoheiHagimoto | 0:0e0631af0305 | 1292 | /** @overload |
RyoheiHagimoto | 0:0e0631af0305 | 1293 | @param size Alternative to the matrix size specification Size(cols, rows) . |
RyoheiHagimoto | 0:0e0631af0305 | 1294 | @param type Created matrix type. |
RyoheiHagimoto | 0:0e0631af0305 | 1295 | */ |
RyoheiHagimoto | 0:0e0631af0305 | 1296 | static MatExpr ones(Size size, int type); |
RyoheiHagimoto | 0:0e0631af0305 | 1297 | |
RyoheiHagimoto | 0:0e0631af0305 | 1298 | /** @overload |
RyoheiHagimoto | 0:0e0631af0305 | 1299 | @param ndims Array dimensionality. |
RyoheiHagimoto | 0:0e0631af0305 | 1300 | @param sz Array of integers specifying the array shape. |
RyoheiHagimoto | 0:0e0631af0305 | 1301 | @param type Created matrix type. |
RyoheiHagimoto | 0:0e0631af0305 | 1302 | */ |
RyoheiHagimoto | 0:0e0631af0305 | 1303 | static MatExpr ones(int ndims, const int* sz, int type); |
RyoheiHagimoto | 0:0e0631af0305 | 1304 | |
RyoheiHagimoto | 0:0e0631af0305 | 1305 | /** @brief Returns an identity matrix of the specified size and type. |
RyoheiHagimoto | 0:0e0631af0305 | 1306 | |
RyoheiHagimoto | 0:0e0631af0305 | 1307 | The method returns a Matlab-style identity matrix initializer, similarly to Mat::zeros. Similarly to |
RyoheiHagimoto | 0:0e0631af0305 | 1308 | Mat::ones, you can use a scale operation to create a scaled identity matrix efficiently: |
RyoheiHagimoto | 0:0e0631af0305 | 1309 | @code |
RyoheiHagimoto | 0:0e0631af0305 | 1310 | // make a 4x4 diagonal matrix with 0.1's on the diagonal. |
RyoheiHagimoto | 0:0e0631af0305 | 1311 | Mat A = Mat::eye(4, 4, CV_32F)*0.1; |
RyoheiHagimoto | 0:0e0631af0305 | 1312 | @endcode |
RyoheiHagimoto | 0:0e0631af0305 | 1313 | @param rows Number of rows. |
RyoheiHagimoto | 0:0e0631af0305 | 1314 | @param cols Number of columns. |
RyoheiHagimoto | 0:0e0631af0305 | 1315 | @param type Created matrix type. |
RyoheiHagimoto | 0:0e0631af0305 | 1316 | */ |
RyoheiHagimoto | 0:0e0631af0305 | 1317 | static MatExpr eye(int rows, int cols, int type); |
RyoheiHagimoto | 0:0e0631af0305 | 1318 | |
RyoheiHagimoto | 0:0e0631af0305 | 1319 | /** @overload |
RyoheiHagimoto | 0:0e0631af0305 | 1320 | @param size Alternative matrix size specification as Size(cols, rows) . |
RyoheiHagimoto | 0:0e0631af0305 | 1321 | @param type Created matrix type. |
RyoheiHagimoto | 0:0e0631af0305 | 1322 | */ |
RyoheiHagimoto | 0:0e0631af0305 | 1323 | static MatExpr eye(Size size, int type); |
RyoheiHagimoto | 0:0e0631af0305 | 1324 | |
RyoheiHagimoto | 0:0e0631af0305 | 1325 | /** @brief Allocates new array data if needed. |
RyoheiHagimoto | 0:0e0631af0305 | 1326 | |
RyoheiHagimoto | 0:0e0631af0305 | 1327 | This is one of the key Mat methods. Most new-style OpenCV functions and methods that produce arrays |
RyoheiHagimoto | 0:0e0631af0305 | 1328 | call this method for each output array. The method uses the following algorithm: |
RyoheiHagimoto | 0:0e0631af0305 | 1329 | |
RyoheiHagimoto | 0:0e0631af0305 | 1330 | -# If the current array shape and the type match the new ones, return immediately. Otherwise, |
RyoheiHagimoto | 0:0e0631af0305 | 1331 | de-reference the previous data by calling Mat::release. |
RyoheiHagimoto | 0:0e0631af0305 | 1332 | -# Initialize the new header. |
RyoheiHagimoto | 0:0e0631af0305 | 1333 | -# Allocate the new data of total()\*elemSize() bytes. |
RyoheiHagimoto | 0:0e0631af0305 | 1334 | -# Allocate the new, associated with the data, reference counter and set it to 1. |
RyoheiHagimoto | 0:0e0631af0305 | 1335 | |
RyoheiHagimoto | 0:0e0631af0305 | 1336 | Such a scheme makes the memory management robust and efficient at the same time and helps avoid |
RyoheiHagimoto | 0:0e0631af0305 | 1337 | extra typing for you. This means that usually there is no need to explicitly allocate output arrays. |
RyoheiHagimoto | 0:0e0631af0305 | 1338 | That is, instead of writing: |
RyoheiHagimoto | 0:0e0631af0305 | 1339 | @code |
RyoheiHagimoto | 0:0e0631af0305 | 1340 | Mat color; |
RyoheiHagimoto | 0:0e0631af0305 | 1341 | ... |
RyoheiHagimoto | 0:0e0631af0305 | 1342 | Mat gray(color.rows, color.cols, color.depth()); |
RyoheiHagimoto | 0:0e0631af0305 | 1343 | cvtColor(color, gray, COLOR_BGR2GRAY); |
RyoheiHagimoto | 0:0e0631af0305 | 1344 | @endcode |
RyoheiHagimoto | 0:0e0631af0305 | 1345 | you can simply write: |
RyoheiHagimoto | 0:0e0631af0305 | 1346 | @code |
RyoheiHagimoto | 0:0e0631af0305 | 1347 | Mat color; |
RyoheiHagimoto | 0:0e0631af0305 | 1348 | ... |
RyoheiHagimoto | 0:0e0631af0305 | 1349 | Mat gray; |
RyoheiHagimoto | 0:0e0631af0305 | 1350 | cvtColor(color, gray, COLOR_BGR2GRAY); |
RyoheiHagimoto | 0:0e0631af0305 | 1351 | @endcode |
RyoheiHagimoto | 0:0e0631af0305 | 1352 | because cvtColor, as well as the most of OpenCV functions, calls Mat::create() for the output array |
RyoheiHagimoto | 0:0e0631af0305 | 1353 | internally. |
RyoheiHagimoto | 0:0e0631af0305 | 1354 | @param rows New number of rows. |
RyoheiHagimoto | 0:0e0631af0305 | 1355 | @param cols New number of columns. |
RyoheiHagimoto | 0:0e0631af0305 | 1356 | @param type New matrix type. |
RyoheiHagimoto | 0:0e0631af0305 | 1357 | */ |
RyoheiHagimoto | 0:0e0631af0305 | 1358 | void create(int rows, int cols, int type); |
RyoheiHagimoto | 0:0e0631af0305 | 1359 | |
RyoheiHagimoto | 0:0e0631af0305 | 1360 | /** @overload |
RyoheiHagimoto | 0:0e0631af0305 | 1361 | @param size Alternative new matrix size specification: Size(cols, rows) |
RyoheiHagimoto | 0:0e0631af0305 | 1362 | @param type New matrix type. |
RyoheiHagimoto | 0:0e0631af0305 | 1363 | */ |
RyoheiHagimoto | 0:0e0631af0305 | 1364 | void create(Size size, int type); |
RyoheiHagimoto | 0:0e0631af0305 | 1365 | |
RyoheiHagimoto | 0:0e0631af0305 | 1366 | /** @overload |
RyoheiHagimoto | 0:0e0631af0305 | 1367 | @param ndims New array dimensionality. |
RyoheiHagimoto | 0:0e0631af0305 | 1368 | @param sizes Array of integers specifying a new array shape. |
RyoheiHagimoto | 0:0e0631af0305 | 1369 | @param type New matrix type. |
RyoheiHagimoto | 0:0e0631af0305 | 1370 | */ |
RyoheiHagimoto | 0:0e0631af0305 | 1371 | void create(int ndims, const int* sizes, int type); |
RyoheiHagimoto | 0:0e0631af0305 | 1372 | |
RyoheiHagimoto | 0:0e0631af0305 | 1373 | /** @overload |
RyoheiHagimoto | 0:0e0631af0305 | 1374 | @param sizes Array of integers specifying a new array shape. |
RyoheiHagimoto | 0:0e0631af0305 | 1375 | @param type New matrix type. |
RyoheiHagimoto | 0:0e0631af0305 | 1376 | */ |
RyoheiHagimoto | 0:0e0631af0305 | 1377 | void create(const std::vector<int>& sizes, int type); |
RyoheiHagimoto | 0:0e0631af0305 | 1378 | |
RyoheiHagimoto | 0:0e0631af0305 | 1379 | /** @brief Increments the reference counter. |
RyoheiHagimoto | 0:0e0631af0305 | 1380 | |
RyoheiHagimoto | 0:0e0631af0305 | 1381 | The method increments the reference counter associated with the matrix data. If the matrix header |
RyoheiHagimoto | 0:0e0631af0305 | 1382 | points to an external data set (see Mat::Mat ), the reference counter is NULL, and the method has no |
RyoheiHagimoto | 0:0e0631af0305 | 1383 | effect in this case. Normally, to avoid memory leaks, the method should not be called explicitly. It |
RyoheiHagimoto | 0:0e0631af0305 | 1384 | is called implicitly by the matrix assignment operator. The reference counter increment is an atomic |
RyoheiHagimoto | 0:0e0631af0305 | 1385 | operation on the platforms that support it. Thus, it is safe to operate on the same matrices |
RyoheiHagimoto | 0:0e0631af0305 | 1386 | asynchronously in different threads. |
RyoheiHagimoto | 0:0e0631af0305 | 1387 | */ |
RyoheiHagimoto | 0:0e0631af0305 | 1388 | void addref(); |
RyoheiHagimoto | 0:0e0631af0305 | 1389 | |
RyoheiHagimoto | 0:0e0631af0305 | 1390 | /** @brief Decrements the reference counter and deallocates the matrix if needed. |
RyoheiHagimoto | 0:0e0631af0305 | 1391 | |
RyoheiHagimoto | 0:0e0631af0305 | 1392 | The method decrements the reference counter associated with the matrix data. When the reference |
RyoheiHagimoto | 0:0e0631af0305 | 1393 | counter reaches 0, the matrix data is deallocated and the data and the reference counter pointers |
RyoheiHagimoto | 0:0e0631af0305 | 1394 | are set to NULL's. If the matrix header points to an external data set (see Mat::Mat ), the |
RyoheiHagimoto | 0:0e0631af0305 | 1395 | reference counter is NULL, and the method has no effect in this case. |
RyoheiHagimoto | 0:0e0631af0305 | 1396 | |
RyoheiHagimoto | 0:0e0631af0305 | 1397 | This method can be called manually to force the matrix data deallocation. But since this method is |
RyoheiHagimoto | 0:0e0631af0305 | 1398 | automatically called in the destructor, or by any other method that changes the data pointer, it is |
RyoheiHagimoto | 0:0e0631af0305 | 1399 | usually not needed. The reference counter decrement and check for 0 is an atomic operation on the |
RyoheiHagimoto | 0:0e0631af0305 | 1400 | platforms that support it. Thus, it is safe to operate on the same matrices asynchronously in |
RyoheiHagimoto | 0:0e0631af0305 | 1401 | different threads. |
RyoheiHagimoto | 0:0e0631af0305 | 1402 | */ |
RyoheiHagimoto | 0:0e0631af0305 | 1403 | void release(); |
RyoheiHagimoto | 0:0e0631af0305 | 1404 | |
RyoheiHagimoto | 0:0e0631af0305 | 1405 | //! deallocates the matrix data |
RyoheiHagimoto | 0:0e0631af0305 | 1406 | void deallocate(); |
RyoheiHagimoto | 0:0e0631af0305 | 1407 | //! internal use function; properly re-allocates _size, _step arrays |
RyoheiHagimoto | 0:0e0631af0305 | 1408 | void copySize(const Mat& m); |
RyoheiHagimoto | 0:0e0631af0305 | 1409 | |
RyoheiHagimoto | 0:0e0631af0305 | 1410 | /** @brief Reserves space for the certain number of rows. |
RyoheiHagimoto | 0:0e0631af0305 | 1411 | |
RyoheiHagimoto | 0:0e0631af0305 | 1412 | The method reserves space for sz rows. If the matrix already has enough space to store sz rows, |
RyoheiHagimoto | 0:0e0631af0305 | 1413 | nothing happens. If the matrix is reallocated, the first Mat::rows rows are preserved. The method |
RyoheiHagimoto | 0:0e0631af0305 | 1414 | emulates the corresponding method of the STL vector class. |
RyoheiHagimoto | 0:0e0631af0305 | 1415 | @param sz Number of rows. |
RyoheiHagimoto | 0:0e0631af0305 | 1416 | */ |
RyoheiHagimoto | 0:0e0631af0305 | 1417 | void reserve(size_t sz); |
RyoheiHagimoto | 0:0e0631af0305 | 1418 | |
RyoheiHagimoto | 0:0e0631af0305 | 1419 | /** @brief Changes the number of matrix rows. |
RyoheiHagimoto | 0:0e0631af0305 | 1420 | |
RyoheiHagimoto | 0:0e0631af0305 | 1421 | The methods change the number of matrix rows. If the matrix is reallocated, the first |
RyoheiHagimoto | 0:0e0631af0305 | 1422 | min(Mat::rows, sz) rows are preserved. The methods emulate the corresponding methods of the STL |
RyoheiHagimoto | 0:0e0631af0305 | 1423 | vector class. |
RyoheiHagimoto | 0:0e0631af0305 | 1424 | @param sz New number of rows. |
RyoheiHagimoto | 0:0e0631af0305 | 1425 | */ |
RyoheiHagimoto | 0:0e0631af0305 | 1426 | void resize(size_t sz); |
RyoheiHagimoto | 0:0e0631af0305 | 1427 | |
RyoheiHagimoto | 0:0e0631af0305 | 1428 | /** @overload |
RyoheiHagimoto | 0:0e0631af0305 | 1429 | @param sz New number of rows. |
RyoheiHagimoto | 0:0e0631af0305 | 1430 | @param s Value assigned to the newly added elements. |
RyoheiHagimoto | 0:0e0631af0305 | 1431 | */ |
RyoheiHagimoto | 0:0e0631af0305 | 1432 | void resize(size_t sz, const Scalar& s); |
RyoheiHagimoto | 0:0e0631af0305 | 1433 | |
RyoheiHagimoto | 0:0e0631af0305 | 1434 | //! internal function |
RyoheiHagimoto | 0:0e0631af0305 | 1435 | void push_back_(const void* elem); |
RyoheiHagimoto | 0:0e0631af0305 | 1436 | |
RyoheiHagimoto | 0:0e0631af0305 | 1437 | /** @brief Adds elements to the bottom of the matrix. |
RyoheiHagimoto | 0:0e0631af0305 | 1438 | |
RyoheiHagimoto | 0:0e0631af0305 | 1439 | The methods add one or more elements to the bottom of the matrix. They emulate the corresponding |
RyoheiHagimoto | 0:0e0631af0305 | 1440 | method of the STL vector class. When elem is Mat , its type and the number of columns must be the |
RyoheiHagimoto | 0:0e0631af0305 | 1441 | same as in the container matrix. |
RyoheiHagimoto | 0:0e0631af0305 | 1442 | @param elem Added element(s). |
RyoheiHagimoto | 0:0e0631af0305 | 1443 | */ |
RyoheiHagimoto | 0:0e0631af0305 | 1444 | template<typename _Tp> void push_back(const _Tp& elem); |
RyoheiHagimoto | 0:0e0631af0305 | 1445 | |
RyoheiHagimoto | 0:0e0631af0305 | 1446 | /** @overload |
RyoheiHagimoto | 0:0e0631af0305 | 1447 | @param elem Added element(s). |
RyoheiHagimoto | 0:0e0631af0305 | 1448 | */ |
RyoheiHagimoto | 0:0e0631af0305 | 1449 | template<typename _Tp> void push_back(const Mat_<_Tp>& elem); |
RyoheiHagimoto | 0:0e0631af0305 | 1450 | |
RyoheiHagimoto | 0:0e0631af0305 | 1451 | /** @overload |
RyoheiHagimoto | 0:0e0631af0305 | 1452 | @param m Added line(s). |
RyoheiHagimoto | 0:0e0631af0305 | 1453 | */ |
RyoheiHagimoto | 0:0e0631af0305 | 1454 | void push_back(const Mat& m); |
RyoheiHagimoto | 0:0e0631af0305 | 1455 | |
RyoheiHagimoto | 0:0e0631af0305 | 1456 | /** @brief Removes elements from the bottom of the matrix. |
RyoheiHagimoto | 0:0e0631af0305 | 1457 | |
RyoheiHagimoto | 0:0e0631af0305 | 1458 | The method removes one or more rows from the bottom of the matrix. |
RyoheiHagimoto | 0:0e0631af0305 | 1459 | @param nelems Number of removed rows. If it is greater than the total number of rows, an exception |
RyoheiHagimoto | 0:0e0631af0305 | 1460 | is thrown. |
RyoheiHagimoto | 0:0e0631af0305 | 1461 | */ |
RyoheiHagimoto | 0:0e0631af0305 | 1462 | void pop_back(size_t nelems=1); |
RyoheiHagimoto | 0:0e0631af0305 | 1463 | |
RyoheiHagimoto | 0:0e0631af0305 | 1464 | /** @brief Locates the matrix header within a parent matrix. |
RyoheiHagimoto | 0:0e0631af0305 | 1465 | |
RyoheiHagimoto | 0:0e0631af0305 | 1466 | After you extracted a submatrix from a matrix using Mat::row, Mat::col, Mat::rowRange, |
RyoheiHagimoto | 0:0e0631af0305 | 1467 | Mat::colRange, and others, the resultant submatrix points just to the part of the original big |
RyoheiHagimoto | 0:0e0631af0305 | 1468 | matrix. However, each submatrix contains information (represented by datastart and dataend |
RyoheiHagimoto | 0:0e0631af0305 | 1469 | fields) that helps reconstruct the original matrix size and the position of the extracted |
RyoheiHagimoto | 0:0e0631af0305 | 1470 | submatrix within the original matrix. The method locateROI does exactly that. |
RyoheiHagimoto | 0:0e0631af0305 | 1471 | @param wholeSize Output parameter that contains the size of the whole matrix containing *this* |
RyoheiHagimoto | 0:0e0631af0305 | 1472 | as a part. |
RyoheiHagimoto | 0:0e0631af0305 | 1473 | @param ofs Output parameter that contains an offset of *this* inside the whole matrix. |
RyoheiHagimoto | 0:0e0631af0305 | 1474 | */ |
RyoheiHagimoto | 0:0e0631af0305 | 1475 | void locateROI( Size& wholeSize, Point& ofs ) const; |
RyoheiHagimoto | 0:0e0631af0305 | 1476 | |
RyoheiHagimoto | 0:0e0631af0305 | 1477 | /** @brief Adjusts a submatrix size and position within the parent matrix. |
RyoheiHagimoto | 0:0e0631af0305 | 1478 | |
RyoheiHagimoto | 0:0e0631af0305 | 1479 | The method is complimentary to Mat::locateROI . The typical use of these functions is to determine |
RyoheiHagimoto | 0:0e0631af0305 | 1480 | the submatrix position within the parent matrix and then shift the position somehow. Typically, it |
RyoheiHagimoto | 0:0e0631af0305 | 1481 | can be required for filtering operations when pixels outside of the ROI should be taken into |
RyoheiHagimoto | 0:0e0631af0305 | 1482 | account. When all the method parameters are positive, the ROI needs to grow in all directions by the |
RyoheiHagimoto | 0:0e0631af0305 | 1483 | specified amount, for example: |
RyoheiHagimoto | 0:0e0631af0305 | 1484 | @code |
RyoheiHagimoto | 0:0e0631af0305 | 1485 | A.adjustROI(2, 2, 2, 2); |
RyoheiHagimoto | 0:0e0631af0305 | 1486 | @endcode |
RyoheiHagimoto | 0:0e0631af0305 | 1487 | In this example, the matrix size is increased by 4 elements in each direction. The matrix is shifted |
RyoheiHagimoto | 0:0e0631af0305 | 1488 | by 2 elements to the left and 2 elements up, which brings in all the necessary pixels for the |
RyoheiHagimoto | 0:0e0631af0305 | 1489 | filtering with the 5x5 kernel. |
RyoheiHagimoto | 0:0e0631af0305 | 1490 | |
RyoheiHagimoto | 0:0e0631af0305 | 1491 | adjustROI forces the adjusted ROI to be inside of the parent matrix that is boundaries of the |
RyoheiHagimoto | 0:0e0631af0305 | 1492 | adjusted ROI are constrained by boundaries of the parent matrix. For example, if the submatrix A is |
RyoheiHagimoto | 0:0e0631af0305 | 1493 | located in the first row of a parent matrix and you called A.adjustROI(2, 2, 2, 2) then A will not |
RyoheiHagimoto | 0:0e0631af0305 | 1494 | be increased in the upward direction. |
RyoheiHagimoto | 0:0e0631af0305 | 1495 | |
RyoheiHagimoto | 0:0e0631af0305 | 1496 | The function is used internally by the OpenCV filtering functions, like filter2D , morphological |
RyoheiHagimoto | 0:0e0631af0305 | 1497 | operations, and so on. |
RyoheiHagimoto | 0:0e0631af0305 | 1498 | @param dtop Shift of the top submatrix boundary upwards. |
RyoheiHagimoto | 0:0e0631af0305 | 1499 | @param dbottom Shift of the bottom submatrix boundary downwards. |
RyoheiHagimoto | 0:0e0631af0305 | 1500 | @param dleft Shift of the left submatrix boundary to the left. |
RyoheiHagimoto | 0:0e0631af0305 | 1501 | @param dright Shift of the right submatrix boundary to the right. |
RyoheiHagimoto | 0:0e0631af0305 | 1502 | @sa copyMakeBorder |
RyoheiHagimoto | 0:0e0631af0305 | 1503 | */ |
RyoheiHagimoto | 0:0e0631af0305 | 1504 | Mat& adjustROI( int dtop, int dbottom, int dleft, int dright ); |
RyoheiHagimoto | 0:0e0631af0305 | 1505 | |
RyoheiHagimoto | 0:0e0631af0305 | 1506 | /** @brief Extracts a rectangular submatrix. |
RyoheiHagimoto | 0:0e0631af0305 | 1507 | |
RyoheiHagimoto | 0:0e0631af0305 | 1508 | The operators make a new header for the specified sub-array of \*this . They are the most |
RyoheiHagimoto | 0:0e0631af0305 | 1509 | generalized forms of Mat::row, Mat::col, Mat::rowRange, and Mat::colRange . For example, |
RyoheiHagimoto | 0:0e0631af0305 | 1510 | `A(Range(0, 10), Range::all())` is equivalent to `A.rowRange(0, 10)`. Similarly to all of the above, |
RyoheiHagimoto | 0:0e0631af0305 | 1511 | the operators are O(1) operations, that is, no matrix data is copied. |
RyoheiHagimoto | 0:0e0631af0305 | 1512 | @param rowRange Start and end row of the extracted submatrix. The upper boundary is not included. To |
RyoheiHagimoto | 0:0e0631af0305 | 1513 | select all the rows, use Range::all(). |
RyoheiHagimoto | 0:0e0631af0305 | 1514 | @param colRange Start and end column of the extracted submatrix. The upper boundary is not included. |
RyoheiHagimoto | 0:0e0631af0305 | 1515 | To select all the columns, use Range::all(). |
RyoheiHagimoto | 0:0e0631af0305 | 1516 | */ |
RyoheiHagimoto | 0:0e0631af0305 | 1517 | Mat operator()( Range rowRange, Range colRange ) const; |
RyoheiHagimoto | 0:0e0631af0305 | 1518 | |
RyoheiHagimoto | 0:0e0631af0305 | 1519 | /** @overload |
RyoheiHagimoto | 0:0e0631af0305 | 1520 | @param roi Extracted submatrix specified as a rectangle. |
RyoheiHagimoto | 0:0e0631af0305 | 1521 | */ |
RyoheiHagimoto | 0:0e0631af0305 | 1522 | Mat operator()( const Rect& roi ) const; |
RyoheiHagimoto | 0:0e0631af0305 | 1523 | |
RyoheiHagimoto | 0:0e0631af0305 | 1524 | /** @overload |
RyoheiHagimoto | 0:0e0631af0305 | 1525 | @param ranges Array of selected ranges along each array dimension. |
RyoheiHagimoto | 0:0e0631af0305 | 1526 | */ |
RyoheiHagimoto | 0:0e0631af0305 | 1527 | Mat operator()( const Range* ranges ) const; |
RyoheiHagimoto | 0:0e0631af0305 | 1528 | |
RyoheiHagimoto | 0:0e0631af0305 | 1529 | /** @overload |
RyoheiHagimoto | 0:0e0631af0305 | 1530 | @param ranges Array of selected ranges along each array dimension. |
RyoheiHagimoto | 0:0e0631af0305 | 1531 | */ |
RyoheiHagimoto | 0:0e0631af0305 | 1532 | Mat operator()(const std::vector<Range>& ranges) const; |
RyoheiHagimoto | 0:0e0631af0305 | 1533 | |
RyoheiHagimoto | 0:0e0631af0305 | 1534 | // //! converts header to CvMat; no data is copied |
RyoheiHagimoto | 0:0e0631af0305 | 1535 | // operator CvMat() const; |
RyoheiHagimoto | 0:0e0631af0305 | 1536 | // //! converts header to CvMatND; no data is copied |
RyoheiHagimoto | 0:0e0631af0305 | 1537 | // operator CvMatND() const; |
RyoheiHagimoto | 0:0e0631af0305 | 1538 | // //! converts header to IplImage; no data is copied |
RyoheiHagimoto | 0:0e0631af0305 | 1539 | // operator IplImage() const; |
RyoheiHagimoto | 0:0e0631af0305 | 1540 | |
RyoheiHagimoto | 0:0e0631af0305 | 1541 | template<typename _Tp> operator std::vector<_Tp>() const; |
RyoheiHagimoto | 0:0e0631af0305 | 1542 | template<typename _Tp, int n> operator Vec<_Tp, n>() const; |
RyoheiHagimoto | 0:0e0631af0305 | 1543 | template<typename _Tp, int m, int n> operator Matx<_Tp, m, n>() const; |
RyoheiHagimoto | 0:0e0631af0305 | 1544 | |
RyoheiHagimoto | 0:0e0631af0305 | 1545 | /** @brief Reports whether the matrix is continuous or not. |
RyoheiHagimoto | 0:0e0631af0305 | 1546 | |
RyoheiHagimoto | 0:0e0631af0305 | 1547 | The method returns true if the matrix elements are stored continuously without gaps at the end of |
RyoheiHagimoto | 0:0e0631af0305 | 1548 | each row. Otherwise, it returns false. Obviously, 1x1 or 1xN matrices are always continuous. |
RyoheiHagimoto | 0:0e0631af0305 | 1549 | Matrices created with Mat::create are always continuous. But if you extract a part of the matrix |
RyoheiHagimoto | 0:0e0631af0305 | 1550 | using Mat::col, Mat::diag, and so on, or constructed a matrix header for externally allocated data, |
RyoheiHagimoto | 0:0e0631af0305 | 1551 | such matrices may no longer have this property. |
RyoheiHagimoto | 0:0e0631af0305 | 1552 | |
RyoheiHagimoto | 0:0e0631af0305 | 1553 | The continuity flag is stored as a bit in the Mat::flags field and is computed automatically when |
RyoheiHagimoto | 0:0e0631af0305 | 1554 | you construct a matrix header. Thus, the continuity check is a very fast operation, though |
RyoheiHagimoto | 0:0e0631af0305 | 1555 | theoretically it could be done as follows: |
RyoheiHagimoto | 0:0e0631af0305 | 1556 | @code |
RyoheiHagimoto | 0:0e0631af0305 | 1557 | // alternative implementation of Mat::isContinuous() |
RyoheiHagimoto | 0:0e0631af0305 | 1558 | bool myCheckMatContinuity(const Mat& m) |
RyoheiHagimoto | 0:0e0631af0305 | 1559 | { |
RyoheiHagimoto | 0:0e0631af0305 | 1560 | //return (m.flags & Mat::CONTINUOUS_FLAG) != 0; |
RyoheiHagimoto | 0:0e0631af0305 | 1561 | return m.rows == 1 || m.step == m.cols*m.elemSize(); |
RyoheiHagimoto | 0:0e0631af0305 | 1562 | } |
RyoheiHagimoto | 0:0e0631af0305 | 1563 | @endcode |
RyoheiHagimoto | 0:0e0631af0305 | 1564 | The method is used in quite a few of OpenCV functions. The point is that element-wise operations |
RyoheiHagimoto | 0:0e0631af0305 | 1565 | (such as arithmetic and logical operations, math functions, alpha blending, color space |
RyoheiHagimoto | 0:0e0631af0305 | 1566 | transformations, and others) do not depend on the image geometry. Thus, if all the input and output |
RyoheiHagimoto | 0:0e0631af0305 | 1567 | arrays are continuous, the functions can process them as very long single-row vectors. The example |
RyoheiHagimoto | 0:0e0631af0305 | 1568 | below illustrates how an alpha-blending function can be implemented: |
RyoheiHagimoto | 0:0e0631af0305 | 1569 | @code |
RyoheiHagimoto | 0:0e0631af0305 | 1570 | template<typename T> |
RyoheiHagimoto | 0:0e0631af0305 | 1571 | void alphaBlendRGBA(const Mat& src1, const Mat& src2, Mat& dst) |
RyoheiHagimoto | 0:0e0631af0305 | 1572 | { |
RyoheiHagimoto | 0:0e0631af0305 | 1573 | const float alpha_scale = (float)std::numeric_limits<T>::max(), |
RyoheiHagimoto | 0:0e0631af0305 | 1574 | inv_scale = 1.f/alpha_scale; |
RyoheiHagimoto | 0:0e0631af0305 | 1575 | |
RyoheiHagimoto | 0:0e0631af0305 | 1576 | CV_Assert( src1.type() == src2.type() && |
RyoheiHagimoto | 0:0e0631af0305 | 1577 | src1.type() == CV_MAKETYPE(DataType<T>::depth, 4) && |
RyoheiHagimoto | 0:0e0631af0305 | 1578 | src1.size() == src2.size()); |
RyoheiHagimoto | 0:0e0631af0305 | 1579 | Size size = src1.size(); |
RyoheiHagimoto | 0:0e0631af0305 | 1580 | dst.create(size, src1.type()); |
RyoheiHagimoto | 0:0e0631af0305 | 1581 | |
RyoheiHagimoto | 0:0e0631af0305 | 1582 | // here is the idiom: check the arrays for continuity and, |
RyoheiHagimoto | 0:0e0631af0305 | 1583 | // if this is the case, |
RyoheiHagimoto | 0:0e0631af0305 | 1584 | // treat the arrays as 1D vectors |
RyoheiHagimoto | 0:0e0631af0305 | 1585 | if( src1.isContinuous() && src2.isContinuous() && dst.isContinuous() ) |
RyoheiHagimoto | 0:0e0631af0305 | 1586 | { |
RyoheiHagimoto | 0:0e0631af0305 | 1587 | size.width *= size.height; |
RyoheiHagimoto | 0:0e0631af0305 | 1588 | size.height = 1; |
RyoheiHagimoto | 0:0e0631af0305 | 1589 | } |
RyoheiHagimoto | 0:0e0631af0305 | 1590 | size.width *= 4; |
RyoheiHagimoto | 0:0e0631af0305 | 1591 | |
RyoheiHagimoto | 0:0e0631af0305 | 1592 | for( int i = 0; i < size.height; i++ ) |
RyoheiHagimoto | 0:0e0631af0305 | 1593 | { |
RyoheiHagimoto | 0:0e0631af0305 | 1594 | // when the arrays are continuous, |
RyoheiHagimoto | 0:0e0631af0305 | 1595 | // the outer loop is executed only once |
RyoheiHagimoto | 0:0e0631af0305 | 1596 | const T* ptr1 = src1.ptr<T>(i); |
RyoheiHagimoto | 0:0e0631af0305 | 1597 | const T* ptr2 = src2.ptr<T>(i); |
RyoheiHagimoto | 0:0e0631af0305 | 1598 | T* dptr = dst.ptr<T>(i); |
RyoheiHagimoto | 0:0e0631af0305 | 1599 | |
RyoheiHagimoto | 0:0e0631af0305 | 1600 | for( int j = 0; j < size.width; j += 4 ) |
RyoheiHagimoto | 0:0e0631af0305 | 1601 | { |
RyoheiHagimoto | 0:0e0631af0305 | 1602 | float alpha = ptr1[j+3]*inv_scale, beta = ptr2[j+3]*inv_scale; |
RyoheiHagimoto | 0:0e0631af0305 | 1603 | dptr[j] = saturate_cast<T>(ptr1[j]*alpha + ptr2[j]*beta); |
RyoheiHagimoto | 0:0e0631af0305 | 1604 | dptr[j+1] = saturate_cast<T>(ptr1[j+1]*alpha + ptr2[j+1]*beta); |
RyoheiHagimoto | 0:0e0631af0305 | 1605 | dptr[j+2] = saturate_cast<T>(ptr1[j+2]*alpha + ptr2[j+2]*beta); |
RyoheiHagimoto | 0:0e0631af0305 | 1606 | dptr[j+3] = saturate_cast<T>((1 - (1-alpha)*(1-beta))*alpha_scale); |
RyoheiHagimoto | 0:0e0631af0305 | 1607 | } |
RyoheiHagimoto | 0:0e0631af0305 | 1608 | } |
RyoheiHagimoto | 0:0e0631af0305 | 1609 | } |
RyoheiHagimoto | 0:0e0631af0305 | 1610 | @endcode |
RyoheiHagimoto | 0:0e0631af0305 | 1611 | This approach, while being very simple, can boost the performance of a simple element-operation by |
RyoheiHagimoto | 0:0e0631af0305 | 1612 | 10-20 percents, especially if the image is rather small and the operation is quite simple. |
RyoheiHagimoto | 0:0e0631af0305 | 1613 | |
RyoheiHagimoto | 0:0e0631af0305 | 1614 | Another OpenCV idiom in this function, a call of Mat::create for the destination array, that |
RyoheiHagimoto | 0:0e0631af0305 | 1615 | allocates the destination array unless it already has the proper size and type. And while the newly |
RyoheiHagimoto | 0:0e0631af0305 | 1616 | allocated arrays are always continuous, you still need to check the destination array because |
RyoheiHagimoto | 0:0e0631af0305 | 1617 | Mat::create does not always allocate a new matrix. |
RyoheiHagimoto | 0:0e0631af0305 | 1618 | */ |
RyoheiHagimoto | 0:0e0631af0305 | 1619 | bool isContinuous() const; |
RyoheiHagimoto | 0:0e0631af0305 | 1620 | |
RyoheiHagimoto | 0:0e0631af0305 | 1621 | //! returns true if the matrix is a submatrix of another matrix |
RyoheiHagimoto | 0:0e0631af0305 | 1622 | bool isSubmatrix() const; |
RyoheiHagimoto | 0:0e0631af0305 | 1623 | |
RyoheiHagimoto | 0:0e0631af0305 | 1624 | /** @brief Returns the matrix element size in bytes. |
RyoheiHagimoto | 0:0e0631af0305 | 1625 | |
RyoheiHagimoto | 0:0e0631af0305 | 1626 | The method returns the matrix element size in bytes. For example, if the matrix type is CV_16SC3 , |
RyoheiHagimoto | 0:0e0631af0305 | 1627 | the method returns 3\*sizeof(short) or 6. |
RyoheiHagimoto | 0:0e0631af0305 | 1628 | */ |
RyoheiHagimoto | 0:0e0631af0305 | 1629 | size_t elemSize() const; |
RyoheiHagimoto | 0:0e0631af0305 | 1630 | |
RyoheiHagimoto | 0:0e0631af0305 | 1631 | /** @brief Returns the size of each matrix element channel in bytes. |
RyoheiHagimoto | 0:0e0631af0305 | 1632 | |
RyoheiHagimoto | 0:0e0631af0305 | 1633 | The method returns the matrix element channel size in bytes, that is, it ignores the number of |
RyoheiHagimoto | 0:0e0631af0305 | 1634 | channels. For example, if the matrix type is CV_16SC3 , the method returns sizeof(short) or 2. |
RyoheiHagimoto | 0:0e0631af0305 | 1635 | */ |
RyoheiHagimoto | 0:0e0631af0305 | 1636 | size_t elemSize1() const; |
RyoheiHagimoto | 0:0e0631af0305 | 1637 | |
RyoheiHagimoto | 0:0e0631af0305 | 1638 | /** @brief Returns the type of a matrix element. |
RyoheiHagimoto | 0:0e0631af0305 | 1639 | |
RyoheiHagimoto | 0:0e0631af0305 | 1640 | The method returns a matrix element type. This is an identifier compatible with the CvMat type |
RyoheiHagimoto | 0:0e0631af0305 | 1641 | system, like CV_16SC3 or 16-bit signed 3-channel array, and so on. |
RyoheiHagimoto | 0:0e0631af0305 | 1642 | */ |
RyoheiHagimoto | 0:0e0631af0305 | 1643 | int type() const; |
RyoheiHagimoto | 0:0e0631af0305 | 1644 | |
RyoheiHagimoto | 0:0e0631af0305 | 1645 | /** @brief Returns the depth of a matrix element. |
RyoheiHagimoto | 0:0e0631af0305 | 1646 | |
RyoheiHagimoto | 0:0e0631af0305 | 1647 | The method returns the identifier of the matrix element depth (the type of each individual channel). |
RyoheiHagimoto | 0:0e0631af0305 | 1648 | For example, for a 16-bit signed element array, the method returns CV_16S . A complete list of |
RyoheiHagimoto | 0:0e0631af0305 | 1649 | matrix types contains the following values: |
RyoheiHagimoto | 0:0e0631af0305 | 1650 | - CV_8U - 8-bit unsigned integers ( 0..255 ) |
RyoheiHagimoto | 0:0e0631af0305 | 1651 | - CV_8S - 8-bit signed integers ( -128..127 ) |
RyoheiHagimoto | 0:0e0631af0305 | 1652 | - CV_16U - 16-bit unsigned integers ( 0..65535 ) |
RyoheiHagimoto | 0:0e0631af0305 | 1653 | - CV_16S - 16-bit signed integers ( -32768..32767 ) |
RyoheiHagimoto | 0:0e0631af0305 | 1654 | - CV_32S - 32-bit signed integers ( -2147483648..2147483647 ) |
RyoheiHagimoto | 0:0e0631af0305 | 1655 | - CV_32F - 32-bit floating-point numbers ( -FLT_MAX..FLT_MAX, INF, NAN ) |
RyoheiHagimoto | 0:0e0631af0305 | 1656 | - CV_64F - 64-bit floating-point numbers ( -DBL_MAX..DBL_MAX, INF, NAN ) |
RyoheiHagimoto | 0:0e0631af0305 | 1657 | */ |
RyoheiHagimoto | 0:0e0631af0305 | 1658 | int depth() const; |
RyoheiHagimoto | 0:0e0631af0305 | 1659 | |
RyoheiHagimoto | 0:0e0631af0305 | 1660 | /** @brief Returns the number of matrix channels. |
RyoheiHagimoto | 0:0e0631af0305 | 1661 | |
RyoheiHagimoto | 0:0e0631af0305 | 1662 | The method returns the number of matrix channels. |
RyoheiHagimoto | 0:0e0631af0305 | 1663 | */ |
RyoheiHagimoto | 0:0e0631af0305 | 1664 | int channels() const; |
RyoheiHagimoto | 0:0e0631af0305 | 1665 | |
RyoheiHagimoto | 0:0e0631af0305 | 1666 | /** @brief Returns a normalized step. |
RyoheiHagimoto | 0:0e0631af0305 | 1667 | |
RyoheiHagimoto | 0:0e0631af0305 | 1668 | The method returns a matrix step divided by Mat::elemSize1() . It can be useful to quickly access an |
RyoheiHagimoto | 0:0e0631af0305 | 1669 | arbitrary matrix element. |
RyoheiHagimoto | 0:0e0631af0305 | 1670 | */ |
RyoheiHagimoto | 0:0e0631af0305 | 1671 | size_t step1(int i=0) const; |
RyoheiHagimoto | 0:0e0631af0305 | 1672 | |
RyoheiHagimoto | 0:0e0631af0305 | 1673 | /** @brief Returns true if the array has no elements. |
RyoheiHagimoto | 0:0e0631af0305 | 1674 | |
RyoheiHagimoto | 0:0e0631af0305 | 1675 | The method returns true if Mat::total() is 0 or if Mat::data is NULL. Because of pop_back() and |
RyoheiHagimoto | 0:0e0631af0305 | 1676 | resize() methods `M.total() == 0` does not imply that `M.data == NULL`. |
RyoheiHagimoto | 0:0e0631af0305 | 1677 | */ |
RyoheiHagimoto | 0:0e0631af0305 | 1678 | bool empty() const; |
RyoheiHagimoto | 0:0e0631af0305 | 1679 | |
RyoheiHagimoto | 0:0e0631af0305 | 1680 | /** @brief Returns the total number of array elements. |
RyoheiHagimoto | 0:0e0631af0305 | 1681 | |
RyoheiHagimoto | 0:0e0631af0305 | 1682 | The method returns the number of array elements (a number of pixels if the array represents an |
RyoheiHagimoto | 0:0e0631af0305 | 1683 | image). |
RyoheiHagimoto | 0:0e0631af0305 | 1684 | */ |
RyoheiHagimoto | 0:0e0631af0305 | 1685 | size_t total() const; |
RyoheiHagimoto | 0:0e0631af0305 | 1686 | |
RyoheiHagimoto | 0:0e0631af0305 | 1687 | //! returns N if the matrix is 1-channel (N x ptdim) or ptdim-channel (1 x N) or (N x 1); negative number otherwise |
RyoheiHagimoto | 0:0e0631af0305 | 1688 | int checkVector(int elemChannels, int depth=-1, bool requireContinuous=true) const; |
RyoheiHagimoto | 0:0e0631af0305 | 1689 | |
RyoheiHagimoto | 0:0e0631af0305 | 1690 | /** @brief Returns a pointer to the specified matrix row. |
RyoheiHagimoto | 0:0e0631af0305 | 1691 | |
RyoheiHagimoto | 0:0e0631af0305 | 1692 | The methods return `uchar*` or typed pointer to the specified matrix row. See the sample in |
RyoheiHagimoto | 0:0e0631af0305 | 1693 | Mat::isContinuous to know how to use these methods. |
RyoheiHagimoto | 0:0e0631af0305 | 1694 | @param i0 A 0-based row index. |
RyoheiHagimoto | 0:0e0631af0305 | 1695 | */ |
RyoheiHagimoto | 0:0e0631af0305 | 1696 | uchar* ptr(int i0=0); |
RyoheiHagimoto | 0:0e0631af0305 | 1697 | /** @overload */ |
RyoheiHagimoto | 0:0e0631af0305 | 1698 | const uchar* ptr(int i0=0) const; |
RyoheiHagimoto | 0:0e0631af0305 | 1699 | |
RyoheiHagimoto | 0:0e0631af0305 | 1700 | /** @overload |
RyoheiHagimoto | 0:0e0631af0305 | 1701 | @param row Index along the dimension 0 |
RyoheiHagimoto | 0:0e0631af0305 | 1702 | @param col Index along the dimension 1 |
RyoheiHagimoto | 0:0e0631af0305 | 1703 | */ |
RyoheiHagimoto | 0:0e0631af0305 | 1704 | uchar* ptr(int row, int col); |
RyoheiHagimoto | 0:0e0631af0305 | 1705 | /** @overload |
RyoheiHagimoto | 0:0e0631af0305 | 1706 | @param row Index along the dimension 0 |
RyoheiHagimoto | 0:0e0631af0305 | 1707 | @param col Index along the dimension 1 |
RyoheiHagimoto | 0:0e0631af0305 | 1708 | */ |
RyoheiHagimoto | 0:0e0631af0305 | 1709 | const uchar* ptr(int row, int col) const; |
RyoheiHagimoto | 0:0e0631af0305 | 1710 | |
RyoheiHagimoto | 0:0e0631af0305 | 1711 | /** @overload */ |
RyoheiHagimoto | 0:0e0631af0305 | 1712 | uchar* ptr(int i0, int i1, int i2); |
RyoheiHagimoto | 0:0e0631af0305 | 1713 | /** @overload */ |
RyoheiHagimoto | 0:0e0631af0305 | 1714 | const uchar* ptr(int i0, int i1, int i2) const; |
RyoheiHagimoto | 0:0e0631af0305 | 1715 | |
RyoheiHagimoto | 0:0e0631af0305 | 1716 | /** @overload */ |
RyoheiHagimoto | 0:0e0631af0305 | 1717 | uchar* ptr(const int* idx); |
RyoheiHagimoto | 0:0e0631af0305 | 1718 | /** @overload */ |
RyoheiHagimoto | 0:0e0631af0305 | 1719 | const uchar* ptr(const int* idx) const; |
RyoheiHagimoto | 0:0e0631af0305 | 1720 | /** @overload */ |
RyoheiHagimoto | 0:0e0631af0305 | 1721 | template<int n> uchar* ptr(const Vec<int, n>& idx); |
RyoheiHagimoto | 0:0e0631af0305 | 1722 | /** @overload */ |
RyoheiHagimoto | 0:0e0631af0305 | 1723 | template<int n> const uchar* ptr(const Vec<int, n>& idx) const; |
RyoheiHagimoto | 0:0e0631af0305 | 1724 | |
RyoheiHagimoto | 0:0e0631af0305 | 1725 | /** @overload */ |
RyoheiHagimoto | 0:0e0631af0305 | 1726 | template<typename _Tp> _Tp* ptr(int i0=0); |
RyoheiHagimoto | 0:0e0631af0305 | 1727 | /** @overload */ |
RyoheiHagimoto | 0:0e0631af0305 | 1728 | template<typename _Tp> const _Tp* ptr(int i0=0) const; |
RyoheiHagimoto | 0:0e0631af0305 | 1729 | /** @overload |
RyoheiHagimoto | 0:0e0631af0305 | 1730 | @param row Index along the dimension 0 |
RyoheiHagimoto | 0:0e0631af0305 | 1731 | @param col Index along the dimension 1 |
RyoheiHagimoto | 0:0e0631af0305 | 1732 | */ |
RyoheiHagimoto | 0:0e0631af0305 | 1733 | template<typename _Tp> _Tp* ptr(int row, int col); |
RyoheiHagimoto | 0:0e0631af0305 | 1734 | /** @overload |
RyoheiHagimoto | 0:0e0631af0305 | 1735 | @param row Index along the dimension 0 |
RyoheiHagimoto | 0:0e0631af0305 | 1736 | @param col Index along the dimension 1 |
RyoheiHagimoto | 0:0e0631af0305 | 1737 | */ |
RyoheiHagimoto | 0:0e0631af0305 | 1738 | template<typename _Tp> const _Tp* ptr(int row, int col) const; |
RyoheiHagimoto | 0:0e0631af0305 | 1739 | /** @overload */ |
RyoheiHagimoto | 0:0e0631af0305 | 1740 | template<typename _Tp> _Tp* ptr(int i0, int i1, int i2); |
RyoheiHagimoto | 0:0e0631af0305 | 1741 | /** @overload */ |
RyoheiHagimoto | 0:0e0631af0305 | 1742 | template<typename _Tp> const _Tp* ptr(int i0, int i1, int i2) const; |
RyoheiHagimoto | 0:0e0631af0305 | 1743 | /** @overload */ |
RyoheiHagimoto | 0:0e0631af0305 | 1744 | template<typename _Tp> _Tp* ptr(const int* idx); |
RyoheiHagimoto | 0:0e0631af0305 | 1745 | /** @overload */ |
RyoheiHagimoto | 0:0e0631af0305 | 1746 | template<typename _Tp> const _Tp* ptr(const int* idx) const; |
RyoheiHagimoto | 0:0e0631af0305 | 1747 | /** @overload */ |
RyoheiHagimoto | 0:0e0631af0305 | 1748 | template<typename _Tp, int n> _Tp* ptr(const Vec<int, n>& idx); |
RyoheiHagimoto | 0:0e0631af0305 | 1749 | /** @overload */ |
RyoheiHagimoto | 0:0e0631af0305 | 1750 | template<typename _Tp, int n> const _Tp* ptr(const Vec<int, n>& idx) const; |
RyoheiHagimoto | 0:0e0631af0305 | 1751 | |
RyoheiHagimoto | 0:0e0631af0305 | 1752 | /** @brief Returns a reference to the specified array element. |
RyoheiHagimoto | 0:0e0631af0305 | 1753 | |
RyoheiHagimoto | 0:0e0631af0305 | 1754 | The template methods return a reference to the specified array element. For the sake of higher |
RyoheiHagimoto | 0:0e0631af0305 | 1755 | performance, the index range checks are only performed in the Debug configuration. |
RyoheiHagimoto | 0:0e0631af0305 | 1756 | |
RyoheiHagimoto | 0:0e0631af0305 | 1757 | Note that the variants with a single index (i) can be used to access elements of single-row or |
RyoheiHagimoto | 0:0e0631af0305 | 1758 | single-column 2-dimensional arrays. That is, if, for example, A is a 1 x N floating-point matrix and |
RyoheiHagimoto | 0:0e0631af0305 | 1759 | B is an M x 1 integer matrix, you can simply write `A.at<float>(k+4)` and `B.at<int>(2*i+1)` |
RyoheiHagimoto | 0:0e0631af0305 | 1760 | instead of `A.at<float>(0,k+4)` and `B.at<int>(2*i+1,0)`, respectively. |
RyoheiHagimoto | 0:0e0631af0305 | 1761 | |
RyoheiHagimoto | 0:0e0631af0305 | 1762 | The example below initializes a Hilbert matrix: |
RyoheiHagimoto | 0:0e0631af0305 | 1763 | @code |
RyoheiHagimoto | 0:0e0631af0305 | 1764 | Mat H(100, 100, CV_64F); |
RyoheiHagimoto | 0:0e0631af0305 | 1765 | for(int i = 0; i < H.rows; i++) |
RyoheiHagimoto | 0:0e0631af0305 | 1766 | for(int j = 0; j < H.cols; j++) |
RyoheiHagimoto | 0:0e0631af0305 | 1767 | H.at<double>(i,j)=1./(i+j+1); |
RyoheiHagimoto | 0:0e0631af0305 | 1768 | @endcode |
RyoheiHagimoto | 0:0e0631af0305 | 1769 | |
RyoheiHagimoto | 0:0e0631af0305 | 1770 | Keep in mind that the size identifier used in the at operator cannot be chosen at random. It depends |
RyoheiHagimoto | 0:0e0631af0305 | 1771 | on the image from which you are trying to retrieve the data. The table below gives a better insight in this: |
RyoheiHagimoto | 0:0e0631af0305 | 1772 | - If matrix is of type `CV_8U` then use `Mat.at<uchar>(y,x)`. |
RyoheiHagimoto | 0:0e0631af0305 | 1773 | - If matrix is of type `CV_8S` then use `Mat.at<schar>(y,x)`. |
RyoheiHagimoto | 0:0e0631af0305 | 1774 | - If matrix is of type `CV_16U` then use `Mat.at<ushort>(y,x)`. |
RyoheiHagimoto | 0:0e0631af0305 | 1775 | - If matrix is of type `CV_16S` then use `Mat.at<short>(y,x)`. |
RyoheiHagimoto | 0:0e0631af0305 | 1776 | - If matrix is of type `CV_32S` then use `Mat.at<int>(y,x)`. |
RyoheiHagimoto | 0:0e0631af0305 | 1777 | - If matrix is of type `CV_32F` then use `Mat.at<float>(y,x)`. |
RyoheiHagimoto | 0:0e0631af0305 | 1778 | - If matrix is of type `CV_64F` then use `Mat.at<double>(y,x)`. |
RyoheiHagimoto | 0:0e0631af0305 | 1779 | |
RyoheiHagimoto | 0:0e0631af0305 | 1780 | @param i0 Index along the dimension 0 |
RyoheiHagimoto | 0:0e0631af0305 | 1781 | */ |
RyoheiHagimoto | 0:0e0631af0305 | 1782 | template<typename _Tp> _Tp& at(int i0=0); |
RyoheiHagimoto | 0:0e0631af0305 | 1783 | /** @overload |
RyoheiHagimoto | 0:0e0631af0305 | 1784 | @param i0 Index along the dimension 0 |
RyoheiHagimoto | 0:0e0631af0305 | 1785 | */ |
RyoheiHagimoto | 0:0e0631af0305 | 1786 | template<typename _Tp> const _Tp& at(int i0=0) const; |
RyoheiHagimoto | 0:0e0631af0305 | 1787 | /** @overload |
RyoheiHagimoto | 0:0e0631af0305 | 1788 | @param row Index along the dimension 0 |
RyoheiHagimoto | 0:0e0631af0305 | 1789 | @param col Index along the dimension 1 |
RyoheiHagimoto | 0:0e0631af0305 | 1790 | */ |
RyoheiHagimoto | 0:0e0631af0305 | 1791 | template<typename _Tp> _Tp& at(int row, int col); |
RyoheiHagimoto | 0:0e0631af0305 | 1792 | /** @overload |
RyoheiHagimoto | 0:0e0631af0305 | 1793 | @param row Index along the dimension 0 |
RyoheiHagimoto | 0:0e0631af0305 | 1794 | @param col Index along the dimension 1 |
RyoheiHagimoto | 0:0e0631af0305 | 1795 | */ |
RyoheiHagimoto | 0:0e0631af0305 | 1796 | template<typename _Tp> const _Tp& at(int row, int col) const; |
RyoheiHagimoto | 0:0e0631af0305 | 1797 | |
RyoheiHagimoto | 0:0e0631af0305 | 1798 | /** @overload |
RyoheiHagimoto | 0:0e0631af0305 | 1799 | @param i0 Index along the dimension 0 |
RyoheiHagimoto | 0:0e0631af0305 | 1800 | @param i1 Index along the dimension 1 |
RyoheiHagimoto | 0:0e0631af0305 | 1801 | @param i2 Index along the dimension 2 |
RyoheiHagimoto | 0:0e0631af0305 | 1802 | */ |
RyoheiHagimoto | 0:0e0631af0305 | 1803 | template<typename _Tp> _Tp& at(int i0, int i1, int i2); |
RyoheiHagimoto | 0:0e0631af0305 | 1804 | /** @overload |
RyoheiHagimoto | 0:0e0631af0305 | 1805 | @param i0 Index along the dimension 0 |
RyoheiHagimoto | 0:0e0631af0305 | 1806 | @param i1 Index along the dimension 1 |
RyoheiHagimoto | 0:0e0631af0305 | 1807 | @param i2 Index along the dimension 2 |
RyoheiHagimoto | 0:0e0631af0305 | 1808 | */ |
RyoheiHagimoto | 0:0e0631af0305 | 1809 | template<typename _Tp> const _Tp& at(int i0, int i1, int i2) const; |
RyoheiHagimoto | 0:0e0631af0305 | 1810 | |
RyoheiHagimoto | 0:0e0631af0305 | 1811 | /** @overload |
RyoheiHagimoto | 0:0e0631af0305 | 1812 | @param idx Array of Mat::dims indices. |
RyoheiHagimoto | 0:0e0631af0305 | 1813 | */ |
RyoheiHagimoto | 0:0e0631af0305 | 1814 | template<typename _Tp> _Tp& at(const int* idx); |
RyoheiHagimoto | 0:0e0631af0305 | 1815 | /** @overload |
RyoheiHagimoto | 0:0e0631af0305 | 1816 | @param idx Array of Mat::dims indices. |
RyoheiHagimoto | 0:0e0631af0305 | 1817 | */ |
RyoheiHagimoto | 0:0e0631af0305 | 1818 | template<typename _Tp> const _Tp& at(const int* idx) const; |
RyoheiHagimoto | 0:0e0631af0305 | 1819 | |
RyoheiHagimoto | 0:0e0631af0305 | 1820 | /** @overload */ |
RyoheiHagimoto | 0:0e0631af0305 | 1821 | template<typename _Tp, int n> _Tp& at(const Vec<int, n>& idx); |
RyoheiHagimoto | 0:0e0631af0305 | 1822 | /** @overload */ |
RyoheiHagimoto | 0:0e0631af0305 | 1823 | template<typename _Tp, int n> const _Tp& at(const Vec<int, n>& idx) const; |
RyoheiHagimoto | 0:0e0631af0305 | 1824 | |
RyoheiHagimoto | 0:0e0631af0305 | 1825 | /** @overload |
RyoheiHagimoto | 0:0e0631af0305 | 1826 | special versions for 2D arrays (especially convenient for referencing image pixels) |
RyoheiHagimoto | 0:0e0631af0305 | 1827 | @param pt Element position specified as Point(j,i) . |
RyoheiHagimoto | 0:0e0631af0305 | 1828 | */ |
RyoheiHagimoto | 0:0e0631af0305 | 1829 | template<typename _Tp> _Tp& at(Point pt); |
RyoheiHagimoto | 0:0e0631af0305 | 1830 | /** @overload |
RyoheiHagimoto | 0:0e0631af0305 | 1831 | special versions for 2D arrays (especially convenient for referencing image pixels) |
RyoheiHagimoto | 0:0e0631af0305 | 1832 | @param pt Element position specified as Point(j,i) . |
RyoheiHagimoto | 0:0e0631af0305 | 1833 | */ |
RyoheiHagimoto | 0:0e0631af0305 | 1834 | template<typename _Tp> const _Tp& at(Point pt) const; |
RyoheiHagimoto | 0:0e0631af0305 | 1835 | |
RyoheiHagimoto | 0:0e0631af0305 | 1836 | /** @brief Returns the matrix iterator and sets it to the first matrix element. |
RyoheiHagimoto | 0:0e0631af0305 | 1837 | |
RyoheiHagimoto | 0:0e0631af0305 | 1838 | The methods return the matrix read-only or read-write iterators. The use of matrix iterators is very |
RyoheiHagimoto | 0:0e0631af0305 | 1839 | similar to the use of bi-directional STL iterators. In the example below, the alpha blending |
RyoheiHagimoto | 0:0e0631af0305 | 1840 | function is rewritten using the matrix iterators: |
RyoheiHagimoto | 0:0e0631af0305 | 1841 | @code |
RyoheiHagimoto | 0:0e0631af0305 | 1842 | template<typename T> |
RyoheiHagimoto | 0:0e0631af0305 | 1843 | void alphaBlendRGBA(const Mat& src1, const Mat& src2, Mat& dst) |
RyoheiHagimoto | 0:0e0631af0305 | 1844 | { |
RyoheiHagimoto | 0:0e0631af0305 | 1845 | typedef Vec<T, 4> VT; |
RyoheiHagimoto | 0:0e0631af0305 | 1846 | |
RyoheiHagimoto | 0:0e0631af0305 | 1847 | const float alpha_scale = (float)std::numeric_limits<T>::max(), |
RyoheiHagimoto | 0:0e0631af0305 | 1848 | inv_scale = 1.f/alpha_scale; |
RyoheiHagimoto | 0:0e0631af0305 | 1849 | |
RyoheiHagimoto | 0:0e0631af0305 | 1850 | CV_Assert( src1.type() == src2.type() && |
RyoheiHagimoto | 0:0e0631af0305 | 1851 | src1.type() == DataType<VT>::type && |
RyoheiHagimoto | 0:0e0631af0305 | 1852 | src1.size() == src2.size()); |
RyoheiHagimoto | 0:0e0631af0305 | 1853 | Size size = src1.size(); |
RyoheiHagimoto | 0:0e0631af0305 | 1854 | dst.create(size, src1.type()); |
RyoheiHagimoto | 0:0e0631af0305 | 1855 | |
RyoheiHagimoto | 0:0e0631af0305 | 1856 | MatConstIterator_<VT> it1 = src1.begin<VT>(), it1_end = src1.end<VT>(); |
RyoheiHagimoto | 0:0e0631af0305 | 1857 | MatConstIterator_<VT> it2 = src2.begin<VT>(); |
RyoheiHagimoto | 0:0e0631af0305 | 1858 | MatIterator_<VT> dst_it = dst.begin<VT>(); |
RyoheiHagimoto | 0:0e0631af0305 | 1859 | |
RyoheiHagimoto | 0:0e0631af0305 | 1860 | for( ; it1 != it1_end; ++it1, ++it2, ++dst_it ) |
RyoheiHagimoto | 0:0e0631af0305 | 1861 | { |
RyoheiHagimoto | 0:0e0631af0305 | 1862 | VT pix1 = *it1, pix2 = *it2; |
RyoheiHagimoto | 0:0e0631af0305 | 1863 | float alpha = pix1[3]*inv_scale, beta = pix2[3]*inv_scale; |
RyoheiHagimoto | 0:0e0631af0305 | 1864 | *dst_it = VT(saturate_cast<T>(pix1[0]*alpha + pix2[0]*beta), |
RyoheiHagimoto | 0:0e0631af0305 | 1865 | saturate_cast<T>(pix1[1]*alpha + pix2[1]*beta), |
RyoheiHagimoto | 0:0e0631af0305 | 1866 | saturate_cast<T>(pix1[2]*alpha + pix2[2]*beta), |
RyoheiHagimoto | 0:0e0631af0305 | 1867 | saturate_cast<T>((1 - (1-alpha)*(1-beta))*alpha_scale)); |
RyoheiHagimoto | 0:0e0631af0305 | 1868 | } |
RyoheiHagimoto | 0:0e0631af0305 | 1869 | } |
RyoheiHagimoto | 0:0e0631af0305 | 1870 | @endcode |
RyoheiHagimoto | 0:0e0631af0305 | 1871 | */ |
RyoheiHagimoto | 0:0e0631af0305 | 1872 | template<typename _Tp> MatIterator_<_Tp> begin(); |
RyoheiHagimoto | 0:0e0631af0305 | 1873 | template<typename _Tp> MatConstIterator_<_Tp> begin() const; |
RyoheiHagimoto | 0:0e0631af0305 | 1874 | |
RyoheiHagimoto | 0:0e0631af0305 | 1875 | /** @brief Returns the matrix iterator and sets it to the after-last matrix element. |
RyoheiHagimoto | 0:0e0631af0305 | 1876 | |
RyoheiHagimoto | 0:0e0631af0305 | 1877 | The methods return the matrix read-only or read-write iterators, set to the point following the last |
RyoheiHagimoto | 0:0e0631af0305 | 1878 | matrix element. |
RyoheiHagimoto | 0:0e0631af0305 | 1879 | */ |
RyoheiHagimoto | 0:0e0631af0305 | 1880 | template<typename _Tp> MatIterator_<_Tp> end(); |
RyoheiHagimoto | 0:0e0631af0305 | 1881 | template<typename _Tp> MatConstIterator_<_Tp> end() const; |
RyoheiHagimoto | 0:0e0631af0305 | 1882 | |
RyoheiHagimoto | 0:0e0631af0305 | 1883 | /** @brief Runs the given functor over all matrix elements in parallel. |
RyoheiHagimoto | 0:0e0631af0305 | 1884 | |
RyoheiHagimoto | 0:0e0631af0305 | 1885 | The operation passed as argument has to be a function pointer, a function object or a lambda(C++11). |
RyoheiHagimoto | 0:0e0631af0305 | 1886 | |
RyoheiHagimoto | 0:0e0631af0305 | 1887 | Example 1. All of the operations below put 0xFF the first channel of all matrix elements: |
RyoheiHagimoto | 0:0e0631af0305 | 1888 | @code |
RyoheiHagimoto | 0:0e0631af0305 | 1889 | Mat image(1920, 1080, CV_8UC3); |
RyoheiHagimoto | 0:0e0631af0305 | 1890 | typedef cv::Point3_<uint8_t> Pixel; |
RyoheiHagimoto | 0:0e0631af0305 | 1891 | |
RyoheiHagimoto | 0:0e0631af0305 | 1892 | // first. raw pointer access. |
RyoheiHagimoto | 0:0e0631af0305 | 1893 | for (int r = 0; r < image.rows; ++r) { |
RyoheiHagimoto | 0:0e0631af0305 | 1894 | Pixel* ptr = image.ptr<Pixel>(0, r); |
RyoheiHagimoto | 0:0e0631af0305 | 1895 | const Pixel* ptr_end = ptr + image.cols; |
RyoheiHagimoto | 0:0e0631af0305 | 1896 | for (; ptr != ptr_end; ++ptr) { |
RyoheiHagimoto | 0:0e0631af0305 | 1897 | ptr->x = 255; |
RyoheiHagimoto | 0:0e0631af0305 | 1898 | } |
RyoheiHagimoto | 0:0e0631af0305 | 1899 | } |
RyoheiHagimoto | 0:0e0631af0305 | 1900 | |
RyoheiHagimoto | 0:0e0631af0305 | 1901 | // Using MatIterator. (Simple but there are a Iterator's overhead) |
RyoheiHagimoto | 0:0e0631af0305 | 1902 | for (Pixel &p : cv::Mat_<Pixel>(image)) { |
RyoheiHagimoto | 0:0e0631af0305 | 1903 | p.x = 255; |
RyoheiHagimoto | 0:0e0631af0305 | 1904 | } |
RyoheiHagimoto | 0:0e0631af0305 | 1905 | |
RyoheiHagimoto | 0:0e0631af0305 | 1906 | // Parallel execution with function object. |
RyoheiHagimoto | 0:0e0631af0305 | 1907 | struct Operator { |
RyoheiHagimoto | 0:0e0631af0305 | 1908 | void operator ()(Pixel &pixel, const int * position) { |
RyoheiHagimoto | 0:0e0631af0305 | 1909 | pixel.x = 255; |
RyoheiHagimoto | 0:0e0631af0305 | 1910 | } |
RyoheiHagimoto | 0:0e0631af0305 | 1911 | }; |
RyoheiHagimoto | 0:0e0631af0305 | 1912 | image.forEach<Pixel>(Operator()); |
RyoheiHagimoto | 0:0e0631af0305 | 1913 | |
RyoheiHagimoto | 0:0e0631af0305 | 1914 | // Parallel execution using C++11 lambda. |
RyoheiHagimoto | 0:0e0631af0305 | 1915 | image.forEach<Pixel>([](Pixel &p, const int * position) -> void { |
RyoheiHagimoto | 0:0e0631af0305 | 1916 | p.x = 255; |
RyoheiHagimoto | 0:0e0631af0305 | 1917 | }); |
RyoheiHagimoto | 0:0e0631af0305 | 1918 | @endcode |
RyoheiHagimoto | 0:0e0631af0305 | 1919 | Example 2. Using the pixel's position: |
RyoheiHagimoto | 0:0e0631af0305 | 1920 | @code |
RyoheiHagimoto | 0:0e0631af0305 | 1921 | // Creating 3D matrix (255 x 255 x 255) typed uint8_t |
RyoheiHagimoto | 0:0e0631af0305 | 1922 | // and initialize all elements by the value which equals elements position. |
RyoheiHagimoto | 0:0e0631af0305 | 1923 | // i.e. pixels (x,y,z) = (1,2,3) is (b,g,r) = (1,2,3). |
RyoheiHagimoto | 0:0e0631af0305 | 1924 | |
RyoheiHagimoto | 0:0e0631af0305 | 1925 | int sizes[] = { 255, 255, 255 }; |
RyoheiHagimoto | 0:0e0631af0305 | 1926 | typedef cv::Point3_<uint8_t> Pixel; |
RyoheiHagimoto | 0:0e0631af0305 | 1927 | |
RyoheiHagimoto | 0:0e0631af0305 | 1928 | Mat_<Pixel> image = Mat::zeros(3, sizes, CV_8UC3); |
RyoheiHagimoto | 0:0e0631af0305 | 1929 | |
RyoheiHagimoto | 0:0e0631af0305 | 1930 | image.forEach<Pixel>([&](Pixel& pixel, const int position[]) -> void { |
RyoheiHagimoto | 0:0e0631af0305 | 1931 | pixel.x = position[0]; |
RyoheiHagimoto | 0:0e0631af0305 | 1932 | pixel.y = position[1]; |
RyoheiHagimoto | 0:0e0631af0305 | 1933 | pixel.z = position[2]; |
RyoheiHagimoto | 0:0e0631af0305 | 1934 | }); |
RyoheiHagimoto | 0:0e0631af0305 | 1935 | @endcode |
RyoheiHagimoto | 0:0e0631af0305 | 1936 | */ |
RyoheiHagimoto | 0:0e0631af0305 | 1937 | template<typename _Tp, typename Functor> void forEach(const Functor& operation); |
RyoheiHagimoto | 0:0e0631af0305 | 1938 | /** @overload */ |
RyoheiHagimoto | 0:0e0631af0305 | 1939 | template<typename _Tp, typename Functor> void forEach(const Functor& operation) const; |
RyoheiHagimoto | 0:0e0631af0305 | 1940 | |
RyoheiHagimoto | 0:0e0631af0305 | 1941 | #ifdef CV_CXX_MOVE_SEMANTICS |
RyoheiHagimoto | 0:0e0631af0305 | 1942 | Mat(Mat&& m); |
RyoheiHagimoto | 0:0e0631af0305 | 1943 | Mat& operator = (Mat&& m); |
RyoheiHagimoto | 0:0e0631af0305 | 1944 | #endif |
RyoheiHagimoto | 0:0e0631af0305 | 1945 | |
RyoheiHagimoto | 0:0e0631af0305 | 1946 | enum { MAGIC_VAL = 0x42FF0000, AUTO_STEP = 0, CONTINUOUS_FLAG = CV_MAT_CONT_FLAG, SUBMATRIX_FLAG = CV_SUBMAT_FLAG }; |
RyoheiHagimoto | 0:0e0631af0305 | 1947 | enum { MAGIC_MASK = 0xFFFF0000, TYPE_MASK = 0x00000FFF, DEPTH_MASK = 7 }; |
RyoheiHagimoto | 0:0e0631af0305 | 1948 | |
RyoheiHagimoto | 0:0e0631af0305 | 1949 | /*! includes several bit-fields: |
RyoheiHagimoto | 0:0e0631af0305 | 1950 | - the magic signature |
RyoheiHagimoto | 0:0e0631af0305 | 1951 | - continuity flag |
RyoheiHagimoto | 0:0e0631af0305 | 1952 | - depth |
RyoheiHagimoto | 0:0e0631af0305 | 1953 | - number of channels |
RyoheiHagimoto | 0:0e0631af0305 | 1954 | */ |
RyoheiHagimoto | 0:0e0631af0305 | 1955 | int flags; |
RyoheiHagimoto | 0:0e0631af0305 | 1956 | //! the matrix dimensionality, >= 2 |
RyoheiHagimoto | 0:0e0631af0305 | 1957 | int dims; |
RyoheiHagimoto | 0:0e0631af0305 | 1958 | //! the number of rows and columns or (-1, -1) when the matrix has more than 2 dimensions |
RyoheiHagimoto | 0:0e0631af0305 | 1959 | int rows, cols; |
RyoheiHagimoto | 0:0e0631af0305 | 1960 | //! pointer to the data |
RyoheiHagimoto | 0:0e0631af0305 | 1961 | uchar* data; |
RyoheiHagimoto | 0:0e0631af0305 | 1962 | |
RyoheiHagimoto | 0:0e0631af0305 | 1963 | //! helper fields used in locateROI and adjustROI |
RyoheiHagimoto | 0:0e0631af0305 | 1964 | const uchar* datastart; |
RyoheiHagimoto | 0:0e0631af0305 | 1965 | const uchar* dataend; |
RyoheiHagimoto | 0:0e0631af0305 | 1966 | const uchar* datalimit; |
RyoheiHagimoto | 0:0e0631af0305 | 1967 | |
RyoheiHagimoto | 0:0e0631af0305 | 1968 | //! custom allocator |
RyoheiHagimoto | 0:0e0631af0305 | 1969 | MatAllocator* allocator; |
RyoheiHagimoto | 0:0e0631af0305 | 1970 | //! and the standard allocator |
RyoheiHagimoto | 0:0e0631af0305 | 1971 | static MatAllocator* getStdAllocator(); |
RyoheiHagimoto | 0:0e0631af0305 | 1972 | static MatAllocator* getDefaultAllocator(); |
RyoheiHagimoto | 0:0e0631af0305 | 1973 | static void setDefaultAllocator(MatAllocator* allocator); |
RyoheiHagimoto | 0:0e0631af0305 | 1974 | |
RyoheiHagimoto | 0:0e0631af0305 | 1975 | //! interaction with UMat |
RyoheiHagimoto | 0:0e0631af0305 | 1976 | UMatData* u; |
RyoheiHagimoto | 0:0e0631af0305 | 1977 | |
RyoheiHagimoto | 0:0e0631af0305 | 1978 | MatSize size; |
RyoheiHagimoto | 0:0e0631af0305 | 1979 | MatStep step; |
RyoheiHagimoto | 0:0e0631af0305 | 1980 | |
RyoheiHagimoto | 0:0e0631af0305 | 1981 | protected: |
RyoheiHagimoto | 0:0e0631af0305 | 1982 | template<typename _Tp, typename Functor> void forEach_impl(const Functor& operation); |
RyoheiHagimoto | 0:0e0631af0305 | 1983 | }; |
RyoheiHagimoto | 0:0e0631af0305 | 1984 | |
RyoheiHagimoto | 0:0e0631af0305 | 1985 | |
RyoheiHagimoto | 0:0e0631af0305 | 1986 | ///////////////////////////////// Mat_<_Tp> //////////////////////////////////// |
RyoheiHagimoto | 0:0e0631af0305 | 1987 | |
RyoheiHagimoto | 0:0e0631af0305 | 1988 | /** @brief Template matrix class derived from Mat |
RyoheiHagimoto | 0:0e0631af0305 | 1989 | |
RyoheiHagimoto | 0:0e0631af0305 | 1990 | @code |
RyoheiHagimoto | 0:0e0631af0305 | 1991 | template<typename _Tp> class Mat_ : public Mat |
RyoheiHagimoto | 0:0e0631af0305 | 1992 | { |
RyoheiHagimoto | 0:0e0631af0305 | 1993 | public: |
RyoheiHagimoto | 0:0e0631af0305 | 1994 | // ... some specific methods |
RyoheiHagimoto | 0:0e0631af0305 | 1995 | // and |
RyoheiHagimoto | 0:0e0631af0305 | 1996 | // no new extra fields |
RyoheiHagimoto | 0:0e0631af0305 | 1997 | }; |
RyoheiHagimoto | 0:0e0631af0305 | 1998 | @endcode |
RyoheiHagimoto | 0:0e0631af0305 | 1999 | The class `Mat_<_Tp>` is a *thin* template wrapper on top of the Mat class. It does not have any |
RyoheiHagimoto | 0:0e0631af0305 | 2000 | extra data fields. Nor this class nor Mat has any virtual methods. Thus, references or pointers to |
RyoheiHagimoto | 0:0e0631af0305 | 2001 | these two classes can be freely but carefully converted one to another. For example: |
RyoheiHagimoto | 0:0e0631af0305 | 2002 | @code |
RyoheiHagimoto | 0:0e0631af0305 | 2003 | // create a 100x100 8-bit matrix |
RyoheiHagimoto | 0:0e0631af0305 | 2004 | Mat M(100,100,CV_8U); |
RyoheiHagimoto | 0:0e0631af0305 | 2005 | // this will be compiled fine. no any data conversion will be done. |
RyoheiHagimoto | 0:0e0631af0305 | 2006 | Mat_<float>& M1 = (Mat_<float>&)M; |
RyoheiHagimoto | 0:0e0631af0305 | 2007 | // the program is likely to crash at the statement below |
RyoheiHagimoto | 0:0e0631af0305 | 2008 | M1(99,99) = 1.f; |
RyoheiHagimoto | 0:0e0631af0305 | 2009 | @endcode |
RyoheiHagimoto | 0:0e0631af0305 | 2010 | While Mat is sufficient in most cases, Mat_ can be more convenient if you use a lot of element |
RyoheiHagimoto | 0:0e0631af0305 | 2011 | access operations and if you know matrix type at the compilation time. Note that |
RyoheiHagimoto | 0:0e0631af0305 | 2012 | `Mat::at(int y,int x)` and `Mat_::operator()(int y,int x)` do absolutely the same |
RyoheiHagimoto | 0:0e0631af0305 | 2013 | and run at the same speed, but the latter is certainly shorter: |
RyoheiHagimoto | 0:0e0631af0305 | 2014 | @code |
RyoheiHagimoto | 0:0e0631af0305 | 2015 | Mat_<double> M(20,20); |
RyoheiHagimoto | 0:0e0631af0305 | 2016 | for(int i = 0; i < M.rows; i++) |
RyoheiHagimoto | 0:0e0631af0305 | 2017 | for(int j = 0; j < M.cols; j++) |
RyoheiHagimoto | 0:0e0631af0305 | 2018 | M(i,j) = 1./(i+j+1); |
RyoheiHagimoto | 0:0e0631af0305 | 2019 | Mat E, V; |
RyoheiHagimoto | 0:0e0631af0305 | 2020 | eigen(M,E,V); |
RyoheiHagimoto | 0:0e0631af0305 | 2021 | cout << E.at<double>(0,0)/E.at<double>(M.rows-1,0); |
RyoheiHagimoto | 0:0e0631af0305 | 2022 | @endcode |
RyoheiHagimoto | 0:0e0631af0305 | 2023 | To use Mat_ for multi-channel images/matrices, pass Vec as a Mat_ parameter: |
RyoheiHagimoto | 0:0e0631af0305 | 2024 | @code |
RyoheiHagimoto | 0:0e0631af0305 | 2025 | // allocate a 320x240 color image and fill it with green (in RGB space) |
RyoheiHagimoto | 0:0e0631af0305 | 2026 | Mat_<Vec3b> img(240, 320, Vec3b(0,255,0)); |
RyoheiHagimoto | 0:0e0631af0305 | 2027 | // now draw a diagonal white line |
RyoheiHagimoto | 0:0e0631af0305 | 2028 | for(int i = 0; i < 100; i++) |
RyoheiHagimoto | 0:0e0631af0305 | 2029 | img(i,i)=Vec3b(255,255,255); |
RyoheiHagimoto | 0:0e0631af0305 | 2030 | // and now scramble the 2nd (red) channel of each pixel |
RyoheiHagimoto | 0:0e0631af0305 | 2031 | for(int i = 0; i < img.rows; i++) |
RyoheiHagimoto | 0:0e0631af0305 | 2032 | for(int j = 0; j < img.cols; j++) |
RyoheiHagimoto | 0:0e0631af0305 | 2033 | img(i,j)[2] ^= (uchar)(i ^ j); |
RyoheiHagimoto | 0:0e0631af0305 | 2034 | @endcode |
RyoheiHagimoto | 0:0e0631af0305 | 2035 | */ |
RyoheiHagimoto | 0:0e0631af0305 | 2036 | template<typename _Tp> class Mat_ : public Mat |
RyoheiHagimoto | 0:0e0631af0305 | 2037 | { |
RyoheiHagimoto | 0:0e0631af0305 | 2038 | public: |
RyoheiHagimoto | 0:0e0631af0305 | 2039 | typedef _Tp value_type; |
RyoheiHagimoto | 0:0e0631af0305 | 2040 | typedef typename DataType<_Tp>::channel_type channel_type; |
RyoheiHagimoto | 0:0e0631af0305 | 2041 | typedef MatIterator_<_Tp> iterator; |
RyoheiHagimoto | 0:0e0631af0305 | 2042 | typedef MatConstIterator_<_Tp> const_iterator; |
RyoheiHagimoto | 0:0e0631af0305 | 2043 | |
RyoheiHagimoto | 0:0e0631af0305 | 2044 | //! default constructor |
RyoheiHagimoto | 0:0e0631af0305 | 2045 | Mat_(); |
RyoheiHagimoto | 0:0e0631af0305 | 2046 | //! equivalent to Mat(_rows, _cols, DataType<_Tp>::type) |
RyoheiHagimoto | 0:0e0631af0305 | 2047 | Mat_(int _rows, int _cols); |
RyoheiHagimoto | 0:0e0631af0305 | 2048 | //! constructor that sets each matrix element to specified value |
RyoheiHagimoto | 0:0e0631af0305 | 2049 | Mat_(int _rows, int _cols, const _Tp& value); |
RyoheiHagimoto | 0:0e0631af0305 | 2050 | //! equivalent to Mat(_size, DataType<_Tp>::type) |
RyoheiHagimoto | 0:0e0631af0305 | 2051 | explicit Mat_(Size _size); |
RyoheiHagimoto | 0:0e0631af0305 | 2052 | //! constructor that sets each matrix element to specified value |
RyoheiHagimoto | 0:0e0631af0305 | 2053 | Mat_(Size _size, const _Tp& value); |
RyoheiHagimoto | 0:0e0631af0305 | 2054 | //! n-dim array constructor |
RyoheiHagimoto | 0:0e0631af0305 | 2055 | Mat_(int _ndims, const int* _sizes); |
RyoheiHagimoto | 0:0e0631af0305 | 2056 | //! n-dim array constructor that sets each matrix element to specified value |
RyoheiHagimoto | 0:0e0631af0305 | 2057 | Mat_(int _ndims, const int* _sizes, const _Tp& value); |
RyoheiHagimoto | 0:0e0631af0305 | 2058 | //! copy/conversion contructor. If m is of different type, it's converted |
RyoheiHagimoto | 0:0e0631af0305 | 2059 | Mat_(const Mat& m); |
RyoheiHagimoto | 0:0e0631af0305 | 2060 | //! copy constructor |
RyoheiHagimoto | 0:0e0631af0305 | 2061 | Mat_(const Mat_& m); |
RyoheiHagimoto | 0:0e0631af0305 | 2062 | //! constructs a matrix on top of user-allocated data. step is in bytes(!!!), regardless of the type |
RyoheiHagimoto | 0:0e0631af0305 | 2063 | Mat_(int _rows, int _cols, _Tp* _data, size_t _step=AUTO_STEP); |
RyoheiHagimoto | 0:0e0631af0305 | 2064 | //! constructs n-dim matrix on top of user-allocated data. steps are in bytes(!!!), regardless of the type |
RyoheiHagimoto | 0:0e0631af0305 | 2065 | Mat_(int _ndims, const int* _sizes, _Tp* _data, const size_t* _steps=0); |
RyoheiHagimoto | 0:0e0631af0305 | 2066 | //! selects a submatrix |
RyoheiHagimoto | 0:0e0631af0305 | 2067 | Mat_(const Mat_& m, const Range& rowRange, const Range& colRange=Range::all()); |
RyoheiHagimoto | 0:0e0631af0305 | 2068 | //! selects a submatrix |
RyoheiHagimoto | 0:0e0631af0305 | 2069 | Mat_(const Mat_& m, const Rect& roi); |
RyoheiHagimoto | 0:0e0631af0305 | 2070 | //! selects a submatrix, n-dim version |
RyoheiHagimoto | 0:0e0631af0305 | 2071 | Mat_(const Mat_& m, const Range* ranges); |
RyoheiHagimoto | 0:0e0631af0305 | 2072 | //! selects a submatrix, n-dim version |
RyoheiHagimoto | 0:0e0631af0305 | 2073 | Mat_(const Mat_& m, const std::vector<Range>& ranges); |
RyoheiHagimoto | 0:0e0631af0305 | 2074 | //! from a matrix expression |
RyoheiHagimoto | 0:0e0631af0305 | 2075 | explicit Mat_(const MatExpr& e); |
RyoheiHagimoto | 0:0e0631af0305 | 2076 | //! makes a matrix out of Vec, std::vector, Point_ or Point3_. The matrix will have a single column |
RyoheiHagimoto | 0:0e0631af0305 | 2077 | explicit Mat_(const std::vector<_Tp>& vec, bool copyData=false); |
RyoheiHagimoto | 0:0e0631af0305 | 2078 | template<int n> explicit Mat_(const Vec<typename DataType<_Tp>::channel_type, n>& vec, bool copyData=true); |
RyoheiHagimoto | 0:0e0631af0305 | 2079 | template<int m, int n> explicit Mat_(const Matx<typename DataType<_Tp>::channel_type, m, n>& mtx, bool copyData=true); |
RyoheiHagimoto | 0:0e0631af0305 | 2080 | explicit Mat_(const Point_<typename DataType<_Tp>::channel_type>& pt, bool copyData=true); |
RyoheiHagimoto | 0:0e0631af0305 | 2081 | explicit Mat_(const Point3_<typename DataType<_Tp>::channel_type>& pt, bool copyData=true); |
RyoheiHagimoto | 0:0e0631af0305 | 2082 | explicit Mat_(const MatCommaInitializer_<_Tp>& commaInitializer); |
RyoheiHagimoto | 0:0e0631af0305 | 2083 | |
RyoheiHagimoto | 0:0e0631af0305 | 2084 | Mat_& operator = (const Mat& m); |
RyoheiHagimoto | 0:0e0631af0305 | 2085 | Mat_& operator = (const Mat_& m); |
RyoheiHagimoto | 0:0e0631af0305 | 2086 | //! set all the elements to s. |
RyoheiHagimoto | 0:0e0631af0305 | 2087 | Mat_& operator = (const _Tp& s); |
RyoheiHagimoto | 0:0e0631af0305 | 2088 | //! assign a matrix expression |
RyoheiHagimoto | 0:0e0631af0305 | 2089 | Mat_& operator = (const MatExpr& e); |
RyoheiHagimoto | 0:0e0631af0305 | 2090 | |
RyoheiHagimoto | 0:0e0631af0305 | 2091 | //! iterators; they are smart enough to skip gaps in the end of rows |
RyoheiHagimoto | 0:0e0631af0305 | 2092 | iterator begin(); |
RyoheiHagimoto | 0:0e0631af0305 | 2093 | iterator end(); |
RyoheiHagimoto | 0:0e0631af0305 | 2094 | const_iterator begin() const; |
RyoheiHagimoto | 0:0e0631af0305 | 2095 | const_iterator end() const; |
RyoheiHagimoto | 0:0e0631af0305 | 2096 | |
RyoheiHagimoto | 0:0e0631af0305 | 2097 | //! template methods for for operation over all matrix elements. |
RyoheiHagimoto | 0:0e0631af0305 | 2098 | // the operations take care of skipping gaps in the end of rows (if any) |
RyoheiHagimoto | 0:0e0631af0305 | 2099 | template<typename Functor> void forEach(const Functor& operation); |
RyoheiHagimoto | 0:0e0631af0305 | 2100 | template<typename Functor> void forEach(const Functor& operation) const; |
RyoheiHagimoto | 0:0e0631af0305 | 2101 | |
RyoheiHagimoto | 0:0e0631af0305 | 2102 | //! equivalent to Mat::create(_rows, _cols, DataType<_Tp>::type) |
RyoheiHagimoto | 0:0e0631af0305 | 2103 | void create(int _rows, int _cols); |
RyoheiHagimoto | 0:0e0631af0305 | 2104 | //! equivalent to Mat::create(_size, DataType<_Tp>::type) |
RyoheiHagimoto | 0:0e0631af0305 | 2105 | void create(Size _size); |
RyoheiHagimoto | 0:0e0631af0305 | 2106 | //! equivalent to Mat::create(_ndims, _sizes, DatType<_Tp>::type) |
RyoheiHagimoto | 0:0e0631af0305 | 2107 | void create(int _ndims, const int* _sizes); |
RyoheiHagimoto | 0:0e0631af0305 | 2108 | //! cross-product |
RyoheiHagimoto | 0:0e0631af0305 | 2109 | Mat_ cross(const Mat_& m) const; |
RyoheiHagimoto | 0:0e0631af0305 | 2110 | //! data type conversion |
RyoheiHagimoto | 0:0e0631af0305 | 2111 | template<typename T2> operator Mat_<T2>() const; |
RyoheiHagimoto | 0:0e0631af0305 | 2112 | //! overridden forms of Mat::row() etc. |
RyoheiHagimoto | 0:0e0631af0305 | 2113 | Mat_ row(int y) const; |
RyoheiHagimoto | 0:0e0631af0305 | 2114 | Mat_ col(int x) const; |
RyoheiHagimoto | 0:0e0631af0305 | 2115 | Mat_ diag(int d=0) const; |
RyoheiHagimoto | 0:0e0631af0305 | 2116 | Mat_ clone() const; |
RyoheiHagimoto | 0:0e0631af0305 | 2117 | |
RyoheiHagimoto | 0:0e0631af0305 | 2118 | //! overridden forms of Mat::elemSize() etc. |
RyoheiHagimoto | 0:0e0631af0305 | 2119 | size_t elemSize() const; |
RyoheiHagimoto | 0:0e0631af0305 | 2120 | size_t elemSize1() const; |
RyoheiHagimoto | 0:0e0631af0305 | 2121 | int type() const; |
RyoheiHagimoto | 0:0e0631af0305 | 2122 | int depth() const; |
RyoheiHagimoto | 0:0e0631af0305 | 2123 | int channels() const; |
RyoheiHagimoto | 0:0e0631af0305 | 2124 | size_t step1(int i=0) const; |
RyoheiHagimoto | 0:0e0631af0305 | 2125 | //! returns step()/sizeof(_Tp) |
RyoheiHagimoto | 0:0e0631af0305 | 2126 | size_t stepT(int i=0) const; |
RyoheiHagimoto | 0:0e0631af0305 | 2127 | |
RyoheiHagimoto | 0:0e0631af0305 | 2128 | //! overridden forms of Mat::zeros() etc. Data type is omitted, of course |
RyoheiHagimoto | 0:0e0631af0305 | 2129 | static MatExpr zeros(int rows, int cols); |
RyoheiHagimoto | 0:0e0631af0305 | 2130 | static MatExpr zeros(Size size); |
RyoheiHagimoto | 0:0e0631af0305 | 2131 | static MatExpr zeros(int _ndims, const int* _sizes); |
RyoheiHagimoto | 0:0e0631af0305 | 2132 | static MatExpr ones(int rows, int cols); |
RyoheiHagimoto | 0:0e0631af0305 | 2133 | static MatExpr ones(Size size); |
RyoheiHagimoto | 0:0e0631af0305 | 2134 | static MatExpr ones(int _ndims, const int* _sizes); |
RyoheiHagimoto | 0:0e0631af0305 | 2135 | static MatExpr eye(int rows, int cols); |
RyoheiHagimoto | 0:0e0631af0305 | 2136 | static MatExpr eye(Size size); |
RyoheiHagimoto | 0:0e0631af0305 | 2137 | |
RyoheiHagimoto | 0:0e0631af0305 | 2138 | //! some more overriden methods |
RyoheiHagimoto | 0:0e0631af0305 | 2139 | Mat_& adjustROI( int dtop, int dbottom, int dleft, int dright ); |
RyoheiHagimoto | 0:0e0631af0305 | 2140 | Mat_ operator()( const Range& rowRange, const Range& colRange ) const; |
RyoheiHagimoto | 0:0e0631af0305 | 2141 | Mat_ operator()( const Rect& roi ) const; |
RyoheiHagimoto | 0:0e0631af0305 | 2142 | Mat_ operator()( const Range* ranges ) const; |
RyoheiHagimoto | 0:0e0631af0305 | 2143 | Mat_ operator()(const std::vector<Range>& ranges) const; |
RyoheiHagimoto | 0:0e0631af0305 | 2144 | |
RyoheiHagimoto | 0:0e0631af0305 | 2145 | //! more convenient forms of row and element access operators |
RyoheiHagimoto | 0:0e0631af0305 | 2146 | _Tp* operator [](int y); |
RyoheiHagimoto | 0:0e0631af0305 | 2147 | const _Tp* operator [](int y) const; |
RyoheiHagimoto | 0:0e0631af0305 | 2148 | |
RyoheiHagimoto | 0:0e0631af0305 | 2149 | //! returns reference to the specified element |
RyoheiHagimoto | 0:0e0631af0305 | 2150 | _Tp& operator ()(const int* idx); |
RyoheiHagimoto | 0:0e0631af0305 | 2151 | //! returns read-only reference to the specified element |
RyoheiHagimoto | 0:0e0631af0305 | 2152 | const _Tp& operator ()(const int* idx) const; |
RyoheiHagimoto | 0:0e0631af0305 | 2153 | |
RyoheiHagimoto | 0:0e0631af0305 | 2154 | //! returns reference to the specified element |
RyoheiHagimoto | 0:0e0631af0305 | 2155 | template<int n> _Tp& operator ()(const Vec<int, n>& idx); |
RyoheiHagimoto | 0:0e0631af0305 | 2156 | //! returns read-only reference to the specified element |
RyoheiHagimoto | 0:0e0631af0305 | 2157 | template<int n> const _Tp& operator ()(const Vec<int, n>& idx) const; |
RyoheiHagimoto | 0:0e0631af0305 | 2158 | |
RyoheiHagimoto | 0:0e0631af0305 | 2159 | //! returns reference to the specified element (1D case) |
RyoheiHagimoto | 0:0e0631af0305 | 2160 | _Tp& operator ()(int idx0); |
RyoheiHagimoto | 0:0e0631af0305 | 2161 | //! returns read-only reference to the specified element (1D case) |
RyoheiHagimoto | 0:0e0631af0305 | 2162 | const _Tp& operator ()(int idx0) const; |
RyoheiHagimoto | 0:0e0631af0305 | 2163 | //! returns reference to the specified element (2D case) |
RyoheiHagimoto | 0:0e0631af0305 | 2164 | _Tp& operator ()(int row, int col); |
RyoheiHagimoto | 0:0e0631af0305 | 2165 | //! returns read-only reference to the specified element (2D case) |
RyoheiHagimoto | 0:0e0631af0305 | 2166 | const _Tp& operator ()(int row, int col) const; |
RyoheiHagimoto | 0:0e0631af0305 | 2167 | //! returns reference to the specified element (3D case) |
RyoheiHagimoto | 0:0e0631af0305 | 2168 | _Tp& operator ()(int idx0, int idx1, int idx2); |
RyoheiHagimoto | 0:0e0631af0305 | 2169 | //! returns read-only reference to the specified element (3D case) |
RyoheiHagimoto | 0:0e0631af0305 | 2170 | const _Tp& operator ()(int idx0, int idx1, int idx2) const; |
RyoheiHagimoto | 0:0e0631af0305 | 2171 | |
RyoheiHagimoto | 0:0e0631af0305 | 2172 | _Tp& operator ()(Point pt); |
RyoheiHagimoto | 0:0e0631af0305 | 2173 | const _Tp& operator ()(Point pt) const; |
RyoheiHagimoto | 0:0e0631af0305 | 2174 | |
RyoheiHagimoto | 0:0e0631af0305 | 2175 | //! conversion to vector. |
RyoheiHagimoto | 0:0e0631af0305 | 2176 | operator std::vector<_Tp>() const; |
RyoheiHagimoto | 0:0e0631af0305 | 2177 | //! conversion to Vec |
RyoheiHagimoto | 0:0e0631af0305 | 2178 | template<int n> operator Vec<typename DataType<_Tp>::channel_type, n>() const; |
RyoheiHagimoto | 0:0e0631af0305 | 2179 | //! conversion to Matx |
RyoheiHagimoto | 0:0e0631af0305 | 2180 | template<int m, int n> operator Matx<typename DataType<_Tp>::channel_type, m, n>() const; |
RyoheiHagimoto | 0:0e0631af0305 | 2181 | |
RyoheiHagimoto | 0:0e0631af0305 | 2182 | #ifdef CV_CXX_MOVE_SEMANTICS |
RyoheiHagimoto | 0:0e0631af0305 | 2183 | Mat_(Mat_&& m); |
RyoheiHagimoto | 0:0e0631af0305 | 2184 | Mat_& operator = (Mat_&& m); |
RyoheiHagimoto | 0:0e0631af0305 | 2185 | |
RyoheiHagimoto | 0:0e0631af0305 | 2186 | Mat_(Mat&& m); |
RyoheiHagimoto | 0:0e0631af0305 | 2187 | Mat_& operator = (Mat&& m); |
RyoheiHagimoto | 0:0e0631af0305 | 2188 | |
RyoheiHagimoto | 0:0e0631af0305 | 2189 | Mat_(MatExpr&& e); |
RyoheiHagimoto | 0:0e0631af0305 | 2190 | #endif |
RyoheiHagimoto | 0:0e0631af0305 | 2191 | }; |
RyoheiHagimoto | 0:0e0631af0305 | 2192 | |
RyoheiHagimoto | 0:0e0631af0305 | 2193 | typedef Mat_<uchar> Mat1b; |
RyoheiHagimoto | 0:0e0631af0305 | 2194 | typedef Mat_<Vec2b> Mat2b; |
RyoheiHagimoto | 0:0e0631af0305 | 2195 | typedef Mat_<Vec3b> Mat3b; |
RyoheiHagimoto | 0:0e0631af0305 | 2196 | typedef Mat_<Vec4b> Mat4b; |
RyoheiHagimoto | 0:0e0631af0305 | 2197 | |
RyoheiHagimoto | 0:0e0631af0305 | 2198 | typedef Mat_<short> Mat1s; |
RyoheiHagimoto | 0:0e0631af0305 | 2199 | typedef Mat_<Vec2s> Mat2s; |
RyoheiHagimoto | 0:0e0631af0305 | 2200 | typedef Mat_<Vec3s> Mat3s; |
RyoheiHagimoto | 0:0e0631af0305 | 2201 | typedef Mat_<Vec4s> Mat4s; |
RyoheiHagimoto | 0:0e0631af0305 | 2202 | |
RyoheiHagimoto | 0:0e0631af0305 | 2203 | typedef Mat_<ushort> Mat1w; |
RyoheiHagimoto | 0:0e0631af0305 | 2204 | typedef Mat_<Vec2w> Mat2w; |
RyoheiHagimoto | 0:0e0631af0305 | 2205 | typedef Mat_<Vec3w> Mat3w; |
RyoheiHagimoto | 0:0e0631af0305 | 2206 | typedef Mat_<Vec4w> Mat4w; |
RyoheiHagimoto | 0:0e0631af0305 | 2207 | |
RyoheiHagimoto | 0:0e0631af0305 | 2208 | typedef Mat_<int> Mat1i; |
RyoheiHagimoto | 0:0e0631af0305 | 2209 | typedef Mat_<Vec2i> Mat2i; |
RyoheiHagimoto | 0:0e0631af0305 | 2210 | typedef Mat_<Vec3i> Mat3i; |
RyoheiHagimoto | 0:0e0631af0305 | 2211 | typedef Mat_<Vec4i> Mat4i; |
RyoheiHagimoto | 0:0e0631af0305 | 2212 | |
RyoheiHagimoto | 0:0e0631af0305 | 2213 | typedef Mat_<float> Mat1f; |
RyoheiHagimoto | 0:0e0631af0305 | 2214 | typedef Mat_<Vec2f> Mat2f; |
RyoheiHagimoto | 0:0e0631af0305 | 2215 | typedef Mat_<Vec3f> Mat3f; |
RyoheiHagimoto | 0:0e0631af0305 | 2216 | typedef Mat_<Vec4f> Mat4f; |
RyoheiHagimoto | 0:0e0631af0305 | 2217 | |
RyoheiHagimoto | 0:0e0631af0305 | 2218 | typedef Mat_<double> Mat1d; |
RyoheiHagimoto | 0:0e0631af0305 | 2219 | typedef Mat_<Vec2d> Mat2d; |
RyoheiHagimoto | 0:0e0631af0305 | 2220 | typedef Mat_<Vec3d> Mat3d; |
RyoheiHagimoto | 0:0e0631af0305 | 2221 | typedef Mat_<Vec4d> Mat4d; |
RyoheiHagimoto | 0:0e0631af0305 | 2222 | |
RyoheiHagimoto | 0:0e0631af0305 | 2223 | /** @todo document */ |
RyoheiHagimoto | 0:0e0631af0305 | 2224 | class CV_EXPORTS UMat |
RyoheiHagimoto | 0:0e0631af0305 | 2225 | { |
RyoheiHagimoto | 0:0e0631af0305 | 2226 | public: |
RyoheiHagimoto | 0:0e0631af0305 | 2227 | //! default constructor |
RyoheiHagimoto | 0:0e0631af0305 | 2228 | UMat(UMatUsageFlags usageFlags = USAGE_DEFAULT); |
RyoheiHagimoto | 0:0e0631af0305 | 2229 | //! constructs 2D matrix of the specified size and type |
RyoheiHagimoto | 0:0e0631af0305 | 2230 | // (_type is CV_8UC1, CV_64FC3, CV_32SC(12) etc.) |
RyoheiHagimoto | 0:0e0631af0305 | 2231 | UMat(int rows, int cols, int type, UMatUsageFlags usageFlags = USAGE_DEFAULT); |
RyoheiHagimoto | 0:0e0631af0305 | 2232 | UMat(Size size, int type, UMatUsageFlags usageFlags = USAGE_DEFAULT); |
RyoheiHagimoto | 0:0e0631af0305 | 2233 | //! constucts 2D matrix and fills it with the specified value _s. |
RyoheiHagimoto | 0:0e0631af0305 | 2234 | UMat(int rows, int cols, int type, const Scalar& s, UMatUsageFlags usageFlags = USAGE_DEFAULT); |
RyoheiHagimoto | 0:0e0631af0305 | 2235 | UMat(Size size, int type, const Scalar& s, UMatUsageFlags usageFlags = USAGE_DEFAULT); |
RyoheiHagimoto | 0:0e0631af0305 | 2236 | |
RyoheiHagimoto | 0:0e0631af0305 | 2237 | //! constructs n-dimensional matrix |
RyoheiHagimoto | 0:0e0631af0305 | 2238 | UMat(int ndims, const int* sizes, int type, UMatUsageFlags usageFlags = USAGE_DEFAULT); |
RyoheiHagimoto | 0:0e0631af0305 | 2239 | UMat(int ndims, const int* sizes, int type, const Scalar& s, UMatUsageFlags usageFlags = USAGE_DEFAULT); |
RyoheiHagimoto | 0:0e0631af0305 | 2240 | |
RyoheiHagimoto | 0:0e0631af0305 | 2241 | //! copy constructor |
RyoheiHagimoto | 0:0e0631af0305 | 2242 | UMat(const UMat& m); |
RyoheiHagimoto | 0:0e0631af0305 | 2243 | |
RyoheiHagimoto | 0:0e0631af0305 | 2244 | //! creates a matrix header for a part of the bigger matrix |
RyoheiHagimoto | 0:0e0631af0305 | 2245 | UMat(const UMat& m, const Range& rowRange, const Range& colRange=Range::all()); |
RyoheiHagimoto | 0:0e0631af0305 | 2246 | UMat(const UMat& m, const Rect& roi); |
RyoheiHagimoto | 0:0e0631af0305 | 2247 | UMat(const UMat& m, const Range* ranges); |
RyoheiHagimoto | 0:0e0631af0305 | 2248 | UMat(const UMat& m, const std::vector<Range>& ranges); |
RyoheiHagimoto | 0:0e0631af0305 | 2249 | //! builds matrix from std::vector with or without copying the data |
RyoheiHagimoto | 0:0e0631af0305 | 2250 | template<typename _Tp> explicit UMat(const std::vector<_Tp>& vec, bool copyData=false); |
RyoheiHagimoto | 0:0e0631af0305 | 2251 | //! builds matrix from cv::Vec; the data is copied by default |
RyoheiHagimoto | 0:0e0631af0305 | 2252 | template<typename _Tp, int n> explicit UMat(const Vec<_Tp, n>& vec, bool copyData=true); |
RyoheiHagimoto | 0:0e0631af0305 | 2253 | //! builds matrix from cv::Matx; the data is copied by default |
RyoheiHagimoto | 0:0e0631af0305 | 2254 | template<typename _Tp, int m, int n> explicit UMat(const Matx<_Tp, m, n>& mtx, bool copyData=true); |
RyoheiHagimoto | 0:0e0631af0305 | 2255 | //! builds matrix from a 2D point |
RyoheiHagimoto | 0:0e0631af0305 | 2256 | template<typename _Tp> explicit UMat(const Point_<_Tp>& pt, bool copyData=true); |
RyoheiHagimoto | 0:0e0631af0305 | 2257 | //! builds matrix from a 3D point |
RyoheiHagimoto | 0:0e0631af0305 | 2258 | template<typename _Tp> explicit UMat(const Point3_<_Tp>& pt, bool copyData=true); |
RyoheiHagimoto | 0:0e0631af0305 | 2259 | //! builds matrix from comma initializer |
RyoheiHagimoto | 0:0e0631af0305 | 2260 | template<typename _Tp> explicit UMat(const MatCommaInitializer_<_Tp>& commaInitializer); |
RyoheiHagimoto | 0:0e0631af0305 | 2261 | |
RyoheiHagimoto | 0:0e0631af0305 | 2262 | //! destructor - calls release() |
RyoheiHagimoto | 0:0e0631af0305 | 2263 | ~UMat(); |
RyoheiHagimoto | 0:0e0631af0305 | 2264 | //! assignment operators |
RyoheiHagimoto | 0:0e0631af0305 | 2265 | UMat& operator = (const UMat& m); |
RyoheiHagimoto | 0:0e0631af0305 | 2266 | |
RyoheiHagimoto | 0:0e0631af0305 | 2267 | Mat getMat(int flags) const; |
RyoheiHagimoto | 0:0e0631af0305 | 2268 | |
RyoheiHagimoto | 0:0e0631af0305 | 2269 | //! returns a new matrix header for the specified row |
RyoheiHagimoto | 0:0e0631af0305 | 2270 | UMat row(int y) const; |
RyoheiHagimoto | 0:0e0631af0305 | 2271 | //! returns a new matrix header for the specified column |
RyoheiHagimoto | 0:0e0631af0305 | 2272 | UMat col(int x) const; |
RyoheiHagimoto | 0:0e0631af0305 | 2273 | //! ... for the specified row span |
RyoheiHagimoto | 0:0e0631af0305 | 2274 | UMat rowRange(int startrow, int endrow) const; |
RyoheiHagimoto | 0:0e0631af0305 | 2275 | UMat rowRange(const Range& r) const; |
RyoheiHagimoto | 0:0e0631af0305 | 2276 | //! ... for the specified column span |
RyoheiHagimoto | 0:0e0631af0305 | 2277 | UMat colRange(int startcol, int endcol) const; |
RyoheiHagimoto | 0:0e0631af0305 | 2278 | UMat colRange(const Range& r) const; |
RyoheiHagimoto | 0:0e0631af0305 | 2279 | //! ... for the specified diagonal |
RyoheiHagimoto | 0:0e0631af0305 | 2280 | // (d=0 - the main diagonal, |
RyoheiHagimoto | 0:0e0631af0305 | 2281 | // >0 - a diagonal from the lower half, |
RyoheiHagimoto | 0:0e0631af0305 | 2282 | // <0 - a diagonal from the upper half) |
RyoheiHagimoto | 0:0e0631af0305 | 2283 | UMat diag(int d=0) const; |
RyoheiHagimoto | 0:0e0631af0305 | 2284 | //! constructs a square diagonal matrix which main diagonal is vector "d" |
RyoheiHagimoto | 0:0e0631af0305 | 2285 | static UMat diag(const UMat& d); |
RyoheiHagimoto | 0:0e0631af0305 | 2286 | |
RyoheiHagimoto | 0:0e0631af0305 | 2287 | //! returns deep copy of the matrix, i.e. the data is copied |
RyoheiHagimoto | 0:0e0631af0305 | 2288 | UMat clone() const; |
RyoheiHagimoto | 0:0e0631af0305 | 2289 | //! copies the matrix content to "m". |
RyoheiHagimoto | 0:0e0631af0305 | 2290 | // It calls m.create(this->size(), this->type()). |
RyoheiHagimoto | 0:0e0631af0305 | 2291 | void copyTo( OutputArray m ) const; |
RyoheiHagimoto | 0:0e0631af0305 | 2292 | //! copies those matrix elements to "m" that are marked with non-zero mask elements. |
RyoheiHagimoto | 0:0e0631af0305 | 2293 | void copyTo( OutputArray m, InputArray mask ) const; |
RyoheiHagimoto | 0:0e0631af0305 | 2294 | //! converts matrix to another datatype with optional scalng. See cvConvertScale. |
RyoheiHagimoto | 0:0e0631af0305 | 2295 | void convertTo( OutputArray m, int rtype, double alpha=1, double beta=0 ) const; |
RyoheiHagimoto | 0:0e0631af0305 | 2296 | |
RyoheiHagimoto | 0:0e0631af0305 | 2297 | void assignTo( UMat& m, int type=-1 ) const; |
RyoheiHagimoto | 0:0e0631af0305 | 2298 | |
RyoheiHagimoto | 0:0e0631af0305 | 2299 | //! sets every matrix element to s |
RyoheiHagimoto | 0:0e0631af0305 | 2300 | UMat& operator = (const Scalar& s); |
RyoheiHagimoto | 0:0e0631af0305 | 2301 | //! sets some of the matrix elements to s, according to the mask |
RyoheiHagimoto | 0:0e0631af0305 | 2302 | UMat& setTo(InputArray value, InputArray mask=noArray()); |
RyoheiHagimoto | 0:0e0631af0305 | 2303 | //! creates alternative matrix header for the same data, with different |
RyoheiHagimoto | 0:0e0631af0305 | 2304 | // number of channels and/or different number of rows. see cvReshape. |
RyoheiHagimoto | 0:0e0631af0305 | 2305 | UMat reshape(int cn, int rows=0) const; |
RyoheiHagimoto | 0:0e0631af0305 | 2306 | UMat reshape(int cn, int newndims, const int* newsz) const; |
RyoheiHagimoto | 0:0e0631af0305 | 2307 | |
RyoheiHagimoto | 0:0e0631af0305 | 2308 | //! matrix transposition by means of matrix expressions |
RyoheiHagimoto | 0:0e0631af0305 | 2309 | UMat t() const; |
RyoheiHagimoto | 0:0e0631af0305 | 2310 | //! matrix inversion by means of matrix expressions |
RyoheiHagimoto | 0:0e0631af0305 | 2311 | UMat inv(int method=DECOMP_LU) const; |
RyoheiHagimoto | 0:0e0631af0305 | 2312 | //! per-element matrix multiplication by means of matrix expressions |
RyoheiHagimoto | 0:0e0631af0305 | 2313 | UMat mul(InputArray m, double scale=1) const; |
RyoheiHagimoto | 0:0e0631af0305 | 2314 | |
RyoheiHagimoto | 0:0e0631af0305 | 2315 | //! computes dot-product |
RyoheiHagimoto | 0:0e0631af0305 | 2316 | double dot(InputArray m) const; |
RyoheiHagimoto | 0:0e0631af0305 | 2317 | |
RyoheiHagimoto | 0:0e0631af0305 | 2318 | //! Matlab-style matrix initialization |
RyoheiHagimoto | 0:0e0631af0305 | 2319 | static UMat zeros(int rows, int cols, int type); |
RyoheiHagimoto | 0:0e0631af0305 | 2320 | static UMat zeros(Size size, int type); |
RyoheiHagimoto | 0:0e0631af0305 | 2321 | static UMat zeros(int ndims, const int* sz, int type); |
RyoheiHagimoto | 0:0e0631af0305 | 2322 | static UMat ones(int rows, int cols, int type); |
RyoheiHagimoto | 0:0e0631af0305 | 2323 | static UMat ones(Size size, int type); |
RyoheiHagimoto | 0:0e0631af0305 | 2324 | static UMat ones(int ndims, const int* sz, int type); |
RyoheiHagimoto | 0:0e0631af0305 | 2325 | static UMat eye(int rows, int cols, int type); |
RyoheiHagimoto | 0:0e0631af0305 | 2326 | static UMat eye(Size size, int type); |
RyoheiHagimoto | 0:0e0631af0305 | 2327 | |
RyoheiHagimoto | 0:0e0631af0305 | 2328 | //! allocates new matrix data unless the matrix already has specified size and type. |
RyoheiHagimoto | 0:0e0631af0305 | 2329 | // previous data is unreferenced if needed. |
RyoheiHagimoto | 0:0e0631af0305 | 2330 | void create(int rows, int cols, int type, UMatUsageFlags usageFlags = USAGE_DEFAULT); |
RyoheiHagimoto | 0:0e0631af0305 | 2331 | void create(Size size, int type, UMatUsageFlags usageFlags = USAGE_DEFAULT); |
RyoheiHagimoto | 0:0e0631af0305 | 2332 | void create(int ndims, const int* sizes, int type, UMatUsageFlags usageFlags = USAGE_DEFAULT); |
RyoheiHagimoto | 0:0e0631af0305 | 2333 | void create(const std::vector<int>& sizes, int type, UMatUsageFlags usageFlags = USAGE_DEFAULT); |
RyoheiHagimoto | 0:0e0631af0305 | 2334 | |
RyoheiHagimoto | 0:0e0631af0305 | 2335 | //! increases the reference counter; use with care to avoid memleaks |
RyoheiHagimoto | 0:0e0631af0305 | 2336 | void addref(); |
RyoheiHagimoto | 0:0e0631af0305 | 2337 | //! decreases reference counter; |
RyoheiHagimoto | 0:0e0631af0305 | 2338 | // deallocates the data when reference counter reaches 0. |
RyoheiHagimoto | 0:0e0631af0305 | 2339 | void release(); |
RyoheiHagimoto | 0:0e0631af0305 | 2340 | |
RyoheiHagimoto | 0:0e0631af0305 | 2341 | //! deallocates the matrix data |
RyoheiHagimoto | 0:0e0631af0305 | 2342 | void deallocate(); |
RyoheiHagimoto | 0:0e0631af0305 | 2343 | //! internal use function; properly re-allocates _size, _step arrays |
RyoheiHagimoto | 0:0e0631af0305 | 2344 | void copySize(const UMat& m); |
RyoheiHagimoto | 0:0e0631af0305 | 2345 | |
RyoheiHagimoto | 0:0e0631af0305 | 2346 | //! locates matrix header within a parent matrix. See below |
RyoheiHagimoto | 0:0e0631af0305 | 2347 | void locateROI( Size& wholeSize, Point& ofs ) const; |
RyoheiHagimoto | 0:0e0631af0305 | 2348 | //! moves/resizes the current matrix ROI inside the parent matrix. |
RyoheiHagimoto | 0:0e0631af0305 | 2349 | UMat& adjustROI( int dtop, int dbottom, int dleft, int dright ); |
RyoheiHagimoto | 0:0e0631af0305 | 2350 | //! extracts a rectangular sub-matrix |
RyoheiHagimoto | 0:0e0631af0305 | 2351 | // (this is a generalized form of row, rowRange etc.) |
RyoheiHagimoto | 0:0e0631af0305 | 2352 | UMat operator()( Range rowRange, Range colRange ) const; |
RyoheiHagimoto | 0:0e0631af0305 | 2353 | UMat operator()( const Rect& roi ) const; |
RyoheiHagimoto | 0:0e0631af0305 | 2354 | UMat operator()( const Range* ranges ) const; |
RyoheiHagimoto | 0:0e0631af0305 | 2355 | UMat operator()(const std::vector<Range>& ranges) const; |
RyoheiHagimoto | 0:0e0631af0305 | 2356 | |
RyoheiHagimoto | 0:0e0631af0305 | 2357 | //! returns true iff the matrix data is continuous |
RyoheiHagimoto | 0:0e0631af0305 | 2358 | // (i.e. when there are no gaps between successive rows). |
RyoheiHagimoto | 0:0e0631af0305 | 2359 | // similar to CV_IS_MAT_CONT(cvmat->type) |
RyoheiHagimoto | 0:0e0631af0305 | 2360 | bool isContinuous() const; |
RyoheiHagimoto | 0:0e0631af0305 | 2361 | |
RyoheiHagimoto | 0:0e0631af0305 | 2362 | //! returns true if the matrix is a submatrix of another matrix |
RyoheiHagimoto | 0:0e0631af0305 | 2363 | bool isSubmatrix() const; |
RyoheiHagimoto | 0:0e0631af0305 | 2364 | |
RyoheiHagimoto | 0:0e0631af0305 | 2365 | //! returns element size in bytes, |
RyoheiHagimoto | 0:0e0631af0305 | 2366 | // similar to CV_ELEM_SIZE(cvmat->type) |
RyoheiHagimoto | 0:0e0631af0305 | 2367 | size_t elemSize() const; |
RyoheiHagimoto | 0:0e0631af0305 | 2368 | //! returns the size of element channel in bytes. |
RyoheiHagimoto | 0:0e0631af0305 | 2369 | size_t elemSize1() const; |
RyoheiHagimoto | 0:0e0631af0305 | 2370 | //! returns element type, similar to CV_MAT_TYPE(cvmat->type) |
RyoheiHagimoto | 0:0e0631af0305 | 2371 | int type() const; |
RyoheiHagimoto | 0:0e0631af0305 | 2372 | //! returns element type, similar to CV_MAT_DEPTH(cvmat->type) |
RyoheiHagimoto | 0:0e0631af0305 | 2373 | int depth() const; |
RyoheiHagimoto | 0:0e0631af0305 | 2374 | //! returns element type, similar to CV_MAT_CN(cvmat->type) |
RyoheiHagimoto | 0:0e0631af0305 | 2375 | int channels() const; |
RyoheiHagimoto | 0:0e0631af0305 | 2376 | //! returns step/elemSize1() |
RyoheiHagimoto | 0:0e0631af0305 | 2377 | size_t step1(int i=0) const; |
RyoheiHagimoto | 0:0e0631af0305 | 2378 | //! returns true if matrix data is NULL |
RyoheiHagimoto | 0:0e0631af0305 | 2379 | bool empty() const; |
RyoheiHagimoto | 0:0e0631af0305 | 2380 | //! returns the total number of matrix elements |
RyoheiHagimoto | 0:0e0631af0305 | 2381 | size_t total() const; |
RyoheiHagimoto | 0:0e0631af0305 | 2382 | |
RyoheiHagimoto | 0:0e0631af0305 | 2383 | //! returns N if the matrix is 1-channel (N x ptdim) or ptdim-channel (1 x N) or (N x 1); negative number otherwise |
RyoheiHagimoto | 0:0e0631af0305 | 2384 | int checkVector(int elemChannels, int depth=-1, bool requireContinuous=true) const; |
RyoheiHagimoto | 0:0e0631af0305 | 2385 | |
RyoheiHagimoto | 0:0e0631af0305 | 2386 | #ifdef CV_CXX_MOVE_SEMANTICS |
RyoheiHagimoto | 0:0e0631af0305 | 2387 | UMat(UMat&& m); |
RyoheiHagimoto | 0:0e0631af0305 | 2388 | UMat& operator = (UMat&& m); |
RyoheiHagimoto | 0:0e0631af0305 | 2389 | #endif |
RyoheiHagimoto | 0:0e0631af0305 | 2390 | |
RyoheiHagimoto | 0:0e0631af0305 | 2391 | void* handle(int accessFlags) const; |
RyoheiHagimoto | 0:0e0631af0305 | 2392 | void ndoffset(size_t* ofs) const; |
RyoheiHagimoto | 0:0e0631af0305 | 2393 | |
RyoheiHagimoto | 0:0e0631af0305 | 2394 | enum { MAGIC_VAL = 0x42FF0000, AUTO_STEP = 0, CONTINUOUS_FLAG = CV_MAT_CONT_FLAG, SUBMATRIX_FLAG = CV_SUBMAT_FLAG }; |
RyoheiHagimoto | 0:0e0631af0305 | 2395 | enum { MAGIC_MASK = 0xFFFF0000, TYPE_MASK = 0x00000FFF, DEPTH_MASK = 7 }; |
RyoheiHagimoto | 0:0e0631af0305 | 2396 | |
RyoheiHagimoto | 0:0e0631af0305 | 2397 | /*! includes several bit-fields: |
RyoheiHagimoto | 0:0e0631af0305 | 2398 | - the magic signature |
RyoheiHagimoto | 0:0e0631af0305 | 2399 | - continuity flag |
RyoheiHagimoto | 0:0e0631af0305 | 2400 | - depth |
RyoheiHagimoto | 0:0e0631af0305 | 2401 | - number of channels |
RyoheiHagimoto | 0:0e0631af0305 | 2402 | */ |
RyoheiHagimoto | 0:0e0631af0305 | 2403 | int flags; |
RyoheiHagimoto | 0:0e0631af0305 | 2404 | //! the matrix dimensionality, >= 2 |
RyoheiHagimoto | 0:0e0631af0305 | 2405 | int dims; |
RyoheiHagimoto | 0:0e0631af0305 | 2406 | //! the number of rows and columns or (-1, -1) when the matrix has more than 2 dimensions |
RyoheiHagimoto | 0:0e0631af0305 | 2407 | int rows, cols; |
RyoheiHagimoto | 0:0e0631af0305 | 2408 | |
RyoheiHagimoto | 0:0e0631af0305 | 2409 | //! custom allocator |
RyoheiHagimoto | 0:0e0631af0305 | 2410 | MatAllocator* allocator; |
RyoheiHagimoto | 0:0e0631af0305 | 2411 | UMatUsageFlags usageFlags; // usage flags for allocator |
RyoheiHagimoto | 0:0e0631af0305 | 2412 | //! and the standard allocator |
RyoheiHagimoto | 0:0e0631af0305 | 2413 | static MatAllocator* getStdAllocator(); |
RyoheiHagimoto | 0:0e0631af0305 | 2414 | |
RyoheiHagimoto | 0:0e0631af0305 | 2415 | // black-box container of UMat data |
RyoheiHagimoto | 0:0e0631af0305 | 2416 | UMatData* u; |
RyoheiHagimoto | 0:0e0631af0305 | 2417 | |
RyoheiHagimoto | 0:0e0631af0305 | 2418 | // offset of the submatrix (or 0) |
RyoheiHagimoto | 0:0e0631af0305 | 2419 | size_t offset; |
RyoheiHagimoto | 0:0e0631af0305 | 2420 | |
RyoheiHagimoto | 0:0e0631af0305 | 2421 | MatSize size; |
RyoheiHagimoto | 0:0e0631af0305 | 2422 | MatStep step; |
RyoheiHagimoto | 0:0e0631af0305 | 2423 | |
RyoheiHagimoto | 0:0e0631af0305 | 2424 | protected: |
RyoheiHagimoto | 0:0e0631af0305 | 2425 | }; |
RyoheiHagimoto | 0:0e0631af0305 | 2426 | |
RyoheiHagimoto | 0:0e0631af0305 | 2427 | |
RyoheiHagimoto | 0:0e0631af0305 | 2428 | /////////////////////////// multi-dimensional sparse matrix ////////////////////////// |
RyoheiHagimoto | 0:0e0631af0305 | 2429 | |
RyoheiHagimoto | 0:0e0631af0305 | 2430 | /** @brief The class SparseMat represents multi-dimensional sparse numerical arrays. |
RyoheiHagimoto | 0:0e0631af0305 | 2431 | |
RyoheiHagimoto | 0:0e0631af0305 | 2432 | Such a sparse array can store elements of any type that Mat can store. *Sparse* means that only |
RyoheiHagimoto | 0:0e0631af0305 | 2433 | non-zero elements are stored (though, as a result of operations on a sparse matrix, some of its |
RyoheiHagimoto | 0:0e0631af0305 | 2434 | stored elements can actually become 0. It is up to you to detect such elements and delete them |
RyoheiHagimoto | 0:0e0631af0305 | 2435 | using SparseMat::erase ). The non-zero elements are stored in a hash table that grows when it is |
RyoheiHagimoto | 0:0e0631af0305 | 2436 | filled so that the search time is O(1) in average (regardless of whether element is there or not). |
RyoheiHagimoto | 0:0e0631af0305 | 2437 | Elements can be accessed using the following methods: |
RyoheiHagimoto | 0:0e0631af0305 | 2438 | - Query operations (SparseMat::ptr and the higher-level SparseMat::ref, SparseMat::value and |
RyoheiHagimoto | 0:0e0631af0305 | 2439 | SparseMat::find), for example: |
RyoheiHagimoto | 0:0e0631af0305 | 2440 | @code |
RyoheiHagimoto | 0:0e0631af0305 | 2441 | const int dims = 5; |
RyoheiHagimoto | 0:0e0631af0305 | 2442 | int size[5] = {10, 10, 10, 10, 10}; |
RyoheiHagimoto | 0:0e0631af0305 | 2443 | SparseMat sparse_mat(dims, size, CV_32F); |
RyoheiHagimoto | 0:0e0631af0305 | 2444 | for(int i = 0; i < 1000; i++) |
RyoheiHagimoto | 0:0e0631af0305 | 2445 | { |
RyoheiHagimoto | 0:0e0631af0305 | 2446 | int idx[dims]; |
RyoheiHagimoto | 0:0e0631af0305 | 2447 | for(int k = 0; k < dims; k++) |
RyoheiHagimoto | 0:0e0631af0305 | 2448 | idx[k] = rand() % size[k]; |
RyoheiHagimoto | 0:0e0631af0305 | 2449 | sparse_mat.ref<float>(idx) += 1.f; |
RyoheiHagimoto | 0:0e0631af0305 | 2450 | } |
RyoheiHagimoto | 0:0e0631af0305 | 2451 | cout << "nnz = " << sparse_mat.nzcount() << endl; |
RyoheiHagimoto | 0:0e0631af0305 | 2452 | @endcode |
RyoheiHagimoto | 0:0e0631af0305 | 2453 | - Sparse matrix iterators. They are similar to MatIterator but different from NAryMatIterator. |
RyoheiHagimoto | 0:0e0631af0305 | 2454 | That is, the iteration loop is familiar to STL users: |
RyoheiHagimoto | 0:0e0631af0305 | 2455 | @code |
RyoheiHagimoto | 0:0e0631af0305 | 2456 | // prints elements of a sparse floating-point matrix |
RyoheiHagimoto | 0:0e0631af0305 | 2457 | // and the sum of elements. |
RyoheiHagimoto | 0:0e0631af0305 | 2458 | SparseMatConstIterator_<float> |
RyoheiHagimoto | 0:0e0631af0305 | 2459 | it = sparse_mat.begin<float>(), |
RyoheiHagimoto | 0:0e0631af0305 | 2460 | it_end = sparse_mat.end<float>(); |
RyoheiHagimoto | 0:0e0631af0305 | 2461 | double s = 0; |
RyoheiHagimoto | 0:0e0631af0305 | 2462 | int dims = sparse_mat.dims(); |
RyoheiHagimoto | 0:0e0631af0305 | 2463 | for(; it != it_end; ++it) |
RyoheiHagimoto | 0:0e0631af0305 | 2464 | { |
RyoheiHagimoto | 0:0e0631af0305 | 2465 | // print element indices and the element value |
RyoheiHagimoto | 0:0e0631af0305 | 2466 | const SparseMat::Node* n = it.node(); |
RyoheiHagimoto | 0:0e0631af0305 | 2467 | printf("("); |
RyoheiHagimoto | 0:0e0631af0305 | 2468 | for(int i = 0; i < dims; i++) |
RyoheiHagimoto | 0:0e0631af0305 | 2469 | printf("%d%s", n->idx[i], i < dims-1 ? ", " : ")"); |
RyoheiHagimoto | 0:0e0631af0305 | 2470 | printf(": %g\n", it.value<float>()); |
RyoheiHagimoto | 0:0e0631af0305 | 2471 | s += *it; |
RyoheiHagimoto | 0:0e0631af0305 | 2472 | } |
RyoheiHagimoto | 0:0e0631af0305 | 2473 | printf("Element sum is %g\n", s); |
RyoheiHagimoto | 0:0e0631af0305 | 2474 | @endcode |
RyoheiHagimoto | 0:0e0631af0305 | 2475 | If you run this loop, you will notice that elements are not enumerated in a logical order |
RyoheiHagimoto | 0:0e0631af0305 | 2476 | (lexicographical, and so on). They come in the same order as they are stored in the hash table |
RyoheiHagimoto | 0:0e0631af0305 | 2477 | (semi-randomly). You may collect pointers to the nodes and sort them to get the proper ordering. |
RyoheiHagimoto | 0:0e0631af0305 | 2478 | Note, however, that pointers to the nodes may become invalid when you add more elements to the |
RyoheiHagimoto | 0:0e0631af0305 | 2479 | matrix. This may happen due to possible buffer reallocation. |
RyoheiHagimoto | 0:0e0631af0305 | 2480 | - Combination of the above 2 methods when you need to process 2 or more sparse matrices |
RyoheiHagimoto | 0:0e0631af0305 | 2481 | simultaneously. For example, this is how you can compute unnormalized cross-correlation of the 2 |
RyoheiHagimoto | 0:0e0631af0305 | 2482 | floating-point sparse matrices: |
RyoheiHagimoto | 0:0e0631af0305 | 2483 | @code |
RyoheiHagimoto | 0:0e0631af0305 | 2484 | double cross_corr(const SparseMat& a, const SparseMat& b) |
RyoheiHagimoto | 0:0e0631af0305 | 2485 | { |
RyoheiHagimoto | 0:0e0631af0305 | 2486 | const SparseMat *_a = &a, *_b = &b; |
RyoheiHagimoto | 0:0e0631af0305 | 2487 | // if b contains less elements than a, |
RyoheiHagimoto | 0:0e0631af0305 | 2488 | // it is faster to iterate through b |
RyoheiHagimoto | 0:0e0631af0305 | 2489 | if(_a->nzcount() > _b->nzcount()) |
RyoheiHagimoto | 0:0e0631af0305 | 2490 | std::swap(_a, _b); |
RyoheiHagimoto | 0:0e0631af0305 | 2491 | SparseMatConstIterator_<float> it = _a->begin<float>(), |
RyoheiHagimoto | 0:0e0631af0305 | 2492 | it_end = _a->end<float>(); |
RyoheiHagimoto | 0:0e0631af0305 | 2493 | double ccorr = 0; |
RyoheiHagimoto | 0:0e0631af0305 | 2494 | for(; it != it_end; ++it) |
RyoheiHagimoto | 0:0e0631af0305 | 2495 | { |
RyoheiHagimoto | 0:0e0631af0305 | 2496 | // take the next element from the first matrix |
RyoheiHagimoto | 0:0e0631af0305 | 2497 | float avalue = *it; |
RyoheiHagimoto | 0:0e0631af0305 | 2498 | const Node* anode = it.node(); |
RyoheiHagimoto | 0:0e0631af0305 | 2499 | // and try to find an element with the same index in the second matrix. |
RyoheiHagimoto | 0:0e0631af0305 | 2500 | // since the hash value depends only on the element index, |
RyoheiHagimoto | 0:0e0631af0305 | 2501 | // reuse the hash value stored in the node |
RyoheiHagimoto | 0:0e0631af0305 | 2502 | float bvalue = _b->value<float>(anode->idx,&anode->hashval); |
RyoheiHagimoto | 0:0e0631af0305 | 2503 | ccorr += avalue*bvalue; |
RyoheiHagimoto | 0:0e0631af0305 | 2504 | } |
RyoheiHagimoto | 0:0e0631af0305 | 2505 | return ccorr; |
RyoheiHagimoto | 0:0e0631af0305 | 2506 | } |
RyoheiHagimoto | 0:0e0631af0305 | 2507 | @endcode |
RyoheiHagimoto | 0:0e0631af0305 | 2508 | */ |
RyoheiHagimoto | 0:0e0631af0305 | 2509 | class CV_EXPORTS SparseMat |
RyoheiHagimoto | 0:0e0631af0305 | 2510 | { |
RyoheiHagimoto | 0:0e0631af0305 | 2511 | public: |
RyoheiHagimoto | 0:0e0631af0305 | 2512 | typedef SparseMatIterator iterator; |
RyoheiHagimoto | 0:0e0631af0305 | 2513 | typedef SparseMatConstIterator const_iterator; |
RyoheiHagimoto | 0:0e0631af0305 | 2514 | |
RyoheiHagimoto | 0:0e0631af0305 | 2515 | enum { MAGIC_VAL=0x42FD0000, MAX_DIM=32, HASH_SCALE=0x5bd1e995, HASH_BIT=0x80000000 }; |
RyoheiHagimoto | 0:0e0631af0305 | 2516 | |
RyoheiHagimoto | 0:0e0631af0305 | 2517 | //! the sparse matrix header |
RyoheiHagimoto | 0:0e0631af0305 | 2518 | struct CV_EXPORTS Hdr |
RyoheiHagimoto | 0:0e0631af0305 | 2519 | { |
RyoheiHagimoto | 0:0e0631af0305 | 2520 | Hdr(int _dims, const int* _sizes, int _type); |
RyoheiHagimoto | 0:0e0631af0305 | 2521 | void clear(); |
RyoheiHagimoto | 0:0e0631af0305 | 2522 | int refcount; |
RyoheiHagimoto | 0:0e0631af0305 | 2523 | int dims; |
RyoheiHagimoto | 0:0e0631af0305 | 2524 | int valueOffset; |
RyoheiHagimoto | 0:0e0631af0305 | 2525 | size_t nodeSize; |
RyoheiHagimoto | 0:0e0631af0305 | 2526 | size_t nodeCount; |
RyoheiHagimoto | 0:0e0631af0305 | 2527 | size_t freeList; |
RyoheiHagimoto | 0:0e0631af0305 | 2528 | std::vector<uchar> pool; |
RyoheiHagimoto | 0:0e0631af0305 | 2529 | std::vector<size_t> hashtab; |
RyoheiHagimoto | 0:0e0631af0305 | 2530 | int size[MAX_DIM]; |
RyoheiHagimoto | 0:0e0631af0305 | 2531 | }; |
RyoheiHagimoto | 0:0e0631af0305 | 2532 | |
RyoheiHagimoto | 0:0e0631af0305 | 2533 | //! sparse matrix node - element of a hash table |
RyoheiHagimoto | 0:0e0631af0305 | 2534 | struct CV_EXPORTS Node |
RyoheiHagimoto | 0:0e0631af0305 | 2535 | { |
RyoheiHagimoto | 0:0e0631af0305 | 2536 | //! hash value |
RyoheiHagimoto | 0:0e0631af0305 | 2537 | size_t hashval; |
RyoheiHagimoto | 0:0e0631af0305 | 2538 | //! index of the next node in the same hash table entry |
RyoheiHagimoto | 0:0e0631af0305 | 2539 | size_t next; |
RyoheiHagimoto | 0:0e0631af0305 | 2540 | //! index of the matrix element |
RyoheiHagimoto | 0:0e0631af0305 | 2541 | int idx[MAX_DIM]; |
RyoheiHagimoto | 0:0e0631af0305 | 2542 | }; |
RyoheiHagimoto | 0:0e0631af0305 | 2543 | |
RyoheiHagimoto | 0:0e0631af0305 | 2544 | /** @brief Various SparseMat constructors. |
RyoheiHagimoto | 0:0e0631af0305 | 2545 | */ |
RyoheiHagimoto | 0:0e0631af0305 | 2546 | SparseMat(); |
RyoheiHagimoto | 0:0e0631af0305 | 2547 | |
RyoheiHagimoto | 0:0e0631af0305 | 2548 | /** @overload |
RyoheiHagimoto | 0:0e0631af0305 | 2549 | @param dims Array dimensionality. |
RyoheiHagimoto | 0:0e0631af0305 | 2550 | @param _sizes Sparce matrix size on all dementions. |
RyoheiHagimoto | 0:0e0631af0305 | 2551 | @param _type Sparse matrix data type. |
RyoheiHagimoto | 0:0e0631af0305 | 2552 | */ |
RyoheiHagimoto | 0:0e0631af0305 | 2553 | SparseMat(int dims, const int* _sizes, int _type); |
RyoheiHagimoto | 0:0e0631af0305 | 2554 | |
RyoheiHagimoto | 0:0e0631af0305 | 2555 | /** @overload |
RyoheiHagimoto | 0:0e0631af0305 | 2556 | @param m Source matrix for copy constructor. If m is dense matrix (ocvMat) then it will be converted |
RyoheiHagimoto | 0:0e0631af0305 | 2557 | to sparse representation. |
RyoheiHagimoto | 0:0e0631af0305 | 2558 | */ |
RyoheiHagimoto | 0:0e0631af0305 | 2559 | SparseMat(const SparseMat& m); |
RyoheiHagimoto | 0:0e0631af0305 | 2560 | |
RyoheiHagimoto | 0:0e0631af0305 | 2561 | /** @overload |
RyoheiHagimoto | 0:0e0631af0305 | 2562 | @param m Source matrix for copy constructor. If m is dense matrix (ocvMat) then it will be converted |
RyoheiHagimoto | 0:0e0631af0305 | 2563 | to sparse representation. |
RyoheiHagimoto | 0:0e0631af0305 | 2564 | */ |
RyoheiHagimoto | 0:0e0631af0305 | 2565 | explicit SparseMat(const Mat& m); |
RyoheiHagimoto | 0:0e0631af0305 | 2566 | |
RyoheiHagimoto | 0:0e0631af0305 | 2567 | //! the destructor |
RyoheiHagimoto | 0:0e0631af0305 | 2568 | ~SparseMat(); |
RyoheiHagimoto | 0:0e0631af0305 | 2569 | |
RyoheiHagimoto | 0:0e0631af0305 | 2570 | //! assignment operator. This is O(1) operation, i.e. no data is copied |
RyoheiHagimoto | 0:0e0631af0305 | 2571 | SparseMat& operator = (const SparseMat& m); |
RyoheiHagimoto | 0:0e0631af0305 | 2572 | //! equivalent to the corresponding constructor |
RyoheiHagimoto | 0:0e0631af0305 | 2573 | SparseMat& operator = (const Mat& m); |
RyoheiHagimoto | 0:0e0631af0305 | 2574 | |
RyoheiHagimoto | 0:0e0631af0305 | 2575 | //! creates full copy of the matrix |
RyoheiHagimoto | 0:0e0631af0305 | 2576 | SparseMat clone() const; |
RyoheiHagimoto | 0:0e0631af0305 | 2577 | |
RyoheiHagimoto | 0:0e0631af0305 | 2578 | //! copies all the data to the destination matrix. All the previous content of m is erased |
RyoheiHagimoto | 0:0e0631af0305 | 2579 | void copyTo( SparseMat& m ) const; |
RyoheiHagimoto | 0:0e0631af0305 | 2580 | //! converts sparse matrix to dense matrix. |
RyoheiHagimoto | 0:0e0631af0305 | 2581 | void copyTo( Mat& m ) const; |
RyoheiHagimoto | 0:0e0631af0305 | 2582 | //! multiplies all the matrix elements by the specified scale factor alpha and converts the results to the specified data type |
RyoheiHagimoto | 0:0e0631af0305 | 2583 | void convertTo( SparseMat& m, int rtype, double alpha=1 ) const; |
RyoheiHagimoto | 0:0e0631af0305 | 2584 | //! converts sparse matrix to dense n-dim matrix with optional type conversion and scaling. |
RyoheiHagimoto | 0:0e0631af0305 | 2585 | /*! |
RyoheiHagimoto | 0:0e0631af0305 | 2586 | @param [out] m - output matrix; if it does not have a proper size or type before the operation, |
RyoheiHagimoto | 0:0e0631af0305 | 2587 | it is reallocated |
RyoheiHagimoto | 0:0e0631af0305 | 2588 | @param [in] rtype – desired output matrix type or, rather, the depth since the number of channels |
RyoheiHagimoto | 0:0e0631af0305 | 2589 | are the same as the input has; if rtype is negative, the output matrix will have the |
RyoheiHagimoto | 0:0e0631af0305 | 2590 | same type as the input. |
RyoheiHagimoto | 0:0e0631af0305 | 2591 | @param [in] alpha – optional scale factor |
RyoheiHagimoto | 0:0e0631af0305 | 2592 | @param [in] beta – optional delta added to the scaled values |
RyoheiHagimoto | 0:0e0631af0305 | 2593 | */ |
RyoheiHagimoto | 0:0e0631af0305 | 2594 | void convertTo( Mat& m, int rtype, double alpha=1, double beta=0 ) const; |
RyoheiHagimoto | 0:0e0631af0305 | 2595 | |
RyoheiHagimoto | 0:0e0631af0305 | 2596 | // not used now |
RyoheiHagimoto | 0:0e0631af0305 | 2597 | void assignTo( SparseMat& m, int type=-1 ) const; |
RyoheiHagimoto | 0:0e0631af0305 | 2598 | |
RyoheiHagimoto | 0:0e0631af0305 | 2599 | //! reallocates sparse matrix. |
RyoheiHagimoto | 0:0e0631af0305 | 2600 | /*! |
RyoheiHagimoto | 0:0e0631af0305 | 2601 | If the matrix already had the proper size and type, |
RyoheiHagimoto | 0:0e0631af0305 | 2602 | it is simply cleared with clear(), otherwise, |
RyoheiHagimoto | 0:0e0631af0305 | 2603 | the old matrix is released (using release()) and the new one is allocated. |
RyoheiHagimoto | 0:0e0631af0305 | 2604 | */ |
RyoheiHagimoto | 0:0e0631af0305 | 2605 | void create(int dims, const int* _sizes, int _type); |
RyoheiHagimoto | 0:0e0631af0305 | 2606 | //! sets all the sparse matrix elements to 0, which means clearing the hash table. |
RyoheiHagimoto | 0:0e0631af0305 | 2607 | void clear(); |
RyoheiHagimoto | 0:0e0631af0305 | 2608 | //! manually increments the reference counter to the header. |
RyoheiHagimoto | 0:0e0631af0305 | 2609 | void addref(); |
RyoheiHagimoto | 0:0e0631af0305 | 2610 | // decrements the header reference counter. When the counter reaches 0, the header and all the underlying data are deallocated. |
RyoheiHagimoto | 0:0e0631af0305 | 2611 | void release(); |
RyoheiHagimoto | 0:0e0631af0305 | 2612 | |
RyoheiHagimoto | 0:0e0631af0305 | 2613 | //! converts sparse matrix to the old-style representation; all the elements are copied. |
RyoheiHagimoto | 0:0e0631af0305 | 2614 | //operator CvSparseMat*() const; |
RyoheiHagimoto | 0:0e0631af0305 | 2615 | //! returns the size of each element in bytes (not including the overhead - the space occupied by SparseMat::Node elements) |
RyoheiHagimoto | 0:0e0631af0305 | 2616 | size_t elemSize() const; |
RyoheiHagimoto | 0:0e0631af0305 | 2617 | //! returns elemSize()/channels() |
RyoheiHagimoto | 0:0e0631af0305 | 2618 | size_t elemSize1() const; |
RyoheiHagimoto | 0:0e0631af0305 | 2619 | |
RyoheiHagimoto | 0:0e0631af0305 | 2620 | //! returns type of sparse matrix elements |
RyoheiHagimoto | 0:0e0631af0305 | 2621 | int type() const; |
RyoheiHagimoto | 0:0e0631af0305 | 2622 | //! returns the depth of sparse matrix elements |
RyoheiHagimoto | 0:0e0631af0305 | 2623 | int depth() const; |
RyoheiHagimoto | 0:0e0631af0305 | 2624 | //! returns the number of channels |
RyoheiHagimoto | 0:0e0631af0305 | 2625 | int channels() const; |
RyoheiHagimoto | 0:0e0631af0305 | 2626 | |
RyoheiHagimoto | 0:0e0631af0305 | 2627 | //! returns the array of sizes, or NULL if the matrix is not allocated |
RyoheiHagimoto | 0:0e0631af0305 | 2628 | const int* size() const; |
RyoheiHagimoto | 0:0e0631af0305 | 2629 | //! returns the size of i-th matrix dimension (or 0) |
RyoheiHagimoto | 0:0e0631af0305 | 2630 | int size(int i) const; |
RyoheiHagimoto | 0:0e0631af0305 | 2631 | //! returns the matrix dimensionality |
RyoheiHagimoto | 0:0e0631af0305 | 2632 | int dims() const; |
RyoheiHagimoto | 0:0e0631af0305 | 2633 | //! returns the number of non-zero elements (=the number of hash table nodes) |
RyoheiHagimoto | 0:0e0631af0305 | 2634 | size_t nzcount() const; |
RyoheiHagimoto | 0:0e0631af0305 | 2635 | |
RyoheiHagimoto | 0:0e0631af0305 | 2636 | //! computes the element hash value (1D case) |
RyoheiHagimoto | 0:0e0631af0305 | 2637 | size_t hash(int i0) const; |
RyoheiHagimoto | 0:0e0631af0305 | 2638 | //! computes the element hash value (2D case) |
RyoheiHagimoto | 0:0e0631af0305 | 2639 | size_t hash(int i0, int i1) const; |
RyoheiHagimoto | 0:0e0631af0305 | 2640 | //! computes the element hash value (3D case) |
RyoheiHagimoto | 0:0e0631af0305 | 2641 | size_t hash(int i0, int i1, int i2) const; |
RyoheiHagimoto | 0:0e0631af0305 | 2642 | //! computes the element hash value (nD case) |
RyoheiHagimoto | 0:0e0631af0305 | 2643 | size_t hash(const int* idx) const; |
RyoheiHagimoto | 0:0e0631af0305 | 2644 | |
RyoheiHagimoto | 0:0e0631af0305 | 2645 | //!@{ |
RyoheiHagimoto | 0:0e0631af0305 | 2646 | /*! |
RyoheiHagimoto | 0:0e0631af0305 | 2647 | specialized variants for 1D, 2D, 3D cases and the generic_type one for n-D case. |
RyoheiHagimoto | 0:0e0631af0305 | 2648 | return pointer to the matrix element. |
RyoheiHagimoto | 0:0e0631af0305 | 2649 | - if the element is there (it's non-zero), the pointer to it is returned |
RyoheiHagimoto | 0:0e0631af0305 | 2650 | - if it's not there and createMissing=false, NULL pointer is returned |
RyoheiHagimoto | 0:0e0631af0305 | 2651 | - if it's not there and createMissing=true, then the new element |
RyoheiHagimoto | 0:0e0631af0305 | 2652 | is created and initialized with 0. Pointer to it is returned |
RyoheiHagimoto | 0:0e0631af0305 | 2653 | - if the optional hashval pointer is not NULL, the element hash value is |
RyoheiHagimoto | 0:0e0631af0305 | 2654 | not computed, but *hashval is taken instead. |
RyoheiHagimoto | 0:0e0631af0305 | 2655 | */ |
RyoheiHagimoto | 0:0e0631af0305 | 2656 | //! returns pointer to the specified element (1D case) |
RyoheiHagimoto | 0:0e0631af0305 | 2657 | uchar* ptr(int i0, bool createMissing, size_t* hashval=0); |
RyoheiHagimoto | 0:0e0631af0305 | 2658 | //! returns pointer to the specified element (2D case) |
RyoheiHagimoto | 0:0e0631af0305 | 2659 | uchar* ptr(int i0, int i1, bool createMissing, size_t* hashval=0); |
RyoheiHagimoto | 0:0e0631af0305 | 2660 | //! returns pointer to the specified element (3D case) |
RyoheiHagimoto | 0:0e0631af0305 | 2661 | uchar* ptr(int i0, int i1, int i2, bool createMissing, size_t* hashval=0); |
RyoheiHagimoto | 0:0e0631af0305 | 2662 | //! returns pointer to the specified element (nD case) |
RyoheiHagimoto | 0:0e0631af0305 | 2663 | uchar* ptr(const int* idx, bool createMissing, size_t* hashval=0); |
RyoheiHagimoto | 0:0e0631af0305 | 2664 | //!@} |
RyoheiHagimoto | 0:0e0631af0305 | 2665 | |
RyoheiHagimoto | 0:0e0631af0305 | 2666 | //!@{ |
RyoheiHagimoto | 0:0e0631af0305 | 2667 | /*! |
RyoheiHagimoto | 0:0e0631af0305 | 2668 | return read-write reference to the specified sparse matrix element. |
RyoheiHagimoto | 0:0e0631af0305 | 2669 | |
RyoheiHagimoto | 0:0e0631af0305 | 2670 | `ref<_Tp>(i0,...[,hashval])` is equivalent to `*(_Tp*)ptr(i0,...,true[,hashval])`. |
RyoheiHagimoto | 0:0e0631af0305 | 2671 | The methods always return a valid reference. |
RyoheiHagimoto | 0:0e0631af0305 | 2672 | If the element did not exist, it is created and initialiazed with 0. |
RyoheiHagimoto | 0:0e0631af0305 | 2673 | */ |
RyoheiHagimoto | 0:0e0631af0305 | 2674 | //! returns reference to the specified element (1D case) |
RyoheiHagimoto | 0:0e0631af0305 | 2675 | template<typename _Tp> _Tp& ref(int i0, size_t* hashval=0); |
RyoheiHagimoto | 0:0e0631af0305 | 2676 | //! returns reference to the specified element (2D case) |
RyoheiHagimoto | 0:0e0631af0305 | 2677 | template<typename _Tp> _Tp& ref(int i0, int i1, size_t* hashval=0); |
RyoheiHagimoto | 0:0e0631af0305 | 2678 | //! returns reference to the specified element (3D case) |
RyoheiHagimoto | 0:0e0631af0305 | 2679 | template<typename _Tp> _Tp& ref(int i0, int i1, int i2, size_t* hashval=0); |
RyoheiHagimoto | 0:0e0631af0305 | 2680 | //! returns reference to the specified element (nD case) |
RyoheiHagimoto | 0:0e0631af0305 | 2681 | template<typename _Tp> _Tp& ref(const int* idx, size_t* hashval=0); |
RyoheiHagimoto | 0:0e0631af0305 | 2682 | //!@} |
RyoheiHagimoto | 0:0e0631af0305 | 2683 | |
RyoheiHagimoto | 0:0e0631af0305 | 2684 | //!@{ |
RyoheiHagimoto | 0:0e0631af0305 | 2685 | /*! |
RyoheiHagimoto | 0:0e0631af0305 | 2686 | return value of the specified sparse matrix element. |
RyoheiHagimoto | 0:0e0631af0305 | 2687 | |
RyoheiHagimoto | 0:0e0631af0305 | 2688 | `value<_Tp>(i0,...[,hashval])` is equivalent to |
RyoheiHagimoto | 0:0e0631af0305 | 2689 | @code |
RyoheiHagimoto | 0:0e0631af0305 | 2690 | { const _Tp* p = find<_Tp>(i0,...[,hashval]); return p ? *p : _Tp(); } |
RyoheiHagimoto | 0:0e0631af0305 | 2691 | @endcode |
RyoheiHagimoto | 0:0e0631af0305 | 2692 | |
RyoheiHagimoto | 0:0e0631af0305 | 2693 | That is, if the element did not exist, the methods return 0. |
RyoheiHagimoto | 0:0e0631af0305 | 2694 | */ |
RyoheiHagimoto | 0:0e0631af0305 | 2695 | //! returns value of the specified element (1D case) |
RyoheiHagimoto | 0:0e0631af0305 | 2696 | template<typename _Tp> _Tp value(int i0, size_t* hashval=0) const; |
RyoheiHagimoto | 0:0e0631af0305 | 2697 | //! returns value of the specified element (2D case) |
RyoheiHagimoto | 0:0e0631af0305 | 2698 | template<typename _Tp> _Tp value(int i0, int i1, size_t* hashval=0) const; |
RyoheiHagimoto | 0:0e0631af0305 | 2699 | //! returns value of the specified element (3D case) |
RyoheiHagimoto | 0:0e0631af0305 | 2700 | template<typename _Tp> _Tp value(int i0, int i1, int i2, size_t* hashval=0) const; |
RyoheiHagimoto | 0:0e0631af0305 | 2701 | //! returns value of the specified element (nD case) |
RyoheiHagimoto | 0:0e0631af0305 | 2702 | template<typename _Tp> _Tp value(const int* idx, size_t* hashval=0) const; |
RyoheiHagimoto | 0:0e0631af0305 | 2703 | //!@} |
RyoheiHagimoto | 0:0e0631af0305 | 2704 | |
RyoheiHagimoto | 0:0e0631af0305 | 2705 | //!@{ |
RyoheiHagimoto | 0:0e0631af0305 | 2706 | /*! |
RyoheiHagimoto | 0:0e0631af0305 | 2707 | Return pointer to the specified sparse matrix element if it exists |
RyoheiHagimoto | 0:0e0631af0305 | 2708 | |
RyoheiHagimoto | 0:0e0631af0305 | 2709 | `find<_Tp>(i0,...[,hashval])` is equivalent to `(_const Tp*)ptr(i0,...false[,hashval])`. |
RyoheiHagimoto | 0:0e0631af0305 | 2710 | |
RyoheiHagimoto | 0:0e0631af0305 | 2711 | If the specified element does not exist, the methods return NULL. |
RyoheiHagimoto | 0:0e0631af0305 | 2712 | */ |
RyoheiHagimoto | 0:0e0631af0305 | 2713 | //! returns pointer to the specified element (1D case) |
RyoheiHagimoto | 0:0e0631af0305 | 2714 | template<typename _Tp> const _Tp* find(int i0, size_t* hashval=0) const; |
RyoheiHagimoto | 0:0e0631af0305 | 2715 | //! returns pointer to the specified element (2D case) |
RyoheiHagimoto | 0:0e0631af0305 | 2716 | template<typename _Tp> const _Tp* find(int i0, int i1, size_t* hashval=0) const; |
RyoheiHagimoto | 0:0e0631af0305 | 2717 | //! returns pointer to the specified element (3D case) |
RyoheiHagimoto | 0:0e0631af0305 | 2718 | template<typename _Tp> const _Tp* find(int i0, int i1, int i2, size_t* hashval=0) const; |
RyoheiHagimoto | 0:0e0631af0305 | 2719 | //! returns pointer to the specified element (nD case) |
RyoheiHagimoto | 0:0e0631af0305 | 2720 | template<typename _Tp> const _Tp* find(const int* idx, size_t* hashval=0) const; |
RyoheiHagimoto | 0:0e0631af0305 | 2721 | //!@} |
RyoheiHagimoto | 0:0e0631af0305 | 2722 | |
RyoheiHagimoto | 0:0e0631af0305 | 2723 | //! erases the specified element (2D case) |
RyoheiHagimoto | 0:0e0631af0305 | 2724 | void erase(int i0, int i1, size_t* hashval=0); |
RyoheiHagimoto | 0:0e0631af0305 | 2725 | //! erases the specified element (3D case) |
RyoheiHagimoto | 0:0e0631af0305 | 2726 | void erase(int i0, int i1, int i2, size_t* hashval=0); |
RyoheiHagimoto | 0:0e0631af0305 | 2727 | //! erases the specified element (nD case) |
RyoheiHagimoto | 0:0e0631af0305 | 2728 | void erase(const int* idx, size_t* hashval=0); |
RyoheiHagimoto | 0:0e0631af0305 | 2729 | |
RyoheiHagimoto | 0:0e0631af0305 | 2730 | //!@{ |
RyoheiHagimoto | 0:0e0631af0305 | 2731 | /*! |
RyoheiHagimoto | 0:0e0631af0305 | 2732 | return the sparse matrix iterator pointing to the first sparse matrix element |
RyoheiHagimoto | 0:0e0631af0305 | 2733 | */ |
RyoheiHagimoto | 0:0e0631af0305 | 2734 | //! returns the sparse matrix iterator at the matrix beginning |
RyoheiHagimoto | 0:0e0631af0305 | 2735 | SparseMatIterator begin(); |
RyoheiHagimoto | 0:0e0631af0305 | 2736 | //! returns the sparse matrix iterator at the matrix beginning |
RyoheiHagimoto | 0:0e0631af0305 | 2737 | template<typename _Tp> SparseMatIterator_<_Tp> begin(); |
RyoheiHagimoto | 0:0e0631af0305 | 2738 | //! returns the read-only sparse matrix iterator at the matrix beginning |
RyoheiHagimoto | 0:0e0631af0305 | 2739 | SparseMatConstIterator begin() const; |
RyoheiHagimoto | 0:0e0631af0305 | 2740 | //! returns the read-only sparse matrix iterator at the matrix beginning |
RyoheiHagimoto | 0:0e0631af0305 | 2741 | template<typename _Tp> SparseMatConstIterator_<_Tp> begin() const; |
RyoheiHagimoto | 0:0e0631af0305 | 2742 | //!@} |
RyoheiHagimoto | 0:0e0631af0305 | 2743 | /*! |
RyoheiHagimoto | 0:0e0631af0305 | 2744 | return the sparse matrix iterator pointing to the element following the last sparse matrix element |
RyoheiHagimoto | 0:0e0631af0305 | 2745 | */ |
RyoheiHagimoto | 0:0e0631af0305 | 2746 | //! returns the sparse matrix iterator at the matrix end |
RyoheiHagimoto | 0:0e0631af0305 | 2747 | SparseMatIterator end(); |
RyoheiHagimoto | 0:0e0631af0305 | 2748 | //! returns the read-only sparse matrix iterator at the matrix end |
RyoheiHagimoto | 0:0e0631af0305 | 2749 | SparseMatConstIterator end() const; |
RyoheiHagimoto | 0:0e0631af0305 | 2750 | //! returns the typed sparse matrix iterator at the matrix end |
RyoheiHagimoto | 0:0e0631af0305 | 2751 | template<typename _Tp> SparseMatIterator_<_Tp> end(); |
RyoheiHagimoto | 0:0e0631af0305 | 2752 | //! returns the typed read-only sparse matrix iterator at the matrix end |
RyoheiHagimoto | 0:0e0631af0305 | 2753 | template<typename _Tp> SparseMatConstIterator_<_Tp> end() const; |
RyoheiHagimoto | 0:0e0631af0305 | 2754 | |
RyoheiHagimoto | 0:0e0631af0305 | 2755 | //! returns the value stored in the sparse martix node |
RyoheiHagimoto | 0:0e0631af0305 | 2756 | template<typename _Tp> _Tp& value(Node* n); |
RyoheiHagimoto | 0:0e0631af0305 | 2757 | //! returns the value stored in the sparse martix node |
RyoheiHagimoto | 0:0e0631af0305 | 2758 | template<typename _Tp> const _Tp& value(const Node* n) const; |
RyoheiHagimoto | 0:0e0631af0305 | 2759 | |
RyoheiHagimoto | 0:0e0631af0305 | 2760 | ////////////// some internal-use methods /////////////// |
RyoheiHagimoto | 0:0e0631af0305 | 2761 | Node* node(size_t nidx); |
RyoheiHagimoto | 0:0e0631af0305 | 2762 | const Node* node(size_t nidx) const; |
RyoheiHagimoto | 0:0e0631af0305 | 2763 | |
RyoheiHagimoto | 0:0e0631af0305 | 2764 | uchar* newNode(const int* idx, size_t hashval); |
RyoheiHagimoto | 0:0e0631af0305 | 2765 | void removeNode(size_t hidx, size_t nidx, size_t previdx); |
RyoheiHagimoto | 0:0e0631af0305 | 2766 | void resizeHashTab(size_t newsize); |
RyoheiHagimoto | 0:0e0631af0305 | 2767 | |
RyoheiHagimoto | 0:0e0631af0305 | 2768 | int flags; |
RyoheiHagimoto | 0:0e0631af0305 | 2769 | Hdr* hdr; |
RyoheiHagimoto | 0:0e0631af0305 | 2770 | }; |
RyoheiHagimoto | 0:0e0631af0305 | 2771 | |
RyoheiHagimoto | 0:0e0631af0305 | 2772 | |
RyoheiHagimoto | 0:0e0631af0305 | 2773 | |
RyoheiHagimoto | 0:0e0631af0305 | 2774 | ///////////////////////////////// SparseMat_<_Tp> //////////////////////////////////// |
RyoheiHagimoto | 0:0e0631af0305 | 2775 | |
RyoheiHagimoto | 0:0e0631af0305 | 2776 | /** @brief Template sparse n-dimensional array class derived from SparseMat |
RyoheiHagimoto | 0:0e0631af0305 | 2777 | |
RyoheiHagimoto | 0:0e0631af0305 | 2778 | SparseMat_ is a thin wrapper on top of SparseMat created in the same way as Mat_ . It simplifies |
RyoheiHagimoto | 0:0e0631af0305 | 2779 | notation of some operations: |
RyoheiHagimoto | 0:0e0631af0305 | 2780 | @code |
RyoheiHagimoto | 0:0e0631af0305 | 2781 | int sz[] = {10, 20, 30}; |
RyoheiHagimoto | 0:0e0631af0305 | 2782 | SparseMat_<double> M(3, sz); |
RyoheiHagimoto | 0:0e0631af0305 | 2783 | ... |
RyoheiHagimoto | 0:0e0631af0305 | 2784 | M.ref(1, 2, 3) = M(4, 5, 6) + M(7, 8, 9); |
RyoheiHagimoto | 0:0e0631af0305 | 2785 | @endcode |
RyoheiHagimoto | 0:0e0631af0305 | 2786 | */ |
RyoheiHagimoto | 0:0e0631af0305 | 2787 | template<typename _Tp> class SparseMat_ : public SparseMat |
RyoheiHagimoto | 0:0e0631af0305 | 2788 | { |
RyoheiHagimoto | 0:0e0631af0305 | 2789 | public: |
RyoheiHagimoto | 0:0e0631af0305 | 2790 | typedef SparseMatIterator_<_Tp> iterator; |
RyoheiHagimoto | 0:0e0631af0305 | 2791 | typedef SparseMatConstIterator_<_Tp> const_iterator; |
RyoheiHagimoto | 0:0e0631af0305 | 2792 | |
RyoheiHagimoto | 0:0e0631af0305 | 2793 | //! the default constructor |
RyoheiHagimoto | 0:0e0631af0305 | 2794 | SparseMat_(); |
RyoheiHagimoto | 0:0e0631af0305 | 2795 | //! the full constructor equivelent to SparseMat(dims, _sizes, DataType<_Tp>::type) |
RyoheiHagimoto | 0:0e0631af0305 | 2796 | SparseMat_(int dims, const int* _sizes); |
RyoheiHagimoto | 0:0e0631af0305 | 2797 | //! the copy constructor. If DataType<_Tp>.type != m.type(), the m elements are converted |
RyoheiHagimoto | 0:0e0631af0305 | 2798 | SparseMat_(const SparseMat& m); |
RyoheiHagimoto | 0:0e0631af0305 | 2799 | //! the copy constructor. This is O(1) operation - no data is copied |
RyoheiHagimoto | 0:0e0631af0305 | 2800 | SparseMat_(const SparseMat_& m); |
RyoheiHagimoto | 0:0e0631af0305 | 2801 | //! converts dense matrix to the sparse form |
RyoheiHagimoto | 0:0e0631af0305 | 2802 | SparseMat_(const Mat& m); |
RyoheiHagimoto | 0:0e0631af0305 | 2803 | //! converts the old-style sparse matrix to the C++ class. All the elements are copied |
RyoheiHagimoto | 0:0e0631af0305 | 2804 | //SparseMat_(const CvSparseMat* m); |
RyoheiHagimoto | 0:0e0631af0305 | 2805 | //! the assignment operator. If DataType<_Tp>.type != m.type(), the m elements are converted |
RyoheiHagimoto | 0:0e0631af0305 | 2806 | SparseMat_& operator = (const SparseMat& m); |
RyoheiHagimoto | 0:0e0631af0305 | 2807 | //! the assignment operator. This is O(1) operation - no data is copied |
RyoheiHagimoto | 0:0e0631af0305 | 2808 | SparseMat_& operator = (const SparseMat_& m); |
RyoheiHagimoto | 0:0e0631af0305 | 2809 | //! converts dense matrix to the sparse form |
RyoheiHagimoto | 0:0e0631af0305 | 2810 | SparseMat_& operator = (const Mat& m); |
RyoheiHagimoto | 0:0e0631af0305 | 2811 | |
RyoheiHagimoto | 0:0e0631af0305 | 2812 | //! makes full copy of the matrix. All the elements are duplicated |
RyoheiHagimoto | 0:0e0631af0305 | 2813 | SparseMat_ clone() const; |
RyoheiHagimoto | 0:0e0631af0305 | 2814 | //! equivalent to cv::SparseMat::create(dims, _sizes, DataType<_Tp>::type) |
RyoheiHagimoto | 0:0e0631af0305 | 2815 | void create(int dims, const int* _sizes); |
RyoheiHagimoto | 0:0e0631af0305 | 2816 | //! converts sparse matrix to the old-style CvSparseMat. All the elements are copied |
RyoheiHagimoto | 0:0e0631af0305 | 2817 | //operator CvSparseMat*() const; |
RyoheiHagimoto | 0:0e0631af0305 | 2818 | |
RyoheiHagimoto | 0:0e0631af0305 | 2819 | //! returns type of the matrix elements |
RyoheiHagimoto | 0:0e0631af0305 | 2820 | int type() const; |
RyoheiHagimoto | 0:0e0631af0305 | 2821 | //! returns depth of the matrix elements |
RyoheiHagimoto | 0:0e0631af0305 | 2822 | int depth() const; |
RyoheiHagimoto | 0:0e0631af0305 | 2823 | //! returns the number of channels in each matrix element |
RyoheiHagimoto | 0:0e0631af0305 | 2824 | int channels() const; |
RyoheiHagimoto | 0:0e0631af0305 | 2825 | |
RyoheiHagimoto | 0:0e0631af0305 | 2826 | //! equivalent to SparseMat::ref<_Tp>(i0, hashval) |
RyoheiHagimoto | 0:0e0631af0305 | 2827 | _Tp& ref(int i0, size_t* hashval=0); |
RyoheiHagimoto | 0:0e0631af0305 | 2828 | //! equivalent to SparseMat::ref<_Tp>(i0, i1, hashval) |
RyoheiHagimoto | 0:0e0631af0305 | 2829 | _Tp& ref(int i0, int i1, size_t* hashval=0); |
RyoheiHagimoto | 0:0e0631af0305 | 2830 | //! equivalent to SparseMat::ref<_Tp>(i0, i1, i2, hashval) |
RyoheiHagimoto | 0:0e0631af0305 | 2831 | _Tp& ref(int i0, int i1, int i2, size_t* hashval=0); |
RyoheiHagimoto | 0:0e0631af0305 | 2832 | //! equivalent to SparseMat::ref<_Tp>(idx, hashval) |
RyoheiHagimoto | 0:0e0631af0305 | 2833 | _Tp& ref(const int* idx, size_t* hashval=0); |
RyoheiHagimoto | 0:0e0631af0305 | 2834 | |
RyoheiHagimoto | 0:0e0631af0305 | 2835 | //! equivalent to SparseMat::value<_Tp>(i0, hashval) |
RyoheiHagimoto | 0:0e0631af0305 | 2836 | _Tp operator()(int i0, size_t* hashval=0) const; |
RyoheiHagimoto | 0:0e0631af0305 | 2837 | //! equivalent to SparseMat::value<_Tp>(i0, i1, hashval) |
RyoheiHagimoto | 0:0e0631af0305 | 2838 | _Tp operator()(int i0, int i1, size_t* hashval=0) const; |
RyoheiHagimoto | 0:0e0631af0305 | 2839 | //! equivalent to SparseMat::value<_Tp>(i0, i1, i2, hashval) |
RyoheiHagimoto | 0:0e0631af0305 | 2840 | _Tp operator()(int i0, int i1, int i2, size_t* hashval=0) const; |
RyoheiHagimoto | 0:0e0631af0305 | 2841 | //! equivalent to SparseMat::value<_Tp>(idx, hashval) |
RyoheiHagimoto | 0:0e0631af0305 | 2842 | _Tp operator()(const int* idx, size_t* hashval=0) const; |
RyoheiHagimoto | 0:0e0631af0305 | 2843 | |
RyoheiHagimoto | 0:0e0631af0305 | 2844 | //! returns sparse matrix iterator pointing to the first sparse matrix element |
RyoheiHagimoto | 0:0e0631af0305 | 2845 | SparseMatIterator_<_Tp> begin(); |
RyoheiHagimoto | 0:0e0631af0305 | 2846 | //! returns read-only sparse matrix iterator pointing to the first sparse matrix element |
RyoheiHagimoto | 0:0e0631af0305 | 2847 | SparseMatConstIterator_<_Tp> begin() const; |
RyoheiHagimoto | 0:0e0631af0305 | 2848 | //! returns sparse matrix iterator pointing to the element following the last sparse matrix element |
RyoheiHagimoto | 0:0e0631af0305 | 2849 | SparseMatIterator_<_Tp> end(); |
RyoheiHagimoto | 0:0e0631af0305 | 2850 | //! returns read-only sparse matrix iterator pointing to the element following the last sparse matrix element |
RyoheiHagimoto | 0:0e0631af0305 | 2851 | SparseMatConstIterator_<_Tp> end() const; |
RyoheiHagimoto | 0:0e0631af0305 | 2852 | }; |
RyoheiHagimoto | 0:0e0631af0305 | 2853 | |
RyoheiHagimoto | 0:0e0631af0305 | 2854 | |
RyoheiHagimoto | 0:0e0631af0305 | 2855 | |
RyoheiHagimoto | 0:0e0631af0305 | 2856 | ////////////////////////////////// MatConstIterator ////////////////////////////////// |
RyoheiHagimoto | 0:0e0631af0305 | 2857 | |
RyoheiHagimoto | 0:0e0631af0305 | 2858 | class CV_EXPORTS MatConstIterator |
RyoheiHagimoto | 0:0e0631af0305 | 2859 | { |
RyoheiHagimoto | 0:0e0631af0305 | 2860 | public: |
RyoheiHagimoto | 0:0e0631af0305 | 2861 | typedef uchar* value_type; |
RyoheiHagimoto | 0:0e0631af0305 | 2862 | typedef ptrdiff_t difference_type; |
RyoheiHagimoto | 0:0e0631af0305 | 2863 | typedef const uchar** pointer; |
RyoheiHagimoto | 0:0e0631af0305 | 2864 | typedef uchar* reference; |
RyoheiHagimoto | 0:0e0631af0305 | 2865 | |
RyoheiHagimoto | 0:0e0631af0305 | 2866 | #ifndef OPENCV_NOSTL |
RyoheiHagimoto | 0:0e0631af0305 | 2867 | typedef std::random_access_iterator_tag iterator_category; |
RyoheiHagimoto | 0:0e0631af0305 | 2868 | #endif |
RyoheiHagimoto | 0:0e0631af0305 | 2869 | |
RyoheiHagimoto | 0:0e0631af0305 | 2870 | //! default constructor |
RyoheiHagimoto | 0:0e0631af0305 | 2871 | MatConstIterator(); |
RyoheiHagimoto | 0:0e0631af0305 | 2872 | //! constructor that sets the iterator to the beginning of the matrix |
RyoheiHagimoto | 0:0e0631af0305 | 2873 | MatConstIterator(const Mat* _m); |
RyoheiHagimoto | 0:0e0631af0305 | 2874 | //! constructor that sets the iterator to the specified element of the matrix |
RyoheiHagimoto | 0:0e0631af0305 | 2875 | MatConstIterator(const Mat* _m, int _row, int _col=0); |
RyoheiHagimoto | 0:0e0631af0305 | 2876 | //! constructor that sets the iterator to the specified element of the matrix |
RyoheiHagimoto | 0:0e0631af0305 | 2877 | MatConstIterator(const Mat* _m, Point _pt); |
RyoheiHagimoto | 0:0e0631af0305 | 2878 | //! constructor that sets the iterator to the specified element of the matrix |
RyoheiHagimoto | 0:0e0631af0305 | 2879 | MatConstIterator(const Mat* _m, const int* _idx); |
RyoheiHagimoto | 0:0e0631af0305 | 2880 | //! copy constructor |
RyoheiHagimoto | 0:0e0631af0305 | 2881 | MatConstIterator(const MatConstIterator& it); |
RyoheiHagimoto | 0:0e0631af0305 | 2882 | |
RyoheiHagimoto | 0:0e0631af0305 | 2883 | //! copy operator |
RyoheiHagimoto | 0:0e0631af0305 | 2884 | MatConstIterator& operator = (const MatConstIterator& it); |
RyoheiHagimoto | 0:0e0631af0305 | 2885 | //! returns the current matrix element |
RyoheiHagimoto | 0:0e0631af0305 | 2886 | const uchar* operator *() const; |
RyoheiHagimoto | 0:0e0631af0305 | 2887 | //! returns the i-th matrix element, relative to the current |
RyoheiHagimoto | 0:0e0631af0305 | 2888 | const uchar* operator [](ptrdiff_t i) const; |
RyoheiHagimoto | 0:0e0631af0305 | 2889 | |
RyoheiHagimoto | 0:0e0631af0305 | 2890 | //! shifts the iterator forward by the specified number of elements |
RyoheiHagimoto | 0:0e0631af0305 | 2891 | MatConstIterator& operator += (ptrdiff_t ofs); |
RyoheiHagimoto | 0:0e0631af0305 | 2892 | //! shifts the iterator backward by the specified number of elements |
RyoheiHagimoto | 0:0e0631af0305 | 2893 | MatConstIterator& operator -= (ptrdiff_t ofs); |
RyoheiHagimoto | 0:0e0631af0305 | 2894 | //! decrements the iterator |
RyoheiHagimoto | 0:0e0631af0305 | 2895 | MatConstIterator& operator --(); |
RyoheiHagimoto | 0:0e0631af0305 | 2896 | //! decrements the iterator |
RyoheiHagimoto | 0:0e0631af0305 | 2897 | MatConstIterator operator --(int); |
RyoheiHagimoto | 0:0e0631af0305 | 2898 | //! increments the iterator |
RyoheiHagimoto | 0:0e0631af0305 | 2899 | MatConstIterator& operator ++(); |
RyoheiHagimoto | 0:0e0631af0305 | 2900 | //! increments the iterator |
RyoheiHagimoto | 0:0e0631af0305 | 2901 | MatConstIterator operator ++(int); |
RyoheiHagimoto | 0:0e0631af0305 | 2902 | //! returns the current iterator position |
RyoheiHagimoto | 0:0e0631af0305 | 2903 | Point pos() const; |
RyoheiHagimoto | 0:0e0631af0305 | 2904 | //! returns the current iterator position |
RyoheiHagimoto | 0:0e0631af0305 | 2905 | void pos(int* _idx) const; |
RyoheiHagimoto | 0:0e0631af0305 | 2906 | |
RyoheiHagimoto | 0:0e0631af0305 | 2907 | ptrdiff_t lpos() const; |
RyoheiHagimoto | 0:0e0631af0305 | 2908 | void seek(ptrdiff_t ofs, bool relative = false); |
RyoheiHagimoto | 0:0e0631af0305 | 2909 | void seek(const int* _idx, bool relative = false); |
RyoheiHagimoto | 0:0e0631af0305 | 2910 | |
RyoheiHagimoto | 0:0e0631af0305 | 2911 | const Mat* m; |
RyoheiHagimoto | 0:0e0631af0305 | 2912 | size_t elemSize; |
RyoheiHagimoto | 0:0e0631af0305 | 2913 | const uchar* ptr; |
RyoheiHagimoto | 0:0e0631af0305 | 2914 | const uchar* sliceStart; |
RyoheiHagimoto | 0:0e0631af0305 | 2915 | const uchar* sliceEnd; |
RyoheiHagimoto | 0:0e0631af0305 | 2916 | }; |
RyoheiHagimoto | 0:0e0631af0305 | 2917 | |
RyoheiHagimoto | 0:0e0631af0305 | 2918 | |
RyoheiHagimoto | 0:0e0631af0305 | 2919 | |
RyoheiHagimoto | 0:0e0631af0305 | 2920 | ////////////////////////////////// MatConstIterator_ ///////////////////////////////// |
RyoheiHagimoto | 0:0e0631af0305 | 2921 | |
RyoheiHagimoto | 0:0e0631af0305 | 2922 | /** @brief Matrix read-only iterator |
RyoheiHagimoto | 0:0e0631af0305 | 2923 | */ |
RyoheiHagimoto | 0:0e0631af0305 | 2924 | template<typename _Tp> |
RyoheiHagimoto | 0:0e0631af0305 | 2925 | class MatConstIterator_ : public MatConstIterator |
RyoheiHagimoto | 0:0e0631af0305 | 2926 | { |
RyoheiHagimoto | 0:0e0631af0305 | 2927 | public: |
RyoheiHagimoto | 0:0e0631af0305 | 2928 | typedef _Tp value_type; |
RyoheiHagimoto | 0:0e0631af0305 | 2929 | typedef ptrdiff_t difference_type; |
RyoheiHagimoto | 0:0e0631af0305 | 2930 | typedef const _Tp* pointer; |
RyoheiHagimoto | 0:0e0631af0305 | 2931 | typedef const _Tp& reference; |
RyoheiHagimoto | 0:0e0631af0305 | 2932 | |
RyoheiHagimoto | 0:0e0631af0305 | 2933 | #ifndef OPENCV_NOSTL |
RyoheiHagimoto | 0:0e0631af0305 | 2934 | typedef std::random_access_iterator_tag iterator_category; |
RyoheiHagimoto | 0:0e0631af0305 | 2935 | #endif |
RyoheiHagimoto | 0:0e0631af0305 | 2936 | |
RyoheiHagimoto | 0:0e0631af0305 | 2937 | //! default constructor |
RyoheiHagimoto | 0:0e0631af0305 | 2938 | MatConstIterator_(); |
RyoheiHagimoto | 0:0e0631af0305 | 2939 | //! constructor that sets the iterator to the beginning of the matrix |
RyoheiHagimoto | 0:0e0631af0305 | 2940 | MatConstIterator_(const Mat_<_Tp>* _m); |
RyoheiHagimoto | 0:0e0631af0305 | 2941 | //! constructor that sets the iterator to the specified element of the matrix |
RyoheiHagimoto | 0:0e0631af0305 | 2942 | MatConstIterator_(const Mat_<_Tp>* _m, int _row, int _col=0); |
RyoheiHagimoto | 0:0e0631af0305 | 2943 | //! constructor that sets the iterator to the specified element of the matrix |
RyoheiHagimoto | 0:0e0631af0305 | 2944 | MatConstIterator_(const Mat_<_Tp>* _m, Point _pt); |
RyoheiHagimoto | 0:0e0631af0305 | 2945 | //! constructor that sets the iterator to the specified element of the matrix |
RyoheiHagimoto | 0:0e0631af0305 | 2946 | MatConstIterator_(const Mat_<_Tp>* _m, const int* _idx); |
RyoheiHagimoto | 0:0e0631af0305 | 2947 | //! copy constructor |
RyoheiHagimoto | 0:0e0631af0305 | 2948 | MatConstIterator_(const MatConstIterator_& it); |
RyoheiHagimoto | 0:0e0631af0305 | 2949 | |
RyoheiHagimoto | 0:0e0631af0305 | 2950 | //! copy operator |
RyoheiHagimoto | 0:0e0631af0305 | 2951 | MatConstIterator_& operator = (const MatConstIterator_& it); |
RyoheiHagimoto | 0:0e0631af0305 | 2952 | //! returns the current matrix element |
RyoheiHagimoto | 0:0e0631af0305 | 2953 | const _Tp& operator *() const; |
RyoheiHagimoto | 0:0e0631af0305 | 2954 | //! returns the i-th matrix element, relative to the current |
RyoheiHagimoto | 0:0e0631af0305 | 2955 | const _Tp& operator [](ptrdiff_t i) const; |
RyoheiHagimoto | 0:0e0631af0305 | 2956 | |
RyoheiHagimoto | 0:0e0631af0305 | 2957 | //! shifts the iterator forward by the specified number of elements |
RyoheiHagimoto | 0:0e0631af0305 | 2958 | MatConstIterator_& operator += (ptrdiff_t ofs); |
RyoheiHagimoto | 0:0e0631af0305 | 2959 | //! shifts the iterator backward by the specified number of elements |
RyoheiHagimoto | 0:0e0631af0305 | 2960 | MatConstIterator_& operator -= (ptrdiff_t ofs); |
RyoheiHagimoto | 0:0e0631af0305 | 2961 | //! decrements the iterator |
RyoheiHagimoto | 0:0e0631af0305 | 2962 | MatConstIterator_& operator --(); |
RyoheiHagimoto | 0:0e0631af0305 | 2963 | //! decrements the iterator |
RyoheiHagimoto | 0:0e0631af0305 | 2964 | MatConstIterator_ operator --(int); |
RyoheiHagimoto | 0:0e0631af0305 | 2965 | //! increments the iterator |
RyoheiHagimoto | 0:0e0631af0305 | 2966 | MatConstIterator_& operator ++(); |
RyoheiHagimoto | 0:0e0631af0305 | 2967 | //! increments the iterator |
RyoheiHagimoto | 0:0e0631af0305 | 2968 | MatConstIterator_ operator ++(int); |
RyoheiHagimoto | 0:0e0631af0305 | 2969 | //! returns the current iterator position |
RyoheiHagimoto | 0:0e0631af0305 | 2970 | Point pos() const; |
RyoheiHagimoto | 0:0e0631af0305 | 2971 | }; |
RyoheiHagimoto | 0:0e0631af0305 | 2972 | |
RyoheiHagimoto | 0:0e0631af0305 | 2973 | |
RyoheiHagimoto | 0:0e0631af0305 | 2974 | |
RyoheiHagimoto | 0:0e0631af0305 | 2975 | //////////////////////////////////// MatIterator_ //////////////////////////////////// |
RyoheiHagimoto | 0:0e0631af0305 | 2976 | |
RyoheiHagimoto | 0:0e0631af0305 | 2977 | /** @brief Matrix read-write iterator |
RyoheiHagimoto | 0:0e0631af0305 | 2978 | */ |
RyoheiHagimoto | 0:0e0631af0305 | 2979 | template<typename _Tp> |
RyoheiHagimoto | 0:0e0631af0305 | 2980 | class MatIterator_ : public MatConstIterator_<_Tp> |
RyoheiHagimoto | 0:0e0631af0305 | 2981 | { |
RyoheiHagimoto | 0:0e0631af0305 | 2982 | public: |
RyoheiHagimoto | 0:0e0631af0305 | 2983 | typedef _Tp* pointer; |
RyoheiHagimoto | 0:0e0631af0305 | 2984 | typedef _Tp& reference; |
RyoheiHagimoto | 0:0e0631af0305 | 2985 | |
RyoheiHagimoto | 0:0e0631af0305 | 2986 | #ifndef OPENCV_NOSTL |
RyoheiHagimoto | 0:0e0631af0305 | 2987 | typedef std::random_access_iterator_tag iterator_category; |
RyoheiHagimoto | 0:0e0631af0305 | 2988 | #endif |
RyoheiHagimoto | 0:0e0631af0305 | 2989 | |
RyoheiHagimoto | 0:0e0631af0305 | 2990 | //! the default constructor |
RyoheiHagimoto | 0:0e0631af0305 | 2991 | MatIterator_(); |
RyoheiHagimoto | 0:0e0631af0305 | 2992 | //! constructor that sets the iterator to the beginning of the matrix |
RyoheiHagimoto | 0:0e0631af0305 | 2993 | MatIterator_(Mat_<_Tp>* _m); |
RyoheiHagimoto | 0:0e0631af0305 | 2994 | //! constructor that sets the iterator to the specified element of the matrix |
RyoheiHagimoto | 0:0e0631af0305 | 2995 | MatIterator_(Mat_<_Tp>* _m, int _row, int _col=0); |
RyoheiHagimoto | 0:0e0631af0305 | 2996 | //! constructor that sets the iterator to the specified element of the matrix |
RyoheiHagimoto | 0:0e0631af0305 | 2997 | MatIterator_(Mat_<_Tp>* _m, Point _pt); |
RyoheiHagimoto | 0:0e0631af0305 | 2998 | //! constructor that sets the iterator to the specified element of the matrix |
RyoheiHagimoto | 0:0e0631af0305 | 2999 | MatIterator_(Mat_<_Tp>* _m, const int* _idx); |
RyoheiHagimoto | 0:0e0631af0305 | 3000 | //! copy constructor |
RyoheiHagimoto | 0:0e0631af0305 | 3001 | MatIterator_(const MatIterator_& it); |
RyoheiHagimoto | 0:0e0631af0305 | 3002 | //! copy operator |
RyoheiHagimoto | 0:0e0631af0305 | 3003 | MatIterator_& operator = (const MatIterator_<_Tp>& it ); |
RyoheiHagimoto | 0:0e0631af0305 | 3004 | |
RyoheiHagimoto | 0:0e0631af0305 | 3005 | //! returns the current matrix element |
RyoheiHagimoto | 0:0e0631af0305 | 3006 | _Tp& operator *() const; |
RyoheiHagimoto | 0:0e0631af0305 | 3007 | //! returns the i-th matrix element, relative to the current |
RyoheiHagimoto | 0:0e0631af0305 | 3008 | _Tp& operator [](ptrdiff_t i) const; |
RyoheiHagimoto | 0:0e0631af0305 | 3009 | |
RyoheiHagimoto | 0:0e0631af0305 | 3010 | //! shifts the iterator forward by the specified number of elements |
RyoheiHagimoto | 0:0e0631af0305 | 3011 | MatIterator_& operator += (ptrdiff_t ofs); |
RyoheiHagimoto | 0:0e0631af0305 | 3012 | //! shifts the iterator backward by the specified number of elements |
RyoheiHagimoto | 0:0e0631af0305 | 3013 | MatIterator_& operator -= (ptrdiff_t ofs); |
RyoheiHagimoto | 0:0e0631af0305 | 3014 | //! decrements the iterator |
RyoheiHagimoto | 0:0e0631af0305 | 3015 | MatIterator_& operator --(); |
RyoheiHagimoto | 0:0e0631af0305 | 3016 | //! decrements the iterator |
RyoheiHagimoto | 0:0e0631af0305 | 3017 | MatIterator_ operator --(int); |
RyoheiHagimoto | 0:0e0631af0305 | 3018 | //! increments the iterator |
RyoheiHagimoto | 0:0e0631af0305 | 3019 | MatIterator_& operator ++(); |
RyoheiHagimoto | 0:0e0631af0305 | 3020 | //! increments the iterator |
RyoheiHagimoto | 0:0e0631af0305 | 3021 | MatIterator_ operator ++(int); |
RyoheiHagimoto | 0:0e0631af0305 | 3022 | }; |
RyoheiHagimoto | 0:0e0631af0305 | 3023 | |
RyoheiHagimoto | 0:0e0631af0305 | 3024 | |
RyoheiHagimoto | 0:0e0631af0305 | 3025 | |
RyoheiHagimoto | 0:0e0631af0305 | 3026 | /////////////////////////////// SparseMatConstIterator /////////////////////////////// |
RyoheiHagimoto | 0:0e0631af0305 | 3027 | |
RyoheiHagimoto | 0:0e0631af0305 | 3028 | /** @brief Read-Only Sparse Matrix Iterator. |
RyoheiHagimoto | 0:0e0631af0305 | 3029 | |
RyoheiHagimoto | 0:0e0631af0305 | 3030 | Here is how to use the iterator to compute the sum of floating-point sparse matrix elements: |
RyoheiHagimoto | 0:0e0631af0305 | 3031 | |
RyoheiHagimoto | 0:0e0631af0305 | 3032 | \code |
RyoheiHagimoto | 0:0e0631af0305 | 3033 | SparseMatConstIterator it = m.begin(), it_end = m.end(); |
RyoheiHagimoto | 0:0e0631af0305 | 3034 | double s = 0; |
RyoheiHagimoto | 0:0e0631af0305 | 3035 | CV_Assert( m.type() == CV_32F ); |
RyoheiHagimoto | 0:0e0631af0305 | 3036 | for( ; it != it_end; ++it ) |
RyoheiHagimoto | 0:0e0631af0305 | 3037 | s += it.value<float>(); |
RyoheiHagimoto | 0:0e0631af0305 | 3038 | \endcode |
RyoheiHagimoto | 0:0e0631af0305 | 3039 | */ |
RyoheiHagimoto | 0:0e0631af0305 | 3040 | class CV_EXPORTS SparseMatConstIterator |
RyoheiHagimoto | 0:0e0631af0305 | 3041 | { |
RyoheiHagimoto | 0:0e0631af0305 | 3042 | public: |
RyoheiHagimoto | 0:0e0631af0305 | 3043 | //! the default constructor |
RyoheiHagimoto | 0:0e0631af0305 | 3044 | SparseMatConstIterator(); |
RyoheiHagimoto | 0:0e0631af0305 | 3045 | //! the full constructor setting the iterator to the first sparse matrix element |
RyoheiHagimoto | 0:0e0631af0305 | 3046 | SparseMatConstIterator(const SparseMat* _m); |
RyoheiHagimoto | 0:0e0631af0305 | 3047 | //! the copy constructor |
RyoheiHagimoto | 0:0e0631af0305 | 3048 | SparseMatConstIterator(const SparseMatConstIterator& it); |
RyoheiHagimoto | 0:0e0631af0305 | 3049 | |
RyoheiHagimoto | 0:0e0631af0305 | 3050 | //! the assignment operator |
RyoheiHagimoto | 0:0e0631af0305 | 3051 | SparseMatConstIterator& operator = (const SparseMatConstIterator& it); |
RyoheiHagimoto | 0:0e0631af0305 | 3052 | |
RyoheiHagimoto | 0:0e0631af0305 | 3053 | //! template method returning the current matrix element |
RyoheiHagimoto | 0:0e0631af0305 | 3054 | template<typename _Tp> const _Tp& value() const; |
RyoheiHagimoto | 0:0e0631af0305 | 3055 | //! returns the current node of the sparse matrix. it.node->idx is the current element index |
RyoheiHagimoto | 0:0e0631af0305 | 3056 | const SparseMat::Node* node() const; |
RyoheiHagimoto | 0:0e0631af0305 | 3057 | |
RyoheiHagimoto | 0:0e0631af0305 | 3058 | //! moves iterator to the previous element |
RyoheiHagimoto | 0:0e0631af0305 | 3059 | SparseMatConstIterator& operator --(); |
RyoheiHagimoto | 0:0e0631af0305 | 3060 | //! moves iterator to the previous element |
RyoheiHagimoto | 0:0e0631af0305 | 3061 | SparseMatConstIterator operator --(int); |
RyoheiHagimoto | 0:0e0631af0305 | 3062 | //! moves iterator to the next element |
RyoheiHagimoto | 0:0e0631af0305 | 3063 | SparseMatConstIterator& operator ++(); |
RyoheiHagimoto | 0:0e0631af0305 | 3064 | //! moves iterator to the next element |
RyoheiHagimoto | 0:0e0631af0305 | 3065 | SparseMatConstIterator operator ++(int); |
RyoheiHagimoto | 0:0e0631af0305 | 3066 | |
RyoheiHagimoto | 0:0e0631af0305 | 3067 | //! moves iterator to the element after the last element |
RyoheiHagimoto | 0:0e0631af0305 | 3068 | void seekEnd(); |
RyoheiHagimoto | 0:0e0631af0305 | 3069 | |
RyoheiHagimoto | 0:0e0631af0305 | 3070 | const SparseMat* m; |
RyoheiHagimoto | 0:0e0631af0305 | 3071 | size_t hashidx; |
RyoheiHagimoto | 0:0e0631af0305 | 3072 | uchar* ptr; |
RyoheiHagimoto | 0:0e0631af0305 | 3073 | }; |
RyoheiHagimoto | 0:0e0631af0305 | 3074 | |
RyoheiHagimoto | 0:0e0631af0305 | 3075 | |
RyoheiHagimoto | 0:0e0631af0305 | 3076 | |
RyoheiHagimoto | 0:0e0631af0305 | 3077 | ////////////////////////////////// SparseMatIterator ///////////////////////////////// |
RyoheiHagimoto | 0:0e0631af0305 | 3078 | |
RyoheiHagimoto | 0:0e0631af0305 | 3079 | /** @brief Read-write Sparse Matrix Iterator |
RyoheiHagimoto | 0:0e0631af0305 | 3080 | |
RyoheiHagimoto | 0:0e0631af0305 | 3081 | The class is similar to cv::SparseMatConstIterator, |
RyoheiHagimoto | 0:0e0631af0305 | 3082 | but can be used for in-place modification of the matrix elements. |
RyoheiHagimoto | 0:0e0631af0305 | 3083 | */ |
RyoheiHagimoto | 0:0e0631af0305 | 3084 | class CV_EXPORTS SparseMatIterator : public SparseMatConstIterator |
RyoheiHagimoto | 0:0e0631af0305 | 3085 | { |
RyoheiHagimoto | 0:0e0631af0305 | 3086 | public: |
RyoheiHagimoto | 0:0e0631af0305 | 3087 | //! the default constructor |
RyoheiHagimoto | 0:0e0631af0305 | 3088 | SparseMatIterator(); |
RyoheiHagimoto | 0:0e0631af0305 | 3089 | //! the full constructor setting the iterator to the first sparse matrix element |
RyoheiHagimoto | 0:0e0631af0305 | 3090 | SparseMatIterator(SparseMat* _m); |
RyoheiHagimoto | 0:0e0631af0305 | 3091 | //! the full constructor setting the iterator to the specified sparse matrix element |
RyoheiHagimoto | 0:0e0631af0305 | 3092 | SparseMatIterator(SparseMat* _m, const int* idx); |
RyoheiHagimoto | 0:0e0631af0305 | 3093 | //! the copy constructor |
RyoheiHagimoto | 0:0e0631af0305 | 3094 | SparseMatIterator(const SparseMatIterator& it); |
RyoheiHagimoto | 0:0e0631af0305 | 3095 | |
RyoheiHagimoto | 0:0e0631af0305 | 3096 | //! the assignment operator |
RyoheiHagimoto | 0:0e0631af0305 | 3097 | SparseMatIterator& operator = (const SparseMatIterator& it); |
RyoheiHagimoto | 0:0e0631af0305 | 3098 | //! returns read-write reference to the current sparse matrix element |
RyoheiHagimoto | 0:0e0631af0305 | 3099 | template<typename _Tp> _Tp& value() const; |
RyoheiHagimoto | 0:0e0631af0305 | 3100 | //! returns pointer to the current sparse matrix node. it.node->idx is the index of the current element (do not modify it!) |
RyoheiHagimoto | 0:0e0631af0305 | 3101 | SparseMat::Node* node() const; |
RyoheiHagimoto | 0:0e0631af0305 | 3102 | |
RyoheiHagimoto | 0:0e0631af0305 | 3103 | //! moves iterator to the next element |
RyoheiHagimoto | 0:0e0631af0305 | 3104 | SparseMatIterator& operator ++(); |
RyoheiHagimoto | 0:0e0631af0305 | 3105 | //! moves iterator to the next element |
RyoheiHagimoto | 0:0e0631af0305 | 3106 | SparseMatIterator operator ++(int); |
RyoheiHagimoto | 0:0e0631af0305 | 3107 | }; |
RyoheiHagimoto | 0:0e0631af0305 | 3108 | |
RyoheiHagimoto | 0:0e0631af0305 | 3109 | |
RyoheiHagimoto | 0:0e0631af0305 | 3110 | |
RyoheiHagimoto | 0:0e0631af0305 | 3111 | /////////////////////////////// SparseMatConstIterator_ ////////////////////////////// |
RyoheiHagimoto | 0:0e0631af0305 | 3112 | |
RyoheiHagimoto | 0:0e0631af0305 | 3113 | /** @brief Template Read-Only Sparse Matrix Iterator Class. |
RyoheiHagimoto | 0:0e0631af0305 | 3114 | |
RyoheiHagimoto | 0:0e0631af0305 | 3115 | This is the derived from SparseMatConstIterator class that |
RyoheiHagimoto | 0:0e0631af0305 | 3116 | introduces more convenient operator *() for accessing the current element. |
RyoheiHagimoto | 0:0e0631af0305 | 3117 | */ |
RyoheiHagimoto | 0:0e0631af0305 | 3118 | template<typename _Tp> class SparseMatConstIterator_ : public SparseMatConstIterator |
RyoheiHagimoto | 0:0e0631af0305 | 3119 | { |
RyoheiHagimoto | 0:0e0631af0305 | 3120 | public: |
RyoheiHagimoto | 0:0e0631af0305 | 3121 | |
RyoheiHagimoto | 0:0e0631af0305 | 3122 | #ifndef OPENCV_NOSTL |
RyoheiHagimoto | 0:0e0631af0305 | 3123 | typedef std::forward_iterator_tag iterator_category; |
RyoheiHagimoto | 0:0e0631af0305 | 3124 | #endif |
RyoheiHagimoto | 0:0e0631af0305 | 3125 | |
RyoheiHagimoto | 0:0e0631af0305 | 3126 | //! the default constructor |
RyoheiHagimoto | 0:0e0631af0305 | 3127 | SparseMatConstIterator_(); |
RyoheiHagimoto | 0:0e0631af0305 | 3128 | //! the full constructor setting the iterator to the first sparse matrix element |
RyoheiHagimoto | 0:0e0631af0305 | 3129 | SparseMatConstIterator_(const SparseMat_<_Tp>* _m); |
RyoheiHagimoto | 0:0e0631af0305 | 3130 | SparseMatConstIterator_(const SparseMat* _m); |
RyoheiHagimoto | 0:0e0631af0305 | 3131 | //! the copy constructor |
RyoheiHagimoto | 0:0e0631af0305 | 3132 | SparseMatConstIterator_(const SparseMatConstIterator_& it); |
RyoheiHagimoto | 0:0e0631af0305 | 3133 | |
RyoheiHagimoto | 0:0e0631af0305 | 3134 | //! the assignment operator |
RyoheiHagimoto | 0:0e0631af0305 | 3135 | SparseMatConstIterator_& operator = (const SparseMatConstIterator_& it); |
RyoheiHagimoto | 0:0e0631af0305 | 3136 | //! the element access operator |
RyoheiHagimoto | 0:0e0631af0305 | 3137 | const _Tp& operator *() const; |
RyoheiHagimoto | 0:0e0631af0305 | 3138 | |
RyoheiHagimoto | 0:0e0631af0305 | 3139 | //! moves iterator to the next element |
RyoheiHagimoto | 0:0e0631af0305 | 3140 | SparseMatConstIterator_& operator ++(); |
RyoheiHagimoto | 0:0e0631af0305 | 3141 | //! moves iterator to the next element |
RyoheiHagimoto | 0:0e0631af0305 | 3142 | SparseMatConstIterator_ operator ++(int); |
RyoheiHagimoto | 0:0e0631af0305 | 3143 | }; |
RyoheiHagimoto | 0:0e0631af0305 | 3144 | |
RyoheiHagimoto | 0:0e0631af0305 | 3145 | |
RyoheiHagimoto | 0:0e0631af0305 | 3146 | |
RyoheiHagimoto | 0:0e0631af0305 | 3147 | ///////////////////////////////// SparseMatIterator_ ///////////////////////////////// |
RyoheiHagimoto | 0:0e0631af0305 | 3148 | |
RyoheiHagimoto | 0:0e0631af0305 | 3149 | /** @brief Template Read-Write Sparse Matrix Iterator Class. |
RyoheiHagimoto | 0:0e0631af0305 | 3150 | |
RyoheiHagimoto | 0:0e0631af0305 | 3151 | This is the derived from cv::SparseMatConstIterator_ class that |
RyoheiHagimoto | 0:0e0631af0305 | 3152 | introduces more convenient operator *() for accessing the current element. |
RyoheiHagimoto | 0:0e0631af0305 | 3153 | */ |
RyoheiHagimoto | 0:0e0631af0305 | 3154 | template<typename _Tp> class SparseMatIterator_ : public SparseMatConstIterator_<_Tp> |
RyoheiHagimoto | 0:0e0631af0305 | 3155 | { |
RyoheiHagimoto | 0:0e0631af0305 | 3156 | public: |
RyoheiHagimoto | 0:0e0631af0305 | 3157 | |
RyoheiHagimoto | 0:0e0631af0305 | 3158 | #ifndef OPENCV_NOSTL |
RyoheiHagimoto | 0:0e0631af0305 | 3159 | typedef std::forward_iterator_tag iterator_category; |
RyoheiHagimoto | 0:0e0631af0305 | 3160 | #endif |
RyoheiHagimoto | 0:0e0631af0305 | 3161 | |
RyoheiHagimoto | 0:0e0631af0305 | 3162 | //! the default constructor |
RyoheiHagimoto | 0:0e0631af0305 | 3163 | SparseMatIterator_(); |
RyoheiHagimoto | 0:0e0631af0305 | 3164 | //! the full constructor setting the iterator to the first sparse matrix element |
RyoheiHagimoto | 0:0e0631af0305 | 3165 | SparseMatIterator_(SparseMat_<_Tp>* _m); |
RyoheiHagimoto | 0:0e0631af0305 | 3166 | SparseMatIterator_(SparseMat* _m); |
RyoheiHagimoto | 0:0e0631af0305 | 3167 | //! the copy constructor |
RyoheiHagimoto | 0:0e0631af0305 | 3168 | SparseMatIterator_(const SparseMatIterator_& it); |
RyoheiHagimoto | 0:0e0631af0305 | 3169 | |
RyoheiHagimoto | 0:0e0631af0305 | 3170 | //! the assignment operator |
RyoheiHagimoto | 0:0e0631af0305 | 3171 | SparseMatIterator_& operator = (const SparseMatIterator_& it); |
RyoheiHagimoto | 0:0e0631af0305 | 3172 | //! returns the reference to the current element |
RyoheiHagimoto | 0:0e0631af0305 | 3173 | _Tp& operator *() const; |
RyoheiHagimoto | 0:0e0631af0305 | 3174 | |
RyoheiHagimoto | 0:0e0631af0305 | 3175 | //! moves the iterator to the next element |
RyoheiHagimoto | 0:0e0631af0305 | 3176 | SparseMatIterator_& operator ++(); |
RyoheiHagimoto | 0:0e0631af0305 | 3177 | //! moves the iterator to the next element |
RyoheiHagimoto | 0:0e0631af0305 | 3178 | SparseMatIterator_ operator ++(int); |
RyoheiHagimoto | 0:0e0631af0305 | 3179 | }; |
RyoheiHagimoto | 0:0e0631af0305 | 3180 | |
RyoheiHagimoto | 0:0e0631af0305 | 3181 | |
RyoheiHagimoto | 0:0e0631af0305 | 3182 | |
RyoheiHagimoto | 0:0e0631af0305 | 3183 | /////////////////////////////////// NAryMatIterator ////////////////////////////////// |
RyoheiHagimoto | 0:0e0631af0305 | 3184 | |
RyoheiHagimoto | 0:0e0631af0305 | 3185 | /** @brief n-ary multi-dimensional array iterator. |
RyoheiHagimoto | 0:0e0631af0305 | 3186 | |
RyoheiHagimoto | 0:0e0631af0305 | 3187 | Use the class to implement unary, binary, and, generally, n-ary element-wise operations on |
RyoheiHagimoto | 0:0e0631af0305 | 3188 | multi-dimensional arrays. Some of the arguments of an n-ary function may be continuous arrays, some |
RyoheiHagimoto | 0:0e0631af0305 | 3189 | may be not. It is possible to use conventional MatIterator 's for each array but incrementing all of |
RyoheiHagimoto | 0:0e0631af0305 | 3190 | the iterators after each small operations may be a big overhead. In this case consider using |
RyoheiHagimoto | 0:0e0631af0305 | 3191 | NAryMatIterator to iterate through several matrices simultaneously as long as they have the same |
RyoheiHagimoto | 0:0e0631af0305 | 3192 | geometry (dimensionality and all the dimension sizes are the same). On each iteration `it.planes[0]`, |
RyoheiHagimoto | 0:0e0631af0305 | 3193 | `it.planes[1]`,... will be the slices of the corresponding matrices. |
RyoheiHagimoto | 0:0e0631af0305 | 3194 | |
RyoheiHagimoto | 0:0e0631af0305 | 3195 | The example below illustrates how you can compute a normalized and threshold 3D color histogram: |
RyoheiHagimoto | 0:0e0631af0305 | 3196 | @code |
RyoheiHagimoto | 0:0e0631af0305 | 3197 | void computeNormalizedColorHist(const Mat& image, Mat& hist, int N, double minProb) |
RyoheiHagimoto | 0:0e0631af0305 | 3198 | { |
RyoheiHagimoto | 0:0e0631af0305 | 3199 | const int histSize[] = {N, N, N}; |
RyoheiHagimoto | 0:0e0631af0305 | 3200 | |
RyoheiHagimoto | 0:0e0631af0305 | 3201 | // make sure that the histogram has a proper size and type |
RyoheiHagimoto | 0:0e0631af0305 | 3202 | hist.create(3, histSize, CV_32F); |
RyoheiHagimoto | 0:0e0631af0305 | 3203 | |
RyoheiHagimoto | 0:0e0631af0305 | 3204 | // and clear it |
RyoheiHagimoto | 0:0e0631af0305 | 3205 | hist = Scalar(0); |
RyoheiHagimoto | 0:0e0631af0305 | 3206 | |
RyoheiHagimoto | 0:0e0631af0305 | 3207 | // the loop below assumes that the image |
RyoheiHagimoto | 0:0e0631af0305 | 3208 | // is a 8-bit 3-channel. check it. |
RyoheiHagimoto | 0:0e0631af0305 | 3209 | CV_Assert(image.type() == CV_8UC3); |
RyoheiHagimoto | 0:0e0631af0305 | 3210 | MatConstIterator_<Vec3b> it = image.begin<Vec3b>(), |
RyoheiHagimoto | 0:0e0631af0305 | 3211 | it_end = image.end<Vec3b>(); |
RyoheiHagimoto | 0:0e0631af0305 | 3212 | for( ; it != it_end; ++it ) |
RyoheiHagimoto | 0:0e0631af0305 | 3213 | { |
RyoheiHagimoto | 0:0e0631af0305 | 3214 | const Vec3b& pix = *it; |
RyoheiHagimoto | 0:0e0631af0305 | 3215 | hist.at<float>(pix[0]*N/256, pix[1]*N/256, pix[2]*N/256) += 1.f; |
RyoheiHagimoto | 0:0e0631af0305 | 3216 | } |
RyoheiHagimoto | 0:0e0631af0305 | 3217 | |
RyoheiHagimoto | 0:0e0631af0305 | 3218 | minProb *= image.rows*image.cols; |
RyoheiHagimoto | 0:0e0631af0305 | 3219 | |
RyoheiHagimoto | 0:0e0631af0305 | 3220 | // initialize iterator (the style is different from STL). |
RyoheiHagimoto | 0:0e0631af0305 | 3221 | // after initialization the iterator will contain |
RyoheiHagimoto | 0:0e0631af0305 | 3222 | // the number of slices or planes the iterator will go through. |
RyoheiHagimoto | 0:0e0631af0305 | 3223 | // it simultaneously increments iterators for several matrices |
RyoheiHagimoto | 0:0e0631af0305 | 3224 | // supplied as a null terminated list of pointers |
RyoheiHagimoto | 0:0e0631af0305 | 3225 | const Mat* arrays[] = {&hist, 0}; |
RyoheiHagimoto | 0:0e0631af0305 | 3226 | Mat planes[1]; |
RyoheiHagimoto | 0:0e0631af0305 | 3227 | NAryMatIterator itNAry(arrays, planes, 1); |
RyoheiHagimoto | 0:0e0631af0305 | 3228 | double s = 0; |
RyoheiHagimoto | 0:0e0631af0305 | 3229 | // iterate through the matrix. on each iteration |
RyoheiHagimoto | 0:0e0631af0305 | 3230 | // itNAry.planes[i] (of type Mat) will be set to the current plane |
RyoheiHagimoto | 0:0e0631af0305 | 3231 | // of the i-th n-dim matrix passed to the iterator constructor. |
RyoheiHagimoto | 0:0e0631af0305 | 3232 | for(int p = 0; p < itNAry.nplanes; p++, ++itNAry) |
RyoheiHagimoto | 0:0e0631af0305 | 3233 | { |
RyoheiHagimoto | 0:0e0631af0305 | 3234 | threshold(itNAry.planes[0], itNAry.planes[0], minProb, 0, THRESH_TOZERO); |
RyoheiHagimoto | 0:0e0631af0305 | 3235 | s += sum(itNAry.planes[0])[0]; |
RyoheiHagimoto | 0:0e0631af0305 | 3236 | } |
RyoheiHagimoto | 0:0e0631af0305 | 3237 | |
RyoheiHagimoto | 0:0e0631af0305 | 3238 | s = 1./s; |
RyoheiHagimoto | 0:0e0631af0305 | 3239 | itNAry = NAryMatIterator(arrays, planes, 1); |
RyoheiHagimoto | 0:0e0631af0305 | 3240 | for(int p = 0; p < itNAry.nplanes; p++, ++itNAry) |
RyoheiHagimoto | 0:0e0631af0305 | 3241 | itNAry.planes[0] *= s; |
RyoheiHagimoto | 0:0e0631af0305 | 3242 | } |
RyoheiHagimoto | 0:0e0631af0305 | 3243 | @endcode |
RyoheiHagimoto | 0:0e0631af0305 | 3244 | */ |
RyoheiHagimoto | 0:0e0631af0305 | 3245 | class CV_EXPORTS NAryMatIterator |
RyoheiHagimoto | 0:0e0631af0305 | 3246 | { |
RyoheiHagimoto | 0:0e0631af0305 | 3247 | public: |
RyoheiHagimoto | 0:0e0631af0305 | 3248 | //! the default constructor |
RyoheiHagimoto | 0:0e0631af0305 | 3249 | NAryMatIterator(); |
RyoheiHagimoto | 0:0e0631af0305 | 3250 | //! the full constructor taking arbitrary number of n-dim matrices |
RyoheiHagimoto | 0:0e0631af0305 | 3251 | NAryMatIterator(const Mat** arrays, uchar** ptrs, int narrays=-1); |
RyoheiHagimoto | 0:0e0631af0305 | 3252 | //! the full constructor taking arbitrary number of n-dim matrices |
RyoheiHagimoto | 0:0e0631af0305 | 3253 | NAryMatIterator(const Mat** arrays, Mat* planes, int narrays=-1); |
RyoheiHagimoto | 0:0e0631af0305 | 3254 | //! the separate iterator initialization method |
RyoheiHagimoto | 0:0e0631af0305 | 3255 | void init(const Mat** arrays, Mat* planes, uchar** ptrs, int narrays=-1); |
RyoheiHagimoto | 0:0e0631af0305 | 3256 | |
RyoheiHagimoto | 0:0e0631af0305 | 3257 | //! proceeds to the next plane of every iterated matrix |
RyoheiHagimoto | 0:0e0631af0305 | 3258 | NAryMatIterator& operator ++(); |
RyoheiHagimoto | 0:0e0631af0305 | 3259 | //! proceeds to the next plane of every iterated matrix (postfix increment operator) |
RyoheiHagimoto | 0:0e0631af0305 | 3260 | NAryMatIterator operator ++(int); |
RyoheiHagimoto | 0:0e0631af0305 | 3261 | |
RyoheiHagimoto | 0:0e0631af0305 | 3262 | //! the iterated arrays |
RyoheiHagimoto | 0:0e0631af0305 | 3263 | const Mat** arrays; |
RyoheiHagimoto | 0:0e0631af0305 | 3264 | //! the current planes |
RyoheiHagimoto | 0:0e0631af0305 | 3265 | Mat* planes; |
RyoheiHagimoto | 0:0e0631af0305 | 3266 | //! data pointers |
RyoheiHagimoto | 0:0e0631af0305 | 3267 | uchar** ptrs; |
RyoheiHagimoto | 0:0e0631af0305 | 3268 | //! the number of arrays |
RyoheiHagimoto | 0:0e0631af0305 | 3269 | int narrays; |
RyoheiHagimoto | 0:0e0631af0305 | 3270 | //! the number of hyper-planes that the iterator steps through |
RyoheiHagimoto | 0:0e0631af0305 | 3271 | size_t nplanes; |
RyoheiHagimoto | 0:0e0631af0305 | 3272 | //! the size of each segment (in elements) |
RyoheiHagimoto | 0:0e0631af0305 | 3273 | size_t size; |
RyoheiHagimoto | 0:0e0631af0305 | 3274 | protected: |
RyoheiHagimoto | 0:0e0631af0305 | 3275 | int iterdepth; |
RyoheiHagimoto | 0:0e0631af0305 | 3276 | size_t idx; |
RyoheiHagimoto | 0:0e0631af0305 | 3277 | }; |
RyoheiHagimoto | 0:0e0631af0305 | 3278 | |
RyoheiHagimoto | 0:0e0631af0305 | 3279 | |
RyoheiHagimoto | 0:0e0631af0305 | 3280 | |
RyoheiHagimoto | 0:0e0631af0305 | 3281 | ///////////////////////////////// Matrix Expressions ///////////////////////////////// |
RyoheiHagimoto | 0:0e0631af0305 | 3282 | |
RyoheiHagimoto | 0:0e0631af0305 | 3283 | class CV_EXPORTS MatOp |
RyoheiHagimoto | 0:0e0631af0305 | 3284 | { |
RyoheiHagimoto | 0:0e0631af0305 | 3285 | public: |
RyoheiHagimoto | 0:0e0631af0305 | 3286 | MatOp(); |
RyoheiHagimoto | 0:0e0631af0305 | 3287 | virtual ~MatOp(); |
RyoheiHagimoto | 0:0e0631af0305 | 3288 | |
RyoheiHagimoto | 0:0e0631af0305 | 3289 | virtual bool elementWise(const MatExpr& expr) const; |
RyoheiHagimoto | 0:0e0631af0305 | 3290 | virtual void assign(const MatExpr& expr, Mat& m, int type=-1) const = 0; |
RyoheiHagimoto | 0:0e0631af0305 | 3291 | virtual void roi(const MatExpr& expr, const Range& rowRange, |
RyoheiHagimoto | 0:0e0631af0305 | 3292 | const Range& colRange, MatExpr& res) const; |
RyoheiHagimoto | 0:0e0631af0305 | 3293 | virtual void diag(const MatExpr& expr, int d, MatExpr& res) const; |
RyoheiHagimoto | 0:0e0631af0305 | 3294 | virtual void augAssignAdd(const MatExpr& expr, Mat& m) const; |
RyoheiHagimoto | 0:0e0631af0305 | 3295 | virtual void augAssignSubtract(const MatExpr& expr, Mat& m) const; |
RyoheiHagimoto | 0:0e0631af0305 | 3296 | virtual void augAssignMultiply(const MatExpr& expr, Mat& m) const; |
RyoheiHagimoto | 0:0e0631af0305 | 3297 | virtual void augAssignDivide(const MatExpr& expr, Mat& m) const; |
RyoheiHagimoto | 0:0e0631af0305 | 3298 | virtual void augAssignAnd(const MatExpr& expr, Mat& m) const; |
RyoheiHagimoto | 0:0e0631af0305 | 3299 | virtual void augAssignOr(const MatExpr& expr, Mat& m) const; |
RyoheiHagimoto | 0:0e0631af0305 | 3300 | virtual void augAssignXor(const MatExpr& expr, Mat& m) const; |
RyoheiHagimoto | 0:0e0631af0305 | 3301 | |
RyoheiHagimoto | 0:0e0631af0305 | 3302 | virtual void add(const MatExpr& expr1, const MatExpr& expr2, MatExpr& res) const; |
RyoheiHagimoto | 0:0e0631af0305 | 3303 | virtual void add(const MatExpr& expr1, const Scalar& s, MatExpr& res) const; |
RyoheiHagimoto | 0:0e0631af0305 | 3304 | |
RyoheiHagimoto | 0:0e0631af0305 | 3305 | virtual void subtract(const MatExpr& expr1, const MatExpr& expr2, MatExpr& res) const; |
RyoheiHagimoto | 0:0e0631af0305 | 3306 | virtual void subtract(const Scalar& s, const MatExpr& expr, MatExpr& res) const; |
RyoheiHagimoto | 0:0e0631af0305 | 3307 | |
RyoheiHagimoto | 0:0e0631af0305 | 3308 | virtual void multiply(const MatExpr& expr1, const MatExpr& expr2, MatExpr& res, double scale=1) const; |
RyoheiHagimoto | 0:0e0631af0305 | 3309 | virtual void multiply(const MatExpr& expr1, double s, MatExpr& res) const; |
RyoheiHagimoto | 0:0e0631af0305 | 3310 | |
RyoheiHagimoto | 0:0e0631af0305 | 3311 | virtual void divide(const MatExpr& expr1, const MatExpr& expr2, MatExpr& res, double scale=1) const; |
RyoheiHagimoto | 0:0e0631af0305 | 3312 | virtual void divide(double s, const MatExpr& expr, MatExpr& res) const; |
RyoheiHagimoto | 0:0e0631af0305 | 3313 | |
RyoheiHagimoto | 0:0e0631af0305 | 3314 | virtual void abs(const MatExpr& expr, MatExpr& res) const; |
RyoheiHagimoto | 0:0e0631af0305 | 3315 | |
RyoheiHagimoto | 0:0e0631af0305 | 3316 | virtual void transpose(const MatExpr& expr, MatExpr& res) const; |
RyoheiHagimoto | 0:0e0631af0305 | 3317 | virtual void matmul(const MatExpr& expr1, const MatExpr& expr2, MatExpr& res) const; |
RyoheiHagimoto | 0:0e0631af0305 | 3318 | virtual void invert(const MatExpr& expr, int method, MatExpr& res) const; |
RyoheiHagimoto | 0:0e0631af0305 | 3319 | |
RyoheiHagimoto | 0:0e0631af0305 | 3320 | virtual Size size(const MatExpr& expr) const; |
RyoheiHagimoto | 0:0e0631af0305 | 3321 | virtual int type(const MatExpr& expr) const; |
RyoheiHagimoto | 0:0e0631af0305 | 3322 | }; |
RyoheiHagimoto | 0:0e0631af0305 | 3323 | |
RyoheiHagimoto | 0:0e0631af0305 | 3324 | /** @brief Matrix expression representation |
RyoheiHagimoto | 0:0e0631af0305 | 3325 | @anchor MatrixExpressions |
RyoheiHagimoto | 0:0e0631af0305 | 3326 | This is a list of implemented matrix operations that can be combined in arbitrary complex |
RyoheiHagimoto | 0:0e0631af0305 | 3327 | expressions (here A, B stand for matrices ( Mat ), s for a scalar ( Scalar ), alpha for a |
RyoheiHagimoto | 0:0e0631af0305 | 3328 | real-valued scalar ( double )): |
RyoheiHagimoto | 0:0e0631af0305 | 3329 | - Addition, subtraction, negation: `A+B`, `A-B`, `A+s`, `A-s`, `s+A`, `s-A`, `-A` |
RyoheiHagimoto | 0:0e0631af0305 | 3330 | - Scaling: `A*alpha` |
RyoheiHagimoto | 0:0e0631af0305 | 3331 | - Per-element multiplication and division: `A.mul(B)`, `A/B`, `alpha/A` |
RyoheiHagimoto | 0:0e0631af0305 | 3332 | - Matrix multiplication: `A*B` |
RyoheiHagimoto | 0:0e0631af0305 | 3333 | - Transposition: `A.t()` (means A<sup>T</sup>) |
RyoheiHagimoto | 0:0e0631af0305 | 3334 | - Matrix inversion and pseudo-inversion, solving linear systems and least-squares problems: |
RyoheiHagimoto | 0:0e0631af0305 | 3335 | `A.inv([method]) (~ A<sup>-1</sup>)`, `A.inv([method])*B (~ X: AX=B)` |
RyoheiHagimoto | 0:0e0631af0305 | 3336 | - Comparison: `A cmpop B`, `A cmpop alpha`, `alpha cmpop A`, where *cmpop* is one of |
RyoheiHagimoto | 0:0e0631af0305 | 3337 | `>`, `>=`, `==`, `!=`, `<=`, `<`. The result of comparison is an 8-bit single channel mask whose |
RyoheiHagimoto | 0:0e0631af0305 | 3338 | elements are set to 255 (if the particular element or pair of elements satisfy the condition) or |
RyoheiHagimoto | 0:0e0631af0305 | 3339 | 0. |
RyoheiHagimoto | 0:0e0631af0305 | 3340 | - Bitwise logical operations: `A logicop B`, `A logicop s`, `s logicop A`, `~A`, where *logicop* is one of |
RyoheiHagimoto | 0:0e0631af0305 | 3341 | `&`, `|`, `^`. |
RyoheiHagimoto | 0:0e0631af0305 | 3342 | - Element-wise minimum and maximum: `min(A, B)`, `min(A, alpha)`, `max(A, B)`, `max(A, alpha)` |
RyoheiHagimoto | 0:0e0631af0305 | 3343 | - Element-wise absolute value: `abs(A)` |
RyoheiHagimoto | 0:0e0631af0305 | 3344 | - Cross-product, dot-product: `A.cross(B)`, `A.dot(B)` |
RyoheiHagimoto | 0:0e0631af0305 | 3345 | - Any function of matrix or matrices and scalars that returns a matrix or a scalar, such as norm, |
RyoheiHagimoto | 0:0e0631af0305 | 3346 | mean, sum, countNonZero, trace, determinant, repeat, and others. |
RyoheiHagimoto | 0:0e0631af0305 | 3347 | - Matrix initializers ( Mat::eye(), Mat::zeros(), Mat::ones() ), matrix comma-separated |
RyoheiHagimoto | 0:0e0631af0305 | 3348 | initializers, matrix constructors and operators that extract sub-matrices (see Mat description). |
RyoheiHagimoto | 0:0e0631af0305 | 3349 | - Mat_<destination_type>() constructors to cast the result to the proper type. |
RyoheiHagimoto | 0:0e0631af0305 | 3350 | @note Comma-separated initializers and probably some other operations may require additional |
RyoheiHagimoto | 0:0e0631af0305 | 3351 | explicit Mat() or Mat_<T>() constructor calls to resolve a possible ambiguity. |
RyoheiHagimoto | 0:0e0631af0305 | 3352 | |
RyoheiHagimoto | 0:0e0631af0305 | 3353 | Here are examples of matrix expressions: |
RyoheiHagimoto | 0:0e0631af0305 | 3354 | @code |
RyoheiHagimoto | 0:0e0631af0305 | 3355 | // compute pseudo-inverse of A, equivalent to A.inv(DECOMP_SVD) |
RyoheiHagimoto | 0:0e0631af0305 | 3356 | SVD svd(A); |
RyoheiHagimoto | 0:0e0631af0305 | 3357 | Mat pinvA = svd.vt.t()*Mat::diag(1./svd.w)*svd.u.t(); |
RyoheiHagimoto | 0:0e0631af0305 | 3358 | |
RyoheiHagimoto | 0:0e0631af0305 | 3359 | // compute the new vector of parameters in the Levenberg-Marquardt algorithm |
RyoheiHagimoto | 0:0e0631af0305 | 3360 | x -= (A.t()*A + lambda*Mat::eye(A.cols,A.cols,A.type())).inv(DECOMP_CHOLESKY)*(A.t()*err); |
RyoheiHagimoto | 0:0e0631af0305 | 3361 | |
RyoheiHagimoto | 0:0e0631af0305 | 3362 | // sharpen image using "unsharp mask" algorithm |
RyoheiHagimoto | 0:0e0631af0305 | 3363 | Mat blurred; double sigma = 1, threshold = 5, amount = 1; |
RyoheiHagimoto | 0:0e0631af0305 | 3364 | GaussianBlur(img, blurred, Size(), sigma, sigma); |
RyoheiHagimoto | 0:0e0631af0305 | 3365 | Mat lowContrastMask = abs(img - blurred) < threshold; |
RyoheiHagimoto | 0:0e0631af0305 | 3366 | Mat sharpened = img*(1+amount) + blurred*(-amount); |
RyoheiHagimoto | 0:0e0631af0305 | 3367 | img.copyTo(sharpened, lowContrastMask); |
RyoheiHagimoto | 0:0e0631af0305 | 3368 | @endcode |
RyoheiHagimoto | 0:0e0631af0305 | 3369 | */ |
RyoheiHagimoto | 0:0e0631af0305 | 3370 | class CV_EXPORTS MatExpr |
RyoheiHagimoto | 0:0e0631af0305 | 3371 | { |
RyoheiHagimoto | 0:0e0631af0305 | 3372 | public: |
RyoheiHagimoto | 0:0e0631af0305 | 3373 | MatExpr(); |
RyoheiHagimoto | 0:0e0631af0305 | 3374 | explicit MatExpr(const Mat& m); |
RyoheiHagimoto | 0:0e0631af0305 | 3375 | |
RyoheiHagimoto | 0:0e0631af0305 | 3376 | MatExpr(const MatOp* _op, int _flags, const Mat& _a = Mat(), const Mat& _b = Mat(), |
RyoheiHagimoto | 0:0e0631af0305 | 3377 | const Mat& _c = Mat(), double _alpha = 1, double _beta = 1, const Scalar& _s = Scalar()); |
RyoheiHagimoto | 0:0e0631af0305 | 3378 | |
RyoheiHagimoto | 0:0e0631af0305 | 3379 | operator Mat() const; |
RyoheiHagimoto | 0:0e0631af0305 | 3380 | template<typename _Tp> operator Mat_<_Tp>() const; |
RyoheiHagimoto | 0:0e0631af0305 | 3381 | |
RyoheiHagimoto | 0:0e0631af0305 | 3382 | Size size() const; |
RyoheiHagimoto | 0:0e0631af0305 | 3383 | int type() const; |
RyoheiHagimoto | 0:0e0631af0305 | 3384 | |
RyoheiHagimoto | 0:0e0631af0305 | 3385 | MatExpr row(int y) const; |
RyoheiHagimoto | 0:0e0631af0305 | 3386 | MatExpr col(int x) const; |
RyoheiHagimoto | 0:0e0631af0305 | 3387 | MatExpr diag(int d = 0) const; |
RyoheiHagimoto | 0:0e0631af0305 | 3388 | MatExpr operator()( const Range& rowRange, const Range& colRange ) const; |
RyoheiHagimoto | 0:0e0631af0305 | 3389 | MatExpr operator()( const Rect& roi ) const; |
RyoheiHagimoto | 0:0e0631af0305 | 3390 | |
RyoheiHagimoto | 0:0e0631af0305 | 3391 | MatExpr t() const; |
RyoheiHagimoto | 0:0e0631af0305 | 3392 | MatExpr inv(int method = DECOMP_LU) const; |
RyoheiHagimoto | 0:0e0631af0305 | 3393 | MatExpr mul(const MatExpr& e, double scale=1) const; |
RyoheiHagimoto | 0:0e0631af0305 | 3394 | MatExpr mul(const Mat& m, double scale=1) const; |
RyoheiHagimoto | 0:0e0631af0305 | 3395 | |
RyoheiHagimoto | 0:0e0631af0305 | 3396 | Mat cross(const Mat& m) const; |
RyoheiHagimoto | 0:0e0631af0305 | 3397 | double dot(const Mat& m) const; |
RyoheiHagimoto | 0:0e0631af0305 | 3398 | |
RyoheiHagimoto | 0:0e0631af0305 | 3399 | const MatOp* op; |
RyoheiHagimoto | 0:0e0631af0305 | 3400 | int flags; |
RyoheiHagimoto | 0:0e0631af0305 | 3401 | |
RyoheiHagimoto | 0:0e0631af0305 | 3402 | Mat a, b, c; |
RyoheiHagimoto | 0:0e0631af0305 | 3403 | double alpha, beta; |
RyoheiHagimoto | 0:0e0631af0305 | 3404 | Scalar s; |
RyoheiHagimoto | 0:0e0631af0305 | 3405 | }; |
RyoheiHagimoto | 0:0e0631af0305 | 3406 | |
RyoheiHagimoto | 0:0e0631af0305 | 3407 | //! @} core_basic |
RyoheiHagimoto | 0:0e0631af0305 | 3408 | |
RyoheiHagimoto | 0:0e0631af0305 | 3409 | //! @relates cv::MatExpr |
RyoheiHagimoto | 0:0e0631af0305 | 3410 | //! @{ |
RyoheiHagimoto | 0:0e0631af0305 | 3411 | CV_EXPORTS MatExpr operator + (const Mat& a, const Mat& b); |
RyoheiHagimoto | 0:0e0631af0305 | 3412 | CV_EXPORTS MatExpr operator + (const Mat& a, const Scalar& s); |
RyoheiHagimoto | 0:0e0631af0305 | 3413 | CV_EXPORTS MatExpr operator + (const Scalar& s, const Mat& a); |
RyoheiHagimoto | 0:0e0631af0305 | 3414 | CV_EXPORTS MatExpr operator + (const MatExpr& e, const Mat& m); |
RyoheiHagimoto | 0:0e0631af0305 | 3415 | CV_EXPORTS MatExpr operator + (const Mat& m, const MatExpr& e); |
RyoheiHagimoto | 0:0e0631af0305 | 3416 | CV_EXPORTS MatExpr operator + (const MatExpr& e, const Scalar& s); |
RyoheiHagimoto | 0:0e0631af0305 | 3417 | CV_EXPORTS MatExpr operator + (const Scalar& s, const MatExpr& e); |
RyoheiHagimoto | 0:0e0631af0305 | 3418 | CV_EXPORTS MatExpr operator + (const MatExpr& e1, const MatExpr& e2); |
RyoheiHagimoto | 0:0e0631af0305 | 3419 | |
RyoheiHagimoto | 0:0e0631af0305 | 3420 | CV_EXPORTS MatExpr operator - (const Mat& a, const Mat& b); |
RyoheiHagimoto | 0:0e0631af0305 | 3421 | CV_EXPORTS MatExpr operator - (const Mat& a, const Scalar& s); |
RyoheiHagimoto | 0:0e0631af0305 | 3422 | CV_EXPORTS MatExpr operator - (const Scalar& s, const Mat& a); |
RyoheiHagimoto | 0:0e0631af0305 | 3423 | CV_EXPORTS MatExpr operator - (const MatExpr& e, const Mat& m); |
RyoheiHagimoto | 0:0e0631af0305 | 3424 | CV_EXPORTS MatExpr operator - (const Mat& m, const MatExpr& e); |
RyoheiHagimoto | 0:0e0631af0305 | 3425 | CV_EXPORTS MatExpr operator - (const MatExpr& e, const Scalar& s); |
RyoheiHagimoto | 0:0e0631af0305 | 3426 | CV_EXPORTS MatExpr operator - (const Scalar& s, const MatExpr& e); |
RyoheiHagimoto | 0:0e0631af0305 | 3427 | CV_EXPORTS MatExpr operator - (const MatExpr& e1, const MatExpr& e2); |
RyoheiHagimoto | 0:0e0631af0305 | 3428 | |
RyoheiHagimoto | 0:0e0631af0305 | 3429 | CV_EXPORTS MatExpr operator - (const Mat& m); |
RyoheiHagimoto | 0:0e0631af0305 | 3430 | CV_EXPORTS MatExpr operator - (const MatExpr& e); |
RyoheiHagimoto | 0:0e0631af0305 | 3431 | |
RyoheiHagimoto | 0:0e0631af0305 | 3432 | CV_EXPORTS MatExpr operator * (const Mat& a, const Mat& b); |
RyoheiHagimoto | 0:0e0631af0305 | 3433 | CV_EXPORTS MatExpr operator * (const Mat& a, double s); |
RyoheiHagimoto | 0:0e0631af0305 | 3434 | CV_EXPORTS MatExpr operator * (double s, const Mat& a); |
RyoheiHagimoto | 0:0e0631af0305 | 3435 | CV_EXPORTS MatExpr operator * (const MatExpr& e, const Mat& m); |
RyoheiHagimoto | 0:0e0631af0305 | 3436 | CV_EXPORTS MatExpr operator * (const Mat& m, const MatExpr& e); |
RyoheiHagimoto | 0:0e0631af0305 | 3437 | CV_EXPORTS MatExpr operator * (const MatExpr& e, double s); |
RyoheiHagimoto | 0:0e0631af0305 | 3438 | CV_EXPORTS MatExpr operator * (double s, const MatExpr& e); |
RyoheiHagimoto | 0:0e0631af0305 | 3439 | CV_EXPORTS MatExpr operator * (const MatExpr& e1, const MatExpr& e2); |
RyoheiHagimoto | 0:0e0631af0305 | 3440 | |
RyoheiHagimoto | 0:0e0631af0305 | 3441 | CV_EXPORTS MatExpr operator / (const Mat& a, const Mat& b); |
RyoheiHagimoto | 0:0e0631af0305 | 3442 | CV_EXPORTS MatExpr operator / (const Mat& a, double s); |
RyoheiHagimoto | 0:0e0631af0305 | 3443 | CV_EXPORTS MatExpr operator / (double s, const Mat& a); |
RyoheiHagimoto | 0:0e0631af0305 | 3444 | CV_EXPORTS MatExpr operator / (const MatExpr& e, const Mat& m); |
RyoheiHagimoto | 0:0e0631af0305 | 3445 | CV_EXPORTS MatExpr operator / (const Mat& m, const MatExpr& e); |
RyoheiHagimoto | 0:0e0631af0305 | 3446 | CV_EXPORTS MatExpr operator / (const MatExpr& e, double s); |
RyoheiHagimoto | 0:0e0631af0305 | 3447 | CV_EXPORTS MatExpr operator / (double s, const MatExpr& e); |
RyoheiHagimoto | 0:0e0631af0305 | 3448 | CV_EXPORTS MatExpr operator / (const MatExpr& e1, const MatExpr& e2); |
RyoheiHagimoto | 0:0e0631af0305 | 3449 | |
RyoheiHagimoto | 0:0e0631af0305 | 3450 | CV_EXPORTS MatExpr operator < (const Mat& a, const Mat& b); |
RyoheiHagimoto | 0:0e0631af0305 | 3451 | CV_EXPORTS MatExpr operator < (const Mat& a, double s); |
RyoheiHagimoto | 0:0e0631af0305 | 3452 | CV_EXPORTS MatExpr operator < (double s, const Mat& a); |
RyoheiHagimoto | 0:0e0631af0305 | 3453 | |
RyoheiHagimoto | 0:0e0631af0305 | 3454 | CV_EXPORTS MatExpr operator <= (const Mat& a, const Mat& b); |
RyoheiHagimoto | 0:0e0631af0305 | 3455 | CV_EXPORTS MatExpr operator <= (const Mat& a, double s); |
RyoheiHagimoto | 0:0e0631af0305 | 3456 | CV_EXPORTS MatExpr operator <= (double s, const Mat& a); |
RyoheiHagimoto | 0:0e0631af0305 | 3457 | |
RyoheiHagimoto | 0:0e0631af0305 | 3458 | CV_EXPORTS MatExpr operator == (const Mat& a, const Mat& b); |
RyoheiHagimoto | 0:0e0631af0305 | 3459 | CV_EXPORTS MatExpr operator == (const Mat& a, double s); |
RyoheiHagimoto | 0:0e0631af0305 | 3460 | CV_EXPORTS MatExpr operator == (double s, const Mat& a); |
RyoheiHagimoto | 0:0e0631af0305 | 3461 | |
RyoheiHagimoto | 0:0e0631af0305 | 3462 | CV_EXPORTS MatExpr operator != (const Mat& a, const Mat& b); |
RyoheiHagimoto | 0:0e0631af0305 | 3463 | CV_EXPORTS MatExpr operator != (const Mat& a, double s); |
RyoheiHagimoto | 0:0e0631af0305 | 3464 | CV_EXPORTS MatExpr operator != (double s, const Mat& a); |
RyoheiHagimoto | 0:0e0631af0305 | 3465 | |
RyoheiHagimoto | 0:0e0631af0305 | 3466 | CV_EXPORTS MatExpr operator >= (const Mat& a, const Mat& b); |
RyoheiHagimoto | 0:0e0631af0305 | 3467 | CV_EXPORTS MatExpr operator >= (const Mat& a, double s); |
RyoheiHagimoto | 0:0e0631af0305 | 3468 | CV_EXPORTS MatExpr operator >= (double s, const Mat& a); |
RyoheiHagimoto | 0:0e0631af0305 | 3469 | |
RyoheiHagimoto | 0:0e0631af0305 | 3470 | CV_EXPORTS MatExpr operator > (const Mat& a, const Mat& b); |
RyoheiHagimoto | 0:0e0631af0305 | 3471 | CV_EXPORTS MatExpr operator > (const Mat& a, double s); |
RyoheiHagimoto | 0:0e0631af0305 | 3472 | CV_EXPORTS MatExpr operator > (double s, const Mat& a); |
RyoheiHagimoto | 0:0e0631af0305 | 3473 | |
RyoheiHagimoto | 0:0e0631af0305 | 3474 | CV_EXPORTS MatExpr operator & (const Mat& a, const Mat& b); |
RyoheiHagimoto | 0:0e0631af0305 | 3475 | CV_EXPORTS MatExpr operator & (const Mat& a, const Scalar& s); |
RyoheiHagimoto | 0:0e0631af0305 | 3476 | CV_EXPORTS MatExpr operator & (const Scalar& s, const Mat& a); |
RyoheiHagimoto | 0:0e0631af0305 | 3477 | |
RyoheiHagimoto | 0:0e0631af0305 | 3478 | CV_EXPORTS MatExpr operator | (const Mat& a, const Mat& b); |
RyoheiHagimoto | 0:0e0631af0305 | 3479 | CV_EXPORTS MatExpr operator | (const Mat& a, const Scalar& s); |
RyoheiHagimoto | 0:0e0631af0305 | 3480 | CV_EXPORTS MatExpr operator | (const Scalar& s, const Mat& a); |
RyoheiHagimoto | 0:0e0631af0305 | 3481 | |
RyoheiHagimoto | 0:0e0631af0305 | 3482 | CV_EXPORTS MatExpr operator ^ (const Mat& a, const Mat& b); |
RyoheiHagimoto | 0:0e0631af0305 | 3483 | CV_EXPORTS MatExpr operator ^ (const Mat& a, const Scalar& s); |
RyoheiHagimoto | 0:0e0631af0305 | 3484 | CV_EXPORTS MatExpr operator ^ (const Scalar& s, const Mat& a); |
RyoheiHagimoto | 0:0e0631af0305 | 3485 | |
RyoheiHagimoto | 0:0e0631af0305 | 3486 | CV_EXPORTS MatExpr operator ~(const Mat& m); |
RyoheiHagimoto | 0:0e0631af0305 | 3487 | |
RyoheiHagimoto | 0:0e0631af0305 | 3488 | CV_EXPORTS MatExpr min(const Mat& a, const Mat& b); |
RyoheiHagimoto | 0:0e0631af0305 | 3489 | CV_EXPORTS MatExpr min(const Mat& a, double s); |
RyoheiHagimoto | 0:0e0631af0305 | 3490 | CV_EXPORTS MatExpr min(double s, const Mat& a); |
RyoheiHagimoto | 0:0e0631af0305 | 3491 | |
RyoheiHagimoto | 0:0e0631af0305 | 3492 | CV_EXPORTS MatExpr max(const Mat& a, const Mat& b); |
RyoheiHagimoto | 0:0e0631af0305 | 3493 | CV_EXPORTS MatExpr max(const Mat& a, double s); |
RyoheiHagimoto | 0:0e0631af0305 | 3494 | CV_EXPORTS MatExpr max(double s, const Mat& a); |
RyoheiHagimoto | 0:0e0631af0305 | 3495 | |
RyoheiHagimoto | 0:0e0631af0305 | 3496 | /** @brief Calculates an absolute value of each matrix element. |
RyoheiHagimoto | 0:0e0631af0305 | 3497 | |
RyoheiHagimoto | 0:0e0631af0305 | 3498 | abs is a meta-function that is expanded to one of absdiff or convertScaleAbs forms: |
RyoheiHagimoto | 0:0e0631af0305 | 3499 | - C = abs(A-B) is equivalent to `absdiff(A, B, C)` |
RyoheiHagimoto | 0:0e0631af0305 | 3500 | - C = abs(A) is equivalent to `absdiff(A, Scalar::all(0), C)` |
RyoheiHagimoto | 0:0e0631af0305 | 3501 | - C = `Mat_<Vec<uchar,n> >(abs(A*alpha + beta))` is equivalent to `convertScaleAbs(A, C, alpha, |
RyoheiHagimoto | 0:0e0631af0305 | 3502 | beta)` |
RyoheiHagimoto | 0:0e0631af0305 | 3503 | |
RyoheiHagimoto | 0:0e0631af0305 | 3504 | The output matrix has the same size and the same type as the input one except for the last case, |
RyoheiHagimoto | 0:0e0631af0305 | 3505 | where C is depth=CV_8U . |
RyoheiHagimoto | 0:0e0631af0305 | 3506 | @param m matrix. |
RyoheiHagimoto | 0:0e0631af0305 | 3507 | @sa @ref MatrixExpressions, absdiff, convertScaleAbs |
RyoheiHagimoto | 0:0e0631af0305 | 3508 | */ |
RyoheiHagimoto | 0:0e0631af0305 | 3509 | CV_EXPORTS MatExpr abs(const Mat& m); |
RyoheiHagimoto | 0:0e0631af0305 | 3510 | /** @overload |
RyoheiHagimoto | 0:0e0631af0305 | 3511 | @param e matrix expression. |
RyoheiHagimoto | 0:0e0631af0305 | 3512 | */ |
RyoheiHagimoto | 0:0e0631af0305 | 3513 | CV_EXPORTS MatExpr abs(const MatExpr& e); |
RyoheiHagimoto | 0:0e0631af0305 | 3514 | //! @} relates cv::MatExpr |
RyoheiHagimoto | 0:0e0631af0305 | 3515 | |
RyoheiHagimoto | 0:0e0631af0305 | 3516 | } // cv |
RyoheiHagimoto | 0:0e0631af0305 | 3517 | |
RyoheiHagimoto | 0:0e0631af0305 | 3518 | #include "opencv2/core/mat.inl.hpp" |
RyoheiHagimoto | 0:0e0631af0305 | 3519 | |
RyoheiHagimoto | 0:0e0631af0305 | 3520 | #endif // OPENCV_CORE_MAT_HPP |