Added SharedMatrix
This commit is contained in:
parent
fa2d79a15b
commit
037ac27ec8
@ -2,35 +2,35 @@
|
|||||||
# IPP_A_LIBRARIES and IPP_A_INCLUDE to use IPP Async
|
# IPP_A_LIBRARIES and IPP_A_INCLUDE to use IPP Async
|
||||||
# HAVE_IPP_A for conditional compilation OpenCV with/without IPP Async
|
# HAVE_IPP_A for conditional compilation OpenCV with/without IPP Async
|
||||||
|
|
||||||
# IPPAROOT - root of IPP Async installation
|
# IPP_ASYNC_ROOT - root of IPP Async installation
|
||||||
|
|
||||||
if(X86_64)
|
if(X86_64)
|
||||||
find_path(
|
find_path(
|
||||||
IPP_A_INCLUDE_DIR
|
IPP_A_INCLUDE_DIR
|
||||||
NAMES ipp_async_defs.h
|
NAMES ipp_async_defs.h
|
||||||
PATHS $ENV{IPPAROOT}
|
PATHS $ENV{IPP_ASYNC_ROOT}
|
||||||
PATH_SUFFIXES include
|
PATH_SUFFIXES include
|
||||||
DOC "Path to Intel IPP Async interface headers")
|
DOC "Path to Intel IPP Async interface headers")
|
||||||
|
|
||||||
find_file(
|
find_file(
|
||||||
IPP_A_LIBRARIES
|
IPP_A_LIBRARIES
|
||||||
NAMES ipp_async_preview.lib
|
NAMES ipp_async_preview.lib
|
||||||
PATHS $ENV{IPPAROOT}
|
PATHS $ENV{IPP_ASYNC_ROOT}
|
||||||
PATH_SUFFIXES lib/intel64
|
PATH_SUFFIXES lib/intel64
|
||||||
DOC "Path to Intel IPP Async interface libraries")
|
DOC "Path to Intel IPP Async interface libraries")
|
||||||
|
|
||||||
else()
|
else()
|
||||||
find_path(
|
find_path(
|
||||||
IPP_A_INCLUDE_DIR
|
IPP_A_INCLUDE_DIR
|
||||||
NAMES ipp_async_defs.h
|
NAMES ipp_async_defs.h
|
||||||
PATHS $ENV{IPPAROOT}
|
PATHS $ENV{IPP_ASYNC_ROOT}
|
||||||
PATH_SUFFIXES include
|
PATH_SUFFIXES include
|
||||||
DOC "Path to Intel IPP Async interface headers")
|
DOC "Path to Intel IPP Async interface headers")
|
||||||
|
|
||||||
find_file(
|
find_file(
|
||||||
IPP_A_LIBRARIES
|
IPP_A_LIBRARIES
|
||||||
NAMES ipp_async_preview.lib
|
NAMES ipp_async_preview.lib
|
||||||
PATHS $ENV{IPPAROOT}
|
PATHS $ENV{IPP_ASYNC_ROOT}
|
||||||
PATH_SUFFIXES lib/ia32
|
PATH_SUFFIXES lib/ia32
|
||||||
DOC "Path to Intel IPP Async interface libraries")
|
DOC "Path to Intel IPP Async interface libraries")
|
||||||
endif()
|
endif()
|
||||||
|
@ -9,14 +9,14 @@ Goal
|
|||||||
.. _hppiSobel: http://software.intel.com/en-us/node/474701
|
.. _hppiSobel: http://software.intel.com/en-us/node/474701
|
||||||
.. _hppiMatrix: http://software.intel.com/en-us/node/501660
|
.. _hppiMatrix: http://software.intel.com/en-us/node/501660
|
||||||
|
|
||||||
The tutorial demonstrates the `Intel® IPP Asynchronous C/C++ <http://software.intel.com/en-us/intel-ipp-preview>`_ library usage with OpenCV.
|
The tutorial demonstrates the `Intel® IPP Asynchronous C/C++ <http://software.intel.com/en-us/intel-ipp-preview>`_ library usage with OpenCV.
|
||||||
The code example below illustrates implementation of the Sobel operation, accelerated with Intel® IPP Asynchronous C/C++ functions.
|
The code example below illustrates implementation of the Sobel operation, accelerated with Intel® IPP Asynchronous C/C++ functions.
|
||||||
In this code example, :ippa_convert:`hpp::getMat <>` and :ippa_convert:`hpp::getHpp <>` functions are used for data conversion between hppiMatrix_ and ``Mat`` matrices.
|
In this code example, :ippa_convert:`hpp::getMat <>` and :ippa_convert:`hpp::getHpp <>` functions are used for data conversion between hppiMatrix_ and ``Mat`` matrices.
|
||||||
|
|
||||||
Code
|
Code
|
||||||
====
|
====
|
||||||
|
|
||||||
You may also find the source code in the :file:`samples/cpp/tutorial_code/core/ippasync/ippasync_sample.cpp`
|
You may also find the source code in the :file:`samples/cpp/tutorial_code/core/ippasync/ippasync_sample.cpp`
|
||||||
file of the OpenCV source library or :download:`download it from here
|
file of the OpenCV source library or :download:`download it from here
|
||||||
<../../../../samples/cpp/tutorial_code/core/ippasync/ippasync_sample.cpp>`.
|
<../../../../samples/cpp/tutorial_code/core/ippasync/ippasync_sample.cpp>`.
|
||||||
|
|
||||||
@ -24,7 +24,7 @@ file of the OpenCV source library or :download:`download it from here
|
|||||||
:language: cpp
|
:language: cpp
|
||||||
:linenos:
|
:linenos:
|
||||||
:tab-width: 4
|
:tab-width: 4
|
||||||
|
|
||||||
Explanation
|
Explanation
|
||||||
===========
|
===========
|
||||||
|
|
||||||
@ -38,17 +38,17 @@ Explanation
|
|||||||
and IPP Async:
|
and IPP Async:
|
||||||
|
|
||||||
.. code-block:: cpp
|
.. code-block:: cpp
|
||||||
|
|
||||||
Ptr<hppiMatrix> src, dst;
|
hppiMatrix* src,* dst;
|
||||||
hppAccel accel = 0;
|
hppAccel accel = 0;
|
||||||
hppAccelType accelType;
|
hppAccelType accelType;
|
||||||
hppStatus sts;
|
hppStatus sts;
|
||||||
hppiVirtualMatrix * virtMatrix;
|
hppiVirtualMatrix * virtMatrix;
|
||||||
|
|
||||||
#. Load input image or video. How to open and read video stream you can see in the :ref:`videoInputPSNRMSSIM` tutorial.
|
#. Load input image or video. How to open and read video stream you can see in the :ref:`videoInputPSNRMSSIM` tutorial.
|
||||||
|
|
||||||
.. code-block:: cpp
|
.. code-block:: cpp
|
||||||
|
|
||||||
if( useCamera )
|
if( useCamera )
|
||||||
{
|
{
|
||||||
printf("used camera\n");
|
printf("used camera\n");
|
||||||
@ -65,25 +65,25 @@ Explanation
|
|||||||
printf("can not open camera or video file\n");
|
printf("can not open camera or video file\n");
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
#. Create accelerator instance using `hppCreateInstance <http://software.intel.com/en-us/node/501686>`_:
|
#. Create accelerator instance using `hppCreateInstance <http://software.intel.com/en-us/node/501686>`_:
|
||||||
|
|
||||||
.. code-block:: cpp
|
.. code-block:: cpp
|
||||||
|
|
||||||
accelType = sAccel == "cpu" ? HPP_ACCEL_TYPE_CPU:
|
accelType = sAccel == "cpu" ? HPP_ACCEL_TYPE_CPU:
|
||||||
sAccel == "gpu" ? HPP_ACCEL_TYPE_GPU:
|
sAccel == "gpu" ? HPP_ACCEL_TYPE_GPU:
|
||||||
HPP_ACCEL_TYPE_ANY;
|
HPP_ACCEL_TYPE_ANY;
|
||||||
|
|
||||||
//Create accelerator instance
|
//Create accelerator instance
|
||||||
sts = hppCreateInstance(accelType, 0, &accel);
|
sts = hppCreateInstance(accelType, 0, &accel);
|
||||||
CHECK_STATUS(sts, "hppCreateInstance");
|
CHECK_STATUS(sts, "hppCreateInstance");
|
||||||
|
|
||||||
#. Create an array of virtual matrices using `hppiCreateVirtualMatrices <http://software.intel.com/en-us/node/501700>`_ function.
|
#. Create an array of virtual matrices using `hppiCreateVirtualMatrices <http://software.intel.com/en-us/node/501700>`_ function.
|
||||||
|
|
||||||
.. code-block:: cpp
|
.. code-block:: cpp
|
||||||
|
|
||||||
virtMatrix = hppiCreateVirtualMatrices(accel, 1);
|
virtMatrix = hppiCreateVirtualMatrices(accel, 1);
|
||||||
|
|
||||||
#. Prepare a matrix for input and output data:
|
#. Prepare a matrix for input and output data:
|
||||||
|
|
||||||
.. code-block:: cpp
|
.. code-block:: cpp
|
||||||
@ -95,14 +95,14 @@ Explanation
|
|||||||
cvtColor( image, gray, COLOR_BGR2GRAY );
|
cvtColor( image, gray, COLOR_BGR2GRAY );
|
||||||
|
|
||||||
result.create( image.rows, image.cols, CV_8U);
|
result.create( image.rows, image.cols, CV_8U);
|
||||||
|
|
||||||
#. Convert ``Mat`` to hppiMatrix_ using :ippa_convert:`getHpp <>` and call hppiSobel_ function.
|
#. Convert ``Mat`` to hppiMatrix_ using :ippa_convert:`getHpp <>` and call hppiSobel_ function.
|
||||||
|
|
||||||
.. code-block:: cpp
|
.. code-block:: cpp
|
||||||
|
|
||||||
//convert Mat to hppiMatrix
|
//convert Mat to hppiMatrix
|
||||||
src = getHpp(gray);
|
src = getHpp(gray, accel);
|
||||||
dst = getHpp(result);
|
dst = getHpp(result, accel);
|
||||||
|
|
||||||
sts = hppiSobel(accel,src, HPP_MASK_SIZE_3X3,HPP_NORM_L1,virtMatrix[0]);
|
sts = hppiSobel(accel,src, HPP_MASK_SIZE_3X3,HPP_NORM_L1,virtMatrix[0]);
|
||||||
CHECK_STATUS(sts,"hppiSobel");
|
CHECK_STATUS(sts,"hppiSobel");
|
||||||
@ -113,7 +113,7 @@ Explanation
|
|||||||
// Wait for tasks to complete
|
// Wait for tasks to complete
|
||||||
sts = hppWait(accel, HPP_TIME_OUT_INFINITE);
|
sts = hppWait(accel, HPP_TIME_OUT_INFINITE);
|
||||||
CHECK_STATUS(sts, "hppWait");
|
CHECK_STATUS(sts, "hppWait");
|
||||||
|
|
||||||
We use `hppiConvert <http://software.intel.com/en-us/node/501746>`_ because hppiSobel_ returns destination
|
We use `hppiConvert <http://software.intel.com/en-us/node/501746>`_ because hppiSobel_ returns destination
|
||||||
matrix with ``HPP_DATA_TYPE_16S`` data type for source matrix with ``HPP_DATA_TYPE_8U`` type.
|
matrix with ``HPP_DATA_TYPE_16S`` data type for source matrix with ``HPP_DATA_TYPE_8U`` type.
|
||||||
You should check ``hppStatus`` after each call IPP Async function.
|
You should check ``hppStatus`` after each call IPP Async function.
|
||||||
@ -126,7 +126,17 @@ Explanation
|
|||||||
imshow("rez", result);
|
imshow("rez", result);
|
||||||
|
|
||||||
waitKey(15);
|
waitKey(15);
|
||||||
|
|
||||||
|
#. Delete hpp matrices.
|
||||||
|
|
||||||
|
.. code-block:: cpp
|
||||||
|
|
||||||
|
sts = hppiFreeMatrix(src);
|
||||||
|
CHECK_DEL_STATUS(sts,"hppiFreeMatrix");
|
||||||
|
|
||||||
|
sts = hppiFreeMatrix(dst);
|
||||||
|
CHECK_DEL_STATUS(sts,"hppiFreeMatrix");
|
||||||
|
|
||||||
#. Delete virtual matrices and accelerator instance.
|
#. Delete virtual matrices and accelerator instance.
|
||||||
|
|
||||||
.. code-block:: cpp
|
.. code-block:: cpp
|
||||||
@ -143,12 +153,10 @@ Explanation
|
|||||||
CHECK_DEL_STATUS(sts, "hppDeleteInstance");
|
CHECK_DEL_STATUS(sts, "hppDeleteInstance");
|
||||||
}
|
}
|
||||||
|
|
||||||
We shouldn't delete hppiMatrix_ because we use :ptr:`Ptr <>` and so `hppiFreeMatrix <http://software.intel.com/en-us/node/501699>`_ will be called implicitly.
|
|
||||||
|
|
||||||
Result
|
Result
|
||||||
=======
|
=======
|
||||||
|
|
||||||
After compiling the code above we can execute it giving an image or video path and accelerator type as an argument.
|
After compiling the code above we can execute it giving an image or video path and accelerator type as an argument.
|
||||||
For this tutorial we use baboon.png image as input. The result is below.
|
For this tutorial we use baboon.png image as input. The result is below.
|
||||||
|
|
||||||
.. image:: images/How_To_Use_IPPA_Result.jpg
|
.. image:: images/How_To_Use_IPPA_Result.jpg
|
||||||
|
@ -204,7 +204,7 @@ Here you will learn the about the basic building blocks of the library. A must r
|
|||||||
+
|
+
|
||||||
.. tabularcolumns:: m{100pt} m{300pt}
|
.. tabularcolumns:: m{100pt} m{300pt}
|
||||||
.. cssclass:: toctableopencv
|
.. cssclass:: toctableopencv
|
||||||
|
|
||||||
=============== ======================================================
|
=============== ======================================================
|
||||||
|IPPIma| **Title:** :ref:`howToUseIPPAconversion`
|
|IPPIma| **Title:** :ref:`howToUseIPPAconversion`
|
||||||
|
|
||||||
@ -213,15 +213,16 @@ Here you will learn the about the basic building blocks of the library. A must r
|
|||||||
*Author:* |Author_ElenaG|
|
*Author:* |Author_ElenaG|
|
||||||
|
|
||||||
You will see how to use the IPP Async with OpenCV.
|
You will see how to use the IPP Async with OpenCV.
|
||||||
|
|
||||||
=============== ======================================================
|
=============== ======================================================
|
||||||
|
|
||||||
.. |IPPIma| image:: images/How_To_Use_IPPA.jpg
|
.. |IPPIma| image:: images/How_To_Use_IPPA.jpg
|
||||||
:height: 90pt
|
:height: 90pt
|
||||||
:width: 90pt
|
:width: 90pt
|
||||||
.. |Author_ElenaG| unicode:: Elena U+0020 Gvozdeva
|
.. |Author_ElenaG| unicode:: Elena U+0020 Gvozdeva
|
||||||
|
|
||||||
=============== ======================================================
|
=============== ======================================================
|
||||||
|
|
||||||
.. raw:: latex
|
.. raw:: latex
|
||||||
|
|
||||||
\pagebreak
|
\pagebreak
|
||||||
|
@ -62,6 +62,8 @@ Building the OpenCV library from scratch requires a couple of tools installed be
|
|||||||
.. _IntelTBB: http://threadingbuildingblocks.org/file.php?fid=77
|
.. _IntelTBB: http://threadingbuildingblocks.org/file.php?fid=77
|
||||||
.. |IntelIIP| replace:: Intel |copy| Integrated Performance Primitives (*IPP*)
|
.. |IntelIIP| replace:: Intel |copy| Integrated Performance Primitives (*IPP*)
|
||||||
.. _IntelIIP: http://software.intel.com/en-us/articles/intel-ipp/
|
.. _IntelIIP: http://software.intel.com/en-us/articles/intel-ipp/
|
||||||
|
.. |IntelIIPA| replace:: Intel |copy| IPP Asynchronous C/C++
|
||||||
|
.. _IntelIIPA: http://software.intel.com/en-us/intel-ipp-preview
|
||||||
.. |qtframework| replace:: Qt framework
|
.. |qtframework| replace:: Qt framework
|
||||||
.. _qtframework: http://qt.nokia.com/downloads
|
.. _qtframework: http://qt.nokia.com/downloads
|
||||||
.. |Eigen| replace:: Eigen
|
.. |Eigen| replace:: Eigen
|
||||||
@ -97,6 +99,8 @@ OpenCV may come in multiple flavors. There is a "core" section that will work on
|
|||||||
|
|
||||||
+ |IntelIIP|_ may be used to improve the performance of color conversion, Haar training and DFT functions of the OpenCV library. Watch out, since this isn't a free service.
|
+ |IntelIIP|_ may be used to improve the performance of color conversion, Haar training and DFT functions of the OpenCV library. Watch out, since this isn't a free service.
|
||||||
|
|
||||||
|
+ |IntelIIPA|_ is currently focused delivering Intel |copy| Graphics support for advanced image processing and computer vision functions.
|
||||||
|
|
||||||
+ OpenCV offers a somewhat fancier and more useful graphical user interface, than the default one by using the |qtframework|_. For a quick overview of what this has to offer look into the documentations *highgui* module, under the *Qt New Functions* section. Version 4.6 or later of the framework is required.
|
+ OpenCV offers a somewhat fancier and more useful graphical user interface, than the default one by using the |qtframework|_. For a quick overview of what this has to offer look into the documentations *highgui* module, under the *Qt New Functions* section. Version 4.6 or later of the framework is required.
|
||||||
|
|
||||||
+ |Eigen|_ is a C++ template library for linear algebra.
|
+ |Eigen|_ is a C++ template library for linear algebra.
|
||||||
@ -168,6 +172,8 @@ Building the library
|
|||||||
:alt: The Miktex Install Screen
|
:alt: The Miktex Install Screen
|
||||||
:align: center
|
:align: center
|
||||||
|
|
||||||
|
#) For the |IntelIIPA|_ download the source files and set environment variable **IPP_ASYNC_ROOT**. It should point to :file:`<your Program Files(x86) directory>/Intel/IPP Preview */ipp directory`. Here ``*`` denotes the particular preview name.
|
||||||
|
|
||||||
#) In case of the |Eigen|_ library it is again a case of download and extract to the :file:`D:/OpenCV/dep` directory.
|
#) In case of the |Eigen|_ library it is again a case of download and extract to the :file:`D:/OpenCV/dep` directory.
|
||||||
|
|
||||||
#) Same as above with |OpenEXR|_.
|
#) Same as above with |OpenEXR|_.
|
||||||
|
@ -6,21 +6,31 @@ Intel® IPP Asynchronous C/C++ Converters
|
|||||||
General Information
|
General Information
|
||||||
-------------------
|
-------------------
|
||||||
|
|
||||||
This section describes conversion between OpenCV and `Intel® IPP Asynchronous C/C++ <http://software.intel.com/en-us/intel-ipp-preview>`_ library.
|
This section describes conversion between OpenCV and `Intel® IPP Asynchronous C/C++ <http://software.intel.com/en-us/intel-ipp-preview>`_ library.
|
||||||
`Getting Started Guide <http://registrationcenter.intel.com/irc_nas/3727/ipp_async_get_started.htm>`_ help you to install the library, configure header and library build paths.
|
`Getting Started Guide <http://registrationcenter.intel.com/irc_nas/3727/ipp_async_get_started.htm>`_ help you to install the library, configure header and library build paths.
|
||||||
|
|
||||||
hpp::getHpp
|
hpp::getHpp
|
||||||
-----------
|
-----------
|
||||||
Create ``hppiMatrix`` from ``Mat``.
|
Create ``hppiMatrix`` from ``Mat``.
|
||||||
|
|
||||||
.. ocv:function:: Ptr<hppiMatrix> hpp::getHpp(const Mat& src)
|
.. ocv:function:: hppiMatrix* hpp::getHpp(const Mat& src, hppAccel accel)
|
||||||
|
|
||||||
:param src: input matrix.
|
:param src: input matrix.
|
||||||
|
:param accel: accelerator instance. Supports type:
|
||||||
|
|
||||||
|
* **HPP_ACCEL_TYPE_CPU** - accelerated by optimized CPU instructions.
|
||||||
|
|
||||||
|
* **HPP_ACCEL_TYPE_GPU** - accelerated by GPU programmable units or fixed-function accelerators.
|
||||||
|
|
||||||
|
* **HPP_ACCEL_TYPE_ANY** - any acceleration or no acceleration available.
|
||||||
|
|
||||||
|
This function allocates and initializes the ``hppiMatrix`` that has the same size and type as input matrix, returns the ``hppiMatrix*``.
|
||||||
|
|
||||||
|
If you want to use zero-copy for GPU you should to have 4KB aligned matrix data. See details `hppiCreateSharedMatrix <http://software.intel.com/ru-ru/node/501697>`_.
|
||||||
|
|
||||||
This function allocates and initializes the ``hppiMatrix`` that has the same size and type as input matrix, returns the ``Ptr<hppiMatrix>``.
|
|
||||||
Supports ``CV_8U``, ``CV_16U``, ``CV_16S``, ``CV_32S``, ``CV_32F``, ``CV_64F``.
|
Supports ``CV_8U``, ``CV_16U``, ``CV_16S``, ``CV_32S``, ``CV_32F``, ``CV_64F``.
|
||||||
|
|
||||||
.. note:: The ``hppiMatrix`` pointer to the image buffer in system memory refers to the ``src.data``. Control the lifetime of the matrix and don't change its data, if there is no special need.
|
.. note:: The ``hppiMatrix`` pointer to the image buffer in system memory refers to the ``src.data``. Control the lifetime of the matrix and don't change its data, if there is no special need.
|
||||||
.. seealso:: :ref:`howToUseIPPAconversion`, :ocv:func:`hpp::getMat`
|
.. seealso:: :ref:`howToUseIPPAconversion`, :ocv:func:`hpp::getMat`
|
||||||
|
|
||||||
|
|
||||||
@ -32,11 +42,11 @@ Create ``Mat`` from ``hppiMatrix``.
|
|||||||
|
|
||||||
:param src: input hppiMatrix.
|
:param src: input hppiMatrix.
|
||||||
|
|
||||||
:param accel: accelerator instance.
|
:param accel: accelerator instance (see :ocv:func:`hpp::getHpp` for the list of acceleration framework types).
|
||||||
|
|
||||||
:param cn: number of channels.
|
:param cn: number of channels.
|
||||||
|
|
||||||
This function allocates and initializes the ``Mat`` that has the same size and type as input matrix.
|
This function allocates and initializes the ``Mat`` that has the same size and type as input matrix.
|
||||||
Supports ``CV_8U``, ``CV_16U``, ``CV_16S``, ``CV_32S``, ``CV_32F``, ``CV_64F``.
|
Supports ``CV_8U``, ``CV_16U``, ``CV_16S``, ``CV_32S``, ``CV_32F``, ``CV_64F``.
|
||||||
|
|
||||||
.. seealso:: :ref:`howToUseIPPAconversion`, :ocv:func:`hpp::copyHppToMat`, :ocv:func:`hpp::getHpp`.
|
.. seealso:: :ref:`howToUseIPPAconversion`, :ocv:func:`hpp::copyHppToMat`, :ocv:func:`hpp::getHpp`.
|
||||||
@ -49,14 +59,14 @@ Convert ``hppiMatrix`` to ``Mat``.
|
|||||||
.. ocv:function:: void hpp::copyHppToMat(hppiMatrix* src, Mat& dst, hppAccel accel, int cn)
|
.. ocv:function:: void hpp::copyHppToMat(hppiMatrix* src, Mat& dst, hppAccel accel, int cn)
|
||||||
|
|
||||||
:param src: input hppiMatrix.
|
:param src: input hppiMatrix.
|
||||||
|
|
||||||
:param dst: output matrix.
|
:param dst: output matrix.
|
||||||
|
|
||||||
:param accel: accelerator instance.
|
:param accel: accelerator instance (see :ocv:func:`hpp::getHpp` for the list of acceleration framework types).
|
||||||
|
|
||||||
:param cn: number of channels.
|
:param cn: number of channels.
|
||||||
|
|
||||||
This function allocates and initializes new matrix (if needed) that has the same size and type as input matrix.
|
This function allocates and initializes new matrix (if needed) that has the same size and type as input matrix.
|
||||||
Supports ``CV_8U``, ``CV_16U``, ``CV_16S``, ``CV_32S``, ``CV_32F``, ``CV_64F``.
|
Supports ``CV_8U``, ``CV_16U``, ``CV_16S``, ``CV_32S``, ``CV_32F``, ``CV_64F``.
|
||||||
|
|
||||||
.. seealso:: :ref:`howToUseIPPAconversion`, :ocv:func:`hpp::getMat`, :ocv:func:`hpp::getHpp`.
|
.. seealso:: :ref:`howToUseIPPAconversion`, :ocv:func:`hpp::getMat`, :ocv:func:`hpp::getHpp`.
|
@ -1,16 +1,14 @@
|
|||||||
#ifndef __OPENCV_CORE_IPPASYNC_HPP__
|
#ifndef __OPENCV_CORE_IPPASYNC_HPP__
|
||||||
#define __OPENCV_CORE_IPPASYNC_HPP__
|
#define __OPENCV_CORE_IPPASYNC_HPP__
|
||||||
|
|
||||||
|
#ifdef HAVE_IPP_A
|
||||||
|
|
||||||
#include "opencv2/core.hpp"
|
#include "opencv2/core.hpp"
|
||||||
#include <ipp_async_op.h>
|
#include <ipp_async_op.h>
|
||||||
#include <ipp_async_accel.h>
|
#include <ipp_async_accel.h>
|
||||||
|
|
||||||
namespace cv
|
namespace cv
|
||||||
{
|
{
|
||||||
void DefaultDeleter<hppiMatrix>::operator () (hppiMatrix* p) const
|
|
||||||
{
|
|
||||||
hppiFreeMatrix(p);
|
|
||||||
}
|
|
||||||
|
|
||||||
namespace hpp
|
namespace hpp
|
||||||
{
|
{
|
||||||
@ -25,7 +23,7 @@ namespace hpp
|
|||||||
depth == CV_32F ? HPP_DATA_TYPE_32F :
|
depth == CV_32F ? HPP_DATA_TYPE_32F :
|
||||||
depth == CV_64F ? HPP_DATA_TYPE_64F : -1;
|
depth == CV_64F ? HPP_DATA_TYPE_64F : -1;
|
||||||
CV_Assert( hppType >= 0 );
|
CV_Assert( hppType >= 0 );
|
||||||
return hppType;
|
return hppType;
|
||||||
}
|
}
|
||||||
|
|
||||||
//convert hppDataType to OpenCV data type
|
//convert hppDataType to OpenCV data type
|
||||||
@ -47,7 +45,8 @@ namespace hpp
|
|||||||
hpp32u width, height;
|
hpp32u width, height;
|
||||||
hppStatus sts;
|
hppStatus sts;
|
||||||
|
|
||||||
CV_Assert(src!=NULL);
|
if (src == NULL)
|
||||||
|
return dst.release();
|
||||||
|
|
||||||
sts = hppiInquireMatrix(src, &type, &width, &height);
|
sts = hppiInquireMatrix(src, &type, &width, &height);
|
||||||
|
|
||||||
@ -76,17 +75,31 @@ namespace hpp
|
|||||||
return dst;
|
return dst;
|
||||||
}
|
}
|
||||||
|
|
||||||
//create hppiMatrix from cv::Mat
|
//create hppiMatrix from cv::Mat
|
||||||
inline Ptr<hppiMatrix> getHpp(const Mat& src)
|
inline hppiMatrix* getHpp(const Mat& src, hppAccel accel)
|
||||||
{
|
{
|
||||||
int htype = toHppType(src.type());
|
int htype = toHppType(src.type());
|
||||||
int cn = src.channels();
|
int cn = src.channels();
|
||||||
|
|
||||||
CV_Assert(src.data);
|
CV_Assert(src.data);
|
||||||
hppiMatrix *dst = hppiCreateMatrix(htype, src.cols*cn, src.rows, src.data, (hpp32s)(src.step));
|
hppAccelType accelType = hppQueryAccelType(accel);
|
||||||
|
|
||||||
return Ptr<hppiMatrix>(dst);
|
if (accelType!=HPP_ACCEL_TYPE_CPU)
|
||||||
|
{
|
||||||
|
hpp32u pitch, size;
|
||||||
|
hppQueryMatrixAllocParams(accel, src.cols*cn, src.rows, htype, &pitch, &size);
|
||||||
|
if (pitch!=0 && size!=0)
|
||||||
|
if ((int)(src.data)%4096==0 && pitch==(hpp32u)(src.step))
|
||||||
|
{
|
||||||
|
return hppiCreateSharedMatrix(htype, src.cols*cn, src.rows, src.data, pitch, size);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return hppiCreateMatrix(htype, src.cols*cn, src.rows, src.data, (hpp32s)(src.step));;
|
||||||
}
|
}
|
||||||
|
|
||||||
}}
|
}}
|
||||||
|
|
||||||
|
#endif
|
||||||
|
|
||||||
#endif
|
#endif
|
@ -1,6 +1,7 @@
|
|||||||
#include "test_precomp.hpp"
|
#include "test_precomp.hpp"
|
||||||
#include "opencv2/ts/ocl_test.hpp"
|
#include "opencv2/ts/ocl_test.hpp"
|
||||||
|
|
||||||
|
#ifdef HAVE_IPP_A
|
||||||
#include "opencv2/core/ippasync.hpp"
|
#include "opencv2/core/ippasync.hpp"
|
||||||
|
|
||||||
using namespace cv;
|
using namespace cv;
|
||||||
@ -18,7 +19,7 @@ PARAM_TEST_CASE(IPPAsync, MatDepth, Channels, hppAccelType)
|
|||||||
hppAccelType accelType;
|
hppAccelType accelType;
|
||||||
|
|
||||||
Mat matrix, result;
|
Mat matrix, result;
|
||||||
Ptr<hppiMatrix> hppMat;
|
hppiMatrix * hppMat;
|
||||||
hppAccel accel;
|
hppAccel accel;
|
||||||
hppiVirtualMatrix * virtMatrix;
|
hppiVirtualMatrix * virtMatrix;
|
||||||
hppStatus sts;
|
hppStatus sts;
|
||||||
@ -47,17 +48,16 @@ PARAM_TEST_CASE(IPPAsync, MatDepth, Channels, hppAccelType)
|
|||||||
|
|
||||||
TEST_P(IPPAsync, accuracy)
|
TEST_P(IPPAsync, accuracy)
|
||||||
{
|
{
|
||||||
if (depth==CV_32S || depth==CV_64F)
|
|
||||||
return;
|
|
||||||
|
|
||||||
sts = hppCreateInstance(accelType, 0, &accel);
|
sts = hppCreateInstance(accelType, 0, &accel);
|
||||||
|
if (sts!=HPP_STATUS_NO_ERROR) printf("hppStatus= %d\n",sts);
|
||||||
CV_Assert(sts==HPP_STATUS_NO_ERROR);
|
CV_Assert(sts==HPP_STATUS_NO_ERROR);
|
||||||
|
|
||||||
virtMatrix = hppiCreateVirtualMatrices(accel, 2);
|
virtMatrix = hppiCreateVirtualMatrices(accel, 2);
|
||||||
|
|
||||||
for (int j = 0; j < test_loop_times; j++)
|
for (int j = 0; j < test_loop_times; j++)
|
||||||
{
|
{
|
||||||
generateTestData();
|
generateTestData();
|
||||||
hppMat = hpp::getHpp(matrix);
|
hppMat = hpp::getHpp(matrix,accel);
|
||||||
|
|
||||||
hppScalar a = 3;
|
hppScalar a = 3;
|
||||||
|
|
||||||
@ -68,10 +68,13 @@ TEST_P(IPPAsync, accuracy)
|
|||||||
|
|
||||||
sts = hppWait(accel, HPP_TIME_OUT_INFINITE);
|
sts = hppWait(accel, HPP_TIME_OUT_INFINITE);
|
||||||
CV_Assert(sts==HPP_STATUS_NO_ERROR);
|
CV_Assert(sts==HPP_STATUS_NO_ERROR);
|
||||||
|
|
||||||
result = hpp::getMat(virtMatrix[1], accel, cn);
|
result = hpp::getMat(virtMatrix[1], accel, cn);
|
||||||
|
|
||||||
Near(5.0e-6);
|
Near(5.0e-6);
|
||||||
|
|
||||||
|
sts = hppiFreeMatrix(hppMat);
|
||||||
|
CV_Assert(sts==HPP_STATUS_NO_ERROR);
|
||||||
}
|
}
|
||||||
|
|
||||||
sts = hppiDeleteVirtualMatrices(accel, virtMatrix);
|
sts = hppiDeleteVirtualMatrices(accel, virtMatrix);
|
||||||
@ -80,26 +83,82 @@ TEST_P(IPPAsync, accuracy)
|
|||||||
CV_Assert(sts==HPP_STATUS_NO_ERROR);
|
CV_Assert(sts==HPP_STATUS_NO_ERROR);
|
||||||
}
|
}
|
||||||
|
|
||||||
TEST_P(IPPAsync, conversion)
|
PARAM_TEST_CASE(IPPAsyncShared, Channels, hppAccelType)
|
||||||
|
{
|
||||||
|
int cn;
|
||||||
|
int type;
|
||||||
|
hppAccelType accelType;
|
||||||
|
|
||||||
|
Mat matrix, result;
|
||||||
|
hppiMatrix* hppMat;
|
||||||
|
hppAccel accel;
|
||||||
|
hppiVirtualMatrix * virtMatrix;
|
||||||
|
hppStatus sts;
|
||||||
|
|
||||||
|
virtual void SetUp()
|
||||||
|
{
|
||||||
|
cn = GET_PARAM(0);
|
||||||
|
accelType = GET_PARAM(1);
|
||||||
|
type=CV_MAKE_TYPE(CV_8U, GET_PARAM(0));
|
||||||
|
}
|
||||||
|
|
||||||
|
virtual void generateTestData()
|
||||||
|
{
|
||||||
|
Size matrix_Size = randomSize(2, 100);
|
||||||
|
hpp32u pitch, size;
|
||||||
|
const int upValue = 100;
|
||||||
|
|
||||||
|
sts = hppQueryMatrixAllocParams(accel, (hpp32u)(matrix_Size.width*cn), (hpp32u)matrix_Size.height, HPP_DATA_TYPE_8U, &pitch, &size);
|
||||||
|
|
||||||
|
if (pitch!=0 && size!=0)
|
||||||
|
{
|
||||||
|
uchar *pData = (uchar*)_aligned_malloc(size, 4096);
|
||||||
|
|
||||||
|
for (int j=0; j<matrix_Size.height; j++)
|
||||||
|
for(int i=0; i<matrix_Size.width*cn; i++)
|
||||||
|
pData[i+j*pitch] = rand()%upValue;
|
||||||
|
|
||||||
|
matrix = Mat(matrix_Size.height, matrix_Size.width, type, pData, pitch);
|
||||||
|
}
|
||||||
|
|
||||||
|
matrix = randomMat(matrix_Size, type, 0, upValue);
|
||||||
|
}
|
||||||
|
|
||||||
|
void Near(double threshold = 0.0)
|
||||||
|
{
|
||||||
|
EXPECT_MAT_NEAR(matrix, result, threshold);
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
TEST_P(IPPAsyncShared, accuracy)
|
||||||
{
|
{
|
||||||
sts = hppCreateInstance(accelType, 0, &accel);
|
sts = hppCreateInstance(accelType, 0, &accel);
|
||||||
|
if (sts!=HPP_STATUS_NO_ERROR) printf("hppStatus= %d\n",sts);
|
||||||
CV_Assert(sts==HPP_STATUS_NO_ERROR);
|
CV_Assert(sts==HPP_STATUS_NO_ERROR);
|
||||||
virtMatrix = hppiCreateVirtualMatrices(accel, 1);
|
|
||||||
|
virtMatrix = hppiCreateVirtualMatrices(accel, 2);
|
||||||
|
|
||||||
for (int j = 0; j < test_loop_times; j++)
|
for (int j = 0; j < test_loop_times; j++)
|
||||||
{
|
{
|
||||||
generateTestData();
|
generateTestData();
|
||||||
hppMat = hpp::getHpp(matrix);
|
hppMat = hpp::getHpp(matrix,accel);
|
||||||
|
|
||||||
sts = hppiCopy (accel, hppMat, virtMatrix[0]);
|
hppScalar a = 3;
|
||||||
|
|
||||||
|
sts = hppiAddC(accel, hppMat, a, 0, virtMatrix[0]);
|
||||||
|
CV_Assert(sts==HPP_STATUS_NO_ERROR);
|
||||||
|
sts = hppiSubC(accel, virtMatrix[0], a, 0, virtMatrix[1]);
|
||||||
CV_Assert(sts==HPP_STATUS_NO_ERROR);
|
CV_Assert(sts==HPP_STATUS_NO_ERROR);
|
||||||
|
|
||||||
sts = hppWait(accel, HPP_TIME_OUT_INFINITE);
|
sts = hppWait(accel, HPP_TIME_OUT_INFINITE);
|
||||||
CV_Assert(sts==HPP_STATUS_NO_ERROR);
|
CV_Assert(sts==HPP_STATUS_NO_ERROR);
|
||||||
|
|
||||||
result = hpp::getMat(virtMatrix[0], accel, cn);
|
|
||||||
|
|
||||||
Near();
|
result = hpp::getMat(virtMatrix[1], accel, cn);
|
||||||
|
|
||||||
|
Near(0);
|
||||||
|
|
||||||
|
sts = hppiFreeMatrix(hppMat);
|
||||||
|
CV_Assert(sts==HPP_STATUS_NO_ERROR);
|
||||||
}
|
}
|
||||||
|
|
||||||
sts = hppiDeleteVirtualMatrices(accel, virtMatrix);
|
sts = hppiDeleteVirtualMatrices(accel, virtMatrix);
|
||||||
@ -108,9 +167,13 @@ TEST_P(IPPAsync, conversion)
|
|||||||
CV_Assert(sts==HPP_STATUS_NO_ERROR);
|
CV_Assert(sts==HPP_STATUS_NO_ERROR);
|
||||||
}
|
}
|
||||||
|
|
||||||
INSTANTIATE_TEST_CASE_P(IppATest, IPPAsync, Combine(Values(CV_8U, CV_16U, CV_16S, CV_32S, CV_32F, CV_64F),
|
INSTANTIATE_TEST_CASE_P(IppATest, IPPAsyncShared, Combine(Values(1, 2, 3, 4),
|
||||||
|
Values( HPP_ACCEL_TYPE_CPU, HPP_ACCEL_TYPE_GPU)));
|
||||||
|
|
||||||
|
INSTANTIATE_TEST_CASE_P(IppATest, IPPAsync, Combine(Values(CV_8U, CV_16U, CV_16S, CV_32F),
|
||||||
Values(1, 2, 3, 4),
|
Values(1, 2, 3, 4),
|
||||||
Values( HPP_ACCEL_TYPE_CPU, HPP_ACCEL_TYPE_GPU)));
|
Values( HPP_ACCEL_TYPE_CPU, HPP_ACCEL_TYPE_GPU)));
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
#endif
|
@ -1,9 +1,15 @@
|
|||||||
#include <stdio.h>
|
#include <stdio.h>
|
||||||
|
|
||||||
#include "opencv2/core/utility.hpp"
|
#include "opencv2/core/utility.hpp"
|
||||||
#include "opencv2/core/ippasync.hpp"
|
|
||||||
#include "opencv2/imgproc.hpp"
|
#include "opencv2/imgproc.hpp"
|
||||||
#include "opencv2/highgui.hpp"
|
#include "opencv2/highgui.hpp"
|
||||||
|
#include "cvconfig.h"
|
||||||
|
|
||||||
|
using namespace std;
|
||||||
|
using namespace cv;
|
||||||
|
|
||||||
|
#ifdef HAVE_IPP_A
|
||||||
|
#include "opencv2/core/ippasync.hpp"
|
||||||
|
|
||||||
#define CHECK_STATUS(STATUS, NAME)\
|
#define CHECK_STATUS(STATUS, NAME)\
|
||||||
if(STATUS!=HPP_STATUS_NO_ERROR){ printf("%s error %d\n", NAME, STATUS);\
|
if(STATUS!=HPP_STATUS_NO_ERROR){ printf("%s error %d\n", NAME, STATUS);\
|
||||||
@ -14,9 +20,7 @@
|
|||||||
#define CHECK_DEL_STATUS(STATUS, NAME)\
|
#define CHECK_DEL_STATUS(STATUS, NAME)\
|
||||||
if(STATUS!=HPP_STATUS_NO_ERROR){ printf("%s error %d\n", NAME, STATUS); return -1;}
|
if(STATUS!=HPP_STATUS_NO_ERROR){ printf("%s error %d\n", NAME, STATUS); return -1;}
|
||||||
|
|
||||||
using namespace std;
|
#endif
|
||||||
using namespace cv;
|
|
||||||
using namespace hpp;
|
|
||||||
|
|
||||||
static void help()
|
static void help()
|
||||||
{
|
{
|
||||||
@ -42,15 +46,17 @@ int main(int argc, const char** argv)
|
|||||||
help();
|
help();
|
||||||
|
|
||||||
VideoCapture cap;
|
VideoCapture cap;
|
||||||
|
CommandLineParser parser(argc, argv, keys);
|
||||||
Mat image, gray, result;
|
Mat image, gray, result;
|
||||||
|
|
||||||
Ptr<hppiMatrix> src, dst;
|
#ifdef HAVE_IPP_A
|
||||||
|
|
||||||
|
hppiMatrix* src,* dst;
|
||||||
hppAccel accel = 0;
|
hppAccel accel = 0;
|
||||||
hppAccelType accelType;
|
hppAccelType accelType;
|
||||||
hppStatus sts;
|
hppStatus sts;
|
||||||
hppiVirtualMatrix * virtMatrix;
|
hppiVirtualMatrix * virtMatrix;
|
||||||
|
|
||||||
CommandLineParser parser(argc, argv, keys);
|
|
||||||
bool useCamera = parser.has("camera");
|
bool useCamera = parser.has("camera");
|
||||||
string file = parser.get<string>("file_name");
|
string file = parser.get<string>("file_name");
|
||||||
string sAccel = parser.get<string>("accel");
|
string sAccel = parser.get<string>("accel");
|
||||||
@ -104,10 +110,10 @@ int main(int argc, const char** argv)
|
|||||||
result.create( image.rows, image.cols, CV_8U);
|
result.create( image.rows, image.cols, CV_8U);
|
||||||
|
|
||||||
double execTime = (double)getTickCount();
|
double execTime = (double)getTickCount();
|
||||||
|
|
||||||
//convert Mat to hppiMatrix
|
//convert Mat to hppiMatrix
|
||||||
src = getHpp(gray);
|
src = hpp::getHpp(gray,accel);
|
||||||
dst = getHpp(result);
|
dst = hpp::getHpp(result,accel);
|
||||||
|
|
||||||
sts = hppiSobel(accel,src, HPP_MASK_SIZE_3X3,HPP_NORM_L1,virtMatrix[0]);
|
sts = hppiSobel(accel,src, HPP_MASK_SIZE_3X3,HPP_NORM_L1,virtMatrix[0]);
|
||||||
CHECK_STATUS(sts,"hppiSobel");
|
CHECK_STATUS(sts,"hppiSobel");
|
||||||
@ -127,6 +133,13 @@ int main(int argc, const char** argv)
|
|||||||
imshow("rez", result);
|
imshow("rez", result);
|
||||||
|
|
||||||
waitKey(15);
|
waitKey(15);
|
||||||
|
|
||||||
|
sts = hppiFreeMatrix(src);
|
||||||
|
CHECK_DEL_STATUS(sts,"hppiFreeMatrix");
|
||||||
|
|
||||||
|
sts = hppiFreeMatrix(dst);
|
||||||
|
CHECK_DEL_STATUS(sts,"hppiFreeMatrix");
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!useCamera)
|
if (!useCamera)
|
||||||
@ -145,5 +158,12 @@ int main(int argc, const char** argv)
|
|||||||
}
|
}
|
||||||
|
|
||||||
printf("SUCCESS\n");
|
printf("SUCCESS\n");
|
||||||
return -1;
|
|
||||||
}
|
#else
|
||||||
|
|
||||||
|
printf("IPP Async not supported\n");
|
||||||
|
|
||||||
|
#endif
|
||||||
|
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user