openCV library for Renesas RZ/A
Dependents: RZ_A2M_Mbed_samples
include/opencv2/core/ippasync.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-2015, 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 | // Copyright (C) 2015, Itseez Inc., all rights reserved. |
RyoheiHagimoto | 0:0e0631af0305 | 17 | // Third party copyrights are property of their respective owners. |
RyoheiHagimoto | 0:0e0631af0305 | 18 | // |
RyoheiHagimoto | 0:0e0631af0305 | 19 | // Redistribution and use in source and binary forms, with or without modification, |
RyoheiHagimoto | 0:0e0631af0305 | 20 | // are permitted provided that the following conditions are met: |
RyoheiHagimoto | 0:0e0631af0305 | 21 | // |
RyoheiHagimoto | 0:0e0631af0305 | 22 | // * Redistribution's of source code must retain the above copyright notice, |
RyoheiHagimoto | 0:0e0631af0305 | 23 | // this list of conditions and the following disclaimer. |
RyoheiHagimoto | 0:0e0631af0305 | 24 | // |
RyoheiHagimoto | 0:0e0631af0305 | 25 | // * Redistribution's in binary form must reproduce the above copyright notice, |
RyoheiHagimoto | 0:0e0631af0305 | 26 | // this list of conditions and the following disclaimer in the documentation |
RyoheiHagimoto | 0:0e0631af0305 | 27 | // and/or other materials provided with the distribution. |
RyoheiHagimoto | 0:0e0631af0305 | 28 | // |
RyoheiHagimoto | 0:0e0631af0305 | 29 | // * The name of the copyright holders may not be used to endorse or promote products |
RyoheiHagimoto | 0:0e0631af0305 | 30 | // derived from this software without specific prior written permission. |
RyoheiHagimoto | 0:0e0631af0305 | 31 | // |
RyoheiHagimoto | 0:0e0631af0305 | 32 | // This software is provided by the copyright holders and contributors "as is" and |
RyoheiHagimoto | 0:0e0631af0305 | 33 | // any express or implied warranties, including, but not limited to, the implied |
RyoheiHagimoto | 0:0e0631af0305 | 34 | // warranties of merchantability and fitness for a particular purpose are disclaimed. |
RyoheiHagimoto | 0:0e0631af0305 | 35 | // In no event shall the Intel Corporation or contributors be liable for any direct, |
RyoheiHagimoto | 0:0e0631af0305 | 36 | // indirect, incidental, special, exemplary, or consequential damages |
RyoheiHagimoto | 0:0e0631af0305 | 37 | // (including, but not limited to, procurement of substitute goods or services; |
RyoheiHagimoto | 0:0e0631af0305 | 38 | // loss of use, data, or profits; or business interruption) however caused |
RyoheiHagimoto | 0:0e0631af0305 | 39 | // and on any theory of liability, whether in contract, strict liability, |
RyoheiHagimoto | 0:0e0631af0305 | 40 | // or tort (including negligence or otherwise) arising in any way out of |
RyoheiHagimoto | 0:0e0631af0305 | 41 | // the use of this software, even if advised of the possibility of such damage. |
RyoheiHagimoto | 0:0e0631af0305 | 42 | // |
RyoheiHagimoto | 0:0e0631af0305 | 43 | //M*/ |
RyoheiHagimoto | 0:0e0631af0305 | 44 | |
RyoheiHagimoto | 0:0e0631af0305 | 45 | #ifndef OPENCV_CORE_IPPASYNC_HPP |
RyoheiHagimoto | 0:0e0631af0305 | 46 | #define OPENCV_CORE_IPPASYNC_HPP |
RyoheiHagimoto | 0:0e0631af0305 | 47 | |
RyoheiHagimoto | 0:0e0631af0305 | 48 | #ifdef HAVE_IPP_A |
RyoheiHagimoto | 0:0e0631af0305 | 49 | |
RyoheiHagimoto | 0:0e0631af0305 | 50 | #include "opencv2/core.hpp" |
RyoheiHagimoto | 0:0e0631af0305 | 51 | #include <ipp_async_op.h> |
RyoheiHagimoto | 0:0e0631af0305 | 52 | #include <ipp_async_accel.h> |
RyoheiHagimoto | 0:0e0631af0305 | 53 | |
RyoheiHagimoto | 0:0e0631af0305 | 54 | namespace cv |
RyoheiHagimoto | 0:0e0631af0305 | 55 | { |
RyoheiHagimoto | 0:0e0631af0305 | 56 | |
RyoheiHagimoto | 0:0e0631af0305 | 57 | namespace hpp |
RyoheiHagimoto | 0:0e0631af0305 | 58 | { |
RyoheiHagimoto | 0:0e0631af0305 | 59 | |
RyoheiHagimoto | 0:0e0631af0305 | 60 | /** @addtogroup core_ipp |
RyoheiHagimoto | 0:0e0631af0305 | 61 | This section describes conversion between OpenCV and [Intel® IPP Asynchronous |
RyoheiHagimoto | 0:0e0631af0305 | 62 | C/C++](http://software.intel.com/en-us/intel-ipp-preview) library. [Getting Started |
RyoheiHagimoto | 0:0e0631af0305 | 63 | Guide](http://registrationcenter.intel.com/irc_nas/3727/ipp_async_get_started.htm) help you to |
RyoheiHagimoto | 0:0e0631af0305 | 64 | install the library, configure header and library build paths. |
RyoheiHagimoto | 0:0e0631af0305 | 65 | */ |
RyoheiHagimoto | 0:0e0631af0305 | 66 | //! @{ |
RyoheiHagimoto | 0:0e0631af0305 | 67 | |
RyoheiHagimoto | 0:0e0631af0305 | 68 | //! convert OpenCV data type to hppDataType |
RyoheiHagimoto | 0:0e0631af0305 | 69 | inline int toHppType(const int cvType) |
RyoheiHagimoto | 0:0e0631af0305 | 70 | { |
RyoheiHagimoto | 0:0e0631af0305 | 71 | int depth = CV_MAT_DEPTH(cvType); |
RyoheiHagimoto | 0:0e0631af0305 | 72 | int hppType = depth == CV_8U ? HPP_DATA_TYPE_8U : |
RyoheiHagimoto | 0:0e0631af0305 | 73 | depth == CV_16U ? HPP_DATA_TYPE_16U : |
RyoheiHagimoto | 0:0e0631af0305 | 74 | depth == CV_16S ? HPP_DATA_TYPE_16S : |
RyoheiHagimoto | 0:0e0631af0305 | 75 | depth == CV_32S ? HPP_DATA_TYPE_32S : |
RyoheiHagimoto | 0:0e0631af0305 | 76 | depth == CV_32F ? HPP_DATA_TYPE_32F : |
RyoheiHagimoto | 0:0e0631af0305 | 77 | depth == CV_64F ? HPP_DATA_TYPE_64F : -1; |
RyoheiHagimoto | 0:0e0631af0305 | 78 | CV_Assert( hppType >= 0 ); |
RyoheiHagimoto | 0:0e0631af0305 | 79 | return hppType; |
RyoheiHagimoto | 0:0e0631af0305 | 80 | } |
RyoheiHagimoto | 0:0e0631af0305 | 81 | |
RyoheiHagimoto | 0:0e0631af0305 | 82 | //! convert hppDataType to OpenCV data type |
RyoheiHagimoto | 0:0e0631af0305 | 83 | inline int toCvType(const int hppType) |
RyoheiHagimoto | 0:0e0631af0305 | 84 | { |
RyoheiHagimoto | 0:0e0631af0305 | 85 | int cvType = hppType == HPP_DATA_TYPE_8U ? CV_8U : |
RyoheiHagimoto | 0:0e0631af0305 | 86 | hppType == HPP_DATA_TYPE_16U ? CV_16U : |
RyoheiHagimoto | 0:0e0631af0305 | 87 | hppType == HPP_DATA_TYPE_16S ? CV_16S : |
RyoheiHagimoto | 0:0e0631af0305 | 88 | hppType == HPP_DATA_TYPE_32S ? CV_32S : |
RyoheiHagimoto | 0:0e0631af0305 | 89 | hppType == HPP_DATA_TYPE_32F ? CV_32F : |
RyoheiHagimoto | 0:0e0631af0305 | 90 | hppType == HPP_DATA_TYPE_64F ? CV_64F : -1; |
RyoheiHagimoto | 0:0e0631af0305 | 91 | CV_Assert( cvType >= 0 ); |
RyoheiHagimoto | 0:0e0631af0305 | 92 | return cvType; |
RyoheiHagimoto | 0:0e0631af0305 | 93 | } |
RyoheiHagimoto | 0:0e0631af0305 | 94 | |
RyoheiHagimoto | 0:0e0631af0305 | 95 | /** @brief Convert hppiMatrix to Mat. |
RyoheiHagimoto | 0:0e0631af0305 | 96 | |
RyoheiHagimoto | 0:0e0631af0305 | 97 | This function allocates and initializes new matrix (if needed) that has the same size and type as |
RyoheiHagimoto | 0:0e0631af0305 | 98 | input matrix. Supports CV_8U, CV_16U, CV_16S, CV_32S, CV_32F, CV_64F. |
RyoheiHagimoto | 0:0e0631af0305 | 99 | @param src input hppiMatrix. |
RyoheiHagimoto | 0:0e0631af0305 | 100 | @param dst output matrix. |
RyoheiHagimoto | 0:0e0631af0305 | 101 | @param accel accelerator instance (see hpp::getHpp for the list of acceleration framework types). |
RyoheiHagimoto | 0:0e0631af0305 | 102 | @param cn number of channels. |
RyoheiHagimoto | 0:0e0631af0305 | 103 | */ |
RyoheiHagimoto | 0:0e0631af0305 | 104 | inline void copyHppToMat(hppiMatrix* src, Mat& dst, hppAccel accel, int cn) |
RyoheiHagimoto | 0:0e0631af0305 | 105 | { |
RyoheiHagimoto | 0:0e0631af0305 | 106 | hppDataType type; |
RyoheiHagimoto | 0:0e0631af0305 | 107 | hpp32u width, height; |
RyoheiHagimoto | 0:0e0631af0305 | 108 | hppStatus sts; |
RyoheiHagimoto | 0:0e0631af0305 | 109 | |
RyoheiHagimoto | 0:0e0631af0305 | 110 | if (src == NULL) |
RyoheiHagimoto | 0:0e0631af0305 | 111 | return dst.release(); |
RyoheiHagimoto | 0:0e0631af0305 | 112 | |
RyoheiHagimoto | 0:0e0631af0305 | 113 | sts = hppiInquireMatrix(src, &type, &width, &height); |
RyoheiHagimoto | 0:0e0631af0305 | 114 | |
RyoheiHagimoto | 0:0e0631af0305 | 115 | CV_Assert( sts == HPP_STATUS_NO_ERROR); |
RyoheiHagimoto | 0:0e0631af0305 | 116 | |
RyoheiHagimoto | 0:0e0631af0305 | 117 | int matType = CV_MAKETYPE(toCvType(type), cn); |
RyoheiHagimoto | 0:0e0631af0305 | 118 | |
RyoheiHagimoto | 0:0e0631af0305 | 119 | CV_Assert(width%cn == 0); |
RyoheiHagimoto | 0:0e0631af0305 | 120 | |
RyoheiHagimoto | 0:0e0631af0305 | 121 | width /= cn; |
RyoheiHagimoto | 0:0e0631af0305 | 122 | |
RyoheiHagimoto | 0:0e0631af0305 | 123 | dst.create((int)height, (int)width, (int)matType); |
RyoheiHagimoto | 0:0e0631af0305 | 124 | |
RyoheiHagimoto | 0:0e0631af0305 | 125 | size_t newSize = (size_t)(height*(hpp32u)(dst.step)); |
RyoheiHagimoto | 0:0e0631af0305 | 126 | |
RyoheiHagimoto | 0:0e0631af0305 | 127 | sts = hppiGetMatrixData(accel,src,(hpp32u)(dst.step),dst.data,&newSize); |
RyoheiHagimoto | 0:0e0631af0305 | 128 | |
RyoheiHagimoto | 0:0e0631af0305 | 129 | CV_Assert( sts == HPP_STATUS_NO_ERROR); |
RyoheiHagimoto | 0:0e0631af0305 | 130 | } |
RyoheiHagimoto | 0:0e0631af0305 | 131 | |
RyoheiHagimoto | 0:0e0631af0305 | 132 | /** @brief Create Mat from hppiMatrix. |
RyoheiHagimoto | 0:0e0631af0305 | 133 | |
RyoheiHagimoto | 0:0e0631af0305 | 134 | This function allocates and initializes the Mat that has the same size and type as input matrix. |
RyoheiHagimoto | 0:0e0631af0305 | 135 | Supports CV_8U, CV_16U, CV_16S, CV_32S, CV_32F, CV_64F. |
RyoheiHagimoto | 0:0e0631af0305 | 136 | @param src input hppiMatrix. |
RyoheiHagimoto | 0:0e0631af0305 | 137 | @param accel accelerator instance (see hpp::getHpp for the list of acceleration framework types). |
RyoheiHagimoto | 0:0e0631af0305 | 138 | @param cn number of channels. |
RyoheiHagimoto | 0:0e0631af0305 | 139 | @sa howToUseIPPAconversion, hpp::copyHppToMat, hpp::getHpp. |
RyoheiHagimoto | 0:0e0631af0305 | 140 | */ |
RyoheiHagimoto | 0:0e0631af0305 | 141 | inline Mat getMat(hppiMatrix* src, hppAccel accel, int cn) |
RyoheiHagimoto | 0:0e0631af0305 | 142 | { |
RyoheiHagimoto | 0:0e0631af0305 | 143 | Mat dst; |
RyoheiHagimoto | 0:0e0631af0305 | 144 | copyHppToMat(src, dst, accel, cn); |
RyoheiHagimoto | 0:0e0631af0305 | 145 | return dst; |
RyoheiHagimoto | 0:0e0631af0305 | 146 | } |
RyoheiHagimoto | 0:0e0631af0305 | 147 | |
RyoheiHagimoto | 0:0e0631af0305 | 148 | /** @brief Create hppiMatrix from Mat. |
RyoheiHagimoto | 0:0e0631af0305 | 149 | |
RyoheiHagimoto | 0:0e0631af0305 | 150 | This function allocates and initializes the hppiMatrix that has the same size and type as input |
RyoheiHagimoto | 0:0e0631af0305 | 151 | matrix, returns the hppiMatrix*. |
RyoheiHagimoto | 0:0e0631af0305 | 152 | |
RyoheiHagimoto | 0:0e0631af0305 | 153 | If you want to use zero-copy for GPU you should to have 4KB aligned matrix data. See details |
RyoheiHagimoto | 0:0e0631af0305 | 154 | [hppiCreateSharedMatrix](http://software.intel.com/ru-ru/node/501697). |
RyoheiHagimoto | 0:0e0631af0305 | 155 | |
RyoheiHagimoto | 0:0e0631af0305 | 156 | Supports CV_8U, CV_16U, CV_16S, CV_32S, CV_32F, CV_64F. |
RyoheiHagimoto | 0:0e0631af0305 | 157 | |
RyoheiHagimoto | 0:0e0631af0305 | 158 | @note The hppiMatrix pointer to the image buffer in system memory refers to the src.data. Control |
RyoheiHagimoto | 0:0e0631af0305 | 159 | the lifetime of the matrix and don't change its data, if there is no special need. |
RyoheiHagimoto | 0:0e0631af0305 | 160 | @param src input matrix. |
RyoheiHagimoto | 0:0e0631af0305 | 161 | @param accel accelerator instance. Supports type: |
RyoheiHagimoto | 0:0e0631af0305 | 162 | - **HPP_ACCEL_TYPE_CPU** - accelerated by optimized CPU instructions. |
RyoheiHagimoto | 0:0e0631af0305 | 163 | - **HPP_ACCEL_TYPE_GPU** - accelerated by GPU programmable units or fixed-function |
RyoheiHagimoto | 0:0e0631af0305 | 164 | accelerators. |
RyoheiHagimoto | 0:0e0631af0305 | 165 | - **HPP_ACCEL_TYPE_ANY** - any acceleration or no acceleration available. |
RyoheiHagimoto | 0:0e0631af0305 | 166 | @sa howToUseIPPAconversion, hpp::getMat |
RyoheiHagimoto | 0:0e0631af0305 | 167 | */ |
RyoheiHagimoto | 0:0e0631af0305 | 168 | inline hppiMatrix* getHpp(const Mat& src, hppAccel accel) |
RyoheiHagimoto | 0:0e0631af0305 | 169 | { |
RyoheiHagimoto | 0:0e0631af0305 | 170 | int htype = toHppType(src.type()); |
RyoheiHagimoto | 0:0e0631af0305 | 171 | int cn = src.channels(); |
RyoheiHagimoto | 0:0e0631af0305 | 172 | |
RyoheiHagimoto | 0:0e0631af0305 | 173 | CV_Assert(src.data); |
RyoheiHagimoto | 0:0e0631af0305 | 174 | hppAccelType accelType = hppQueryAccelType(accel); |
RyoheiHagimoto | 0:0e0631af0305 | 175 | |
RyoheiHagimoto | 0:0e0631af0305 | 176 | if (accelType!=HPP_ACCEL_TYPE_CPU) |
RyoheiHagimoto | 0:0e0631af0305 | 177 | { |
RyoheiHagimoto | 0:0e0631af0305 | 178 | hpp32u pitch, size; |
RyoheiHagimoto | 0:0e0631af0305 | 179 | hppQueryMatrixAllocParams(accel, src.cols*cn, src.rows, htype, &pitch, &size); |
RyoheiHagimoto | 0:0e0631af0305 | 180 | if (pitch!=0 && size!=0) |
RyoheiHagimoto | 0:0e0631af0305 | 181 | if ((int)(src.data)%4096==0 && pitch==(hpp32u)(src.step)) |
RyoheiHagimoto | 0:0e0631af0305 | 182 | { |
RyoheiHagimoto | 0:0e0631af0305 | 183 | return hppiCreateSharedMatrix(htype, src.cols*cn, src.rows, src.data, pitch, size); |
RyoheiHagimoto | 0:0e0631af0305 | 184 | } |
RyoheiHagimoto | 0:0e0631af0305 | 185 | } |
RyoheiHagimoto | 0:0e0631af0305 | 186 | |
RyoheiHagimoto | 0:0e0631af0305 | 187 | return hppiCreateMatrix(htype, src.cols*cn, src.rows, src.data, (hpp32s)(src.step));; |
RyoheiHagimoto | 0:0e0631af0305 | 188 | } |
RyoheiHagimoto | 0:0e0631af0305 | 189 | |
RyoheiHagimoto | 0:0e0631af0305 | 190 | //! @} |
RyoheiHagimoto | 0:0e0631af0305 | 191 | }} |
RyoheiHagimoto | 0:0e0631af0305 | 192 | |
RyoheiHagimoto | 0:0e0631af0305 | 193 | #endif |
RyoheiHagimoto | 0:0e0631af0305 | 194 | |
RyoheiHagimoto | 0:0e0631af0305 | 195 | #endif |