Merge pull request #2538 from ElenaGvozdeva:ipp_async_convert

pull/2582/merge
Andrey Pavlenko 11 years ago committed by OpenCV Buildbot
commit 9ec823d800
  1. 6
      CMakeLists.txt
  2. 45
      cmake/OpenCVFindIPPAsync.cmake
  3. 11
      cmake/OpenCVFindLibsPerf.cmake
  4. 3
      cmake/templates/cvconfig.h.in
  5. 4
      doc/conf.py
  6. 164
      doc/tutorials/core/how_to_use_ippa_conversion/how_to_use_ippa_conversion.rst
  7. BIN
      doc/tutorials/core/how_to_use_ippa_conversion/images/How_To_Use_IPPA_Result.jpg
  8. BIN
      doc/tutorials/core/table_of_content_core/images/How_To_Use_IPPA.jpg
  9. 22
      doc/tutorials/core/table_of_content_core/table_of_content_core.rst
  10. 6
      doc/tutorials/introduction/windows_install/windows_install.rst
  11. 1
      modules/core/doc/core.rst
  12. 72
      modules/core/doc/ipp_async_converters.rst
  13. 105
      modules/core/include/opencv2/core/ippasync.hpp
  14. 179
      modules/core/test/test_ippasync.cpp
  15. 168
      samples/cpp/tutorial_code/core/ippasync/ippasync_sample.cpp

@ -158,7 +158,7 @@ OCV_OPTION(WITH_OPENCLAMDFFT "Include AMD OpenCL FFT library support" ON
OCV_OPTION(WITH_OPENCLAMDBLAS "Include AMD OpenCL BLAS library support" ON IF (NOT ANDROID AND NOT IOS) )
OCV_OPTION(WITH_DIRECTX "Include DirectX support" ON IF WIN32 )
OCV_OPTION(WITH_INTELPERC "Include Intel Perceptual Computing support" OFF IF WIN32 )
OCV_OPTION(WITH_IPP_A "Include Intel IPP_A support" OFF IF (MSVC OR X86 OR X86_64) )
# OpenCV build components
# ===================================================
@ -924,6 +924,10 @@ else()
status(" Use IPP:" (WITH_IPP OR WITH_ICV) AND NOT HAVE_IPP THEN "IPP not found" ELSE NO)
endif()
if(DEFINED WITH_IPP_A)
status(" Use IPP Async:" HAVE_IPP_A THEN "YES" ELSE NO)
endif(DEFINED WITH_IPP_A)
status(" Use Eigen:" HAVE_EIGEN THEN "YES (ver ${EIGEN_WORLD_VERSION}.${EIGEN_MAJOR_VERSION}.${EIGEN_MINOR_VERSION})" ELSE NO)
status(" Use TBB:" HAVE_TBB THEN "YES (ver ${TBB_VERSION_MAJOR}.${TBB_VERSION_MINOR} interface ${TBB_INTERFACE_VERSION})" ELSE NO)
status(" Use OpenMP:" HAVE_OPENMP THEN YES ELSE NO)

@ -0,0 +1,45 @@
# Main variables:
# IPP_A_LIBRARIES and IPP_A_INCLUDE to use IPP Async
# HAVE_IPP_A for conditional compilation OpenCV with/without IPP Async
# IPP_ASYNC_ROOT - root of IPP Async installation
if(X86_64)
find_path(
IPP_A_INCLUDE_DIR
NAMES ipp_async_defs.h
PATHS $ENV{IPP_ASYNC_ROOT}
PATH_SUFFIXES include
DOC "Path to Intel IPP Async interface headers")
find_file(
IPP_A_LIBRARIES
NAMES ipp_async_preview.lib
PATHS $ENV{IPP_ASYNC_ROOT}
PATH_SUFFIXES lib/intel64
DOC "Path to Intel IPP Async interface libraries")
else()
find_path(
IPP_A_INCLUDE_DIR
NAMES ipp_async_defs.h
PATHS $ENV{IPP_ASYNC_ROOT}
PATH_SUFFIXES include
DOC "Path to Intel IPP Async interface headers")
find_file(
IPP_A_LIBRARIES
NAMES ipp_async_preview.lib
PATHS $ENV{IPP_ASYNC_ROOT}
PATH_SUFFIXES lib/ia32
DOC "Path to Intel IPP Async interface libraries")
endif()
if(IPP_A_INCLUDE_DIR AND IPP_A_LIBRARIES)
set(HAVE_IPP_A TRUE)
else()
set(HAVE_IPP_A FALSE)
message(WARNING "Intel IPP Async library directory (set by IPP_A_LIBRARIES_DIR variable) is not found or does not have Intel IPP Async libraries.")
endif()
mark_as_advanced(FORCE IPP_A_LIBRARIES IPP_A_INCLUDE_DIR)

@ -16,6 +16,17 @@ if(WITH_IPP OR WITH_ICV)
endif()
endif()
# --- IPP Async ---
if(WITH_IPP_A)
include("${OpenCV_SOURCE_DIR}/cmake/OpenCVFindIPPAsync.cmake")
if(IPP_A_INCLUDE_DIR AND IPP_A_LIBRARIES)
ocv_include_directories(${IPP_A_INCLUDE_DIR})
link_directories(${IPP_A_LIBRARIES})
set(OPENCV_LINKER_LIBS ${OPENCV_LINKER_LIBS} ${IPP_A_LIBRARIES})
endif()
endif(WITH_IPP_A)
# --- CUDA ---
if(WITH_CUDA)
include("${OpenCV_SOURCE_DIR}/cmake/OpenCVDetectCUDA.cmake")

@ -95,6 +95,9 @@
#cmakedefine HAVE_IPP
#cmakedefine HAVE_IPP_ICV_ONLY
/* Intel IPP Async */
#cmakedefine HAVE_IPP_A
/* JPEG-2000 codec */
#cmakedefine HAVE_JASPER

@ -418,5 +418,7 @@ extlinks = {
'background_subtractor' : ('http://docs.opencv.org/modules/video/doc/motion_analysis_and_object_tracking.html?highlight=backgroundsubtractor#backgroundsubtractor%s', None),
'background_subtractor_mog' : ('http://docs.opencv.org/modules/video/doc/motion_analysis_and_object_tracking.html?highlight=backgroundsubtractorMOG#backgroundsubtractormog%s', None),
'background_subtractor_mog_two' : ('http://docs.opencv.org/modules/video/doc/motion_analysis_and_object_tracking.html?highlight=backgroundsubtractorMOG2#backgroundsubtractormog2%s', None),
'video_capture' : ('http://docs.opencv.org/modules/highgui/doc/reading_and_writing_images_and_video.html?highlight=videocapture#videocapture%s', None)
'video_capture' : ('http://docs.opencv.org/modules/highgui/doc/reading_and_writing_images_and_video.html?highlight=videocapture#videocapture%s', None),
'ippa_convert': ('http://docs.opencv.org/modules/core/doc/ipp_async_converters.html#%s', None),
'ptr':('http://docs.opencv.org/modules/core/doc/basic_structures.html?highlight=Ptr#Ptr%s', None)
}

@ -0,0 +1,164 @@
.. _howToUseIPPAconversion:
Intel® IPP Asynchronous C/C++ library in OpenCV
***********************************************
Goal
====
.. _hppiSobel: http://software.intel.com/en-us/node/474701
.. _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 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.
Code
====
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
<../../../../samples/cpp/tutorial_code/core/ippasync/ippasync_sample.cpp>`.
.. literalinclude:: ../../../../samples/cpp/tutorial_code/core/ippasync/ippasync_sample.cpp
:language: cpp
:linenos:
:tab-width: 4
Explanation
===========
#. Create parameters for OpenCV:
.. code-block:: cpp
VideoCapture cap;
Mat image, gray, result;
and IPP Async:
.. code-block:: cpp
hppiMatrix* src,* dst;
hppAccel accel = 0;
hppAccelType accelType;
hppStatus sts;
hppiVirtualMatrix * virtMatrix;
#. Load input image or video. How to open and read video stream you can see in the :ref:`videoInputPSNRMSSIM` tutorial.
.. code-block:: cpp
if( useCamera )
{
printf("used camera\n");
cap.open(0);
}
else
{
printf("used image %s\n", file.c_str());
cap.open(file.c_str());
}
if( !cap.isOpened() )
{
printf("can not open camera or video file\n");
return -1;
}
#. Create accelerator instance using `hppCreateInstance <http://software.intel.com/en-us/node/501686>`_:
.. code-block:: cpp
accelType = sAccel == "cpu" ? HPP_ACCEL_TYPE_CPU:
sAccel == "gpu" ? HPP_ACCEL_TYPE_GPU:
HPP_ACCEL_TYPE_ANY;
//Create accelerator instance
sts = hppCreateInstance(accelType, 0, &accel);
CHECK_STATUS(sts, "hppCreateInstance");
#. Create an array of virtual matrices using `hppiCreateVirtualMatrices <http://software.intel.com/en-us/node/501700>`_ function.
.. code-block:: cpp
virtMatrix = hppiCreateVirtualMatrices(accel, 1);
#. Prepare a matrix for input and output data:
.. code-block:: cpp
cap >> image;
if(image.empty())
break;
cvtColor( image, gray, COLOR_BGR2GRAY );
result.create( image.rows, image.cols, CV_8U);
#. Convert ``Mat`` to hppiMatrix_ using :ippa_convert:`getHpp <>` and call hppiSobel_ function.
.. code-block:: cpp
//convert Mat to hppiMatrix
src = getHpp(gray, accel);
dst = getHpp(result, accel);
sts = hppiSobel(accel,src, HPP_MASK_SIZE_3X3,HPP_NORM_L1,virtMatrix[0]);
CHECK_STATUS(sts,"hppiSobel");
sts = hppiConvert(accel, virtMatrix[0], 0, HPP_RND_MODE_NEAR, dst, HPP_DATA_TYPE_8U);
CHECK_STATUS(sts,"hppiConvert");
// Wait for tasks to complete
sts = hppWait(accel, HPP_TIME_OUT_INFINITE);
CHECK_STATUS(sts, "hppWait");
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.
You should check ``hppStatus`` after each call IPP Async function.
#. Create windows and show the images, the usual way.
.. code-block:: cpp
imshow("image", image);
imshow("rez", result);
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.
.. code-block:: cpp
if (virtMatrix)
{
sts = hppiDeleteVirtualMatrices(accel, virtMatrix);
CHECK_DEL_STATUS(sts,"hppiDeleteVirtualMatrices");
}
if (accel)
{
sts = hppDeleteInstance(accel);
CHECK_DEL_STATUS(sts, "hppDeleteInstance");
}
Result
=======
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.
.. image:: images/How_To_Use_IPPA_Result.jpg
:alt: Final Result
:align: center

Binary file not shown.

After

Width:  |  Height:  |  Size: 61 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 6.8 KiB

@ -200,7 +200,28 @@ Here you will learn the about the basic building blocks of the library. A must r
:height: 90pt
:width: 90pt
=============== ======================================================
+
.. tabularcolumns:: m{100pt} m{300pt}
.. cssclass:: toctableopencv
=============== ======================================================
|IPPIma| **Title:** :ref:`howToUseIPPAconversion`
*Compatibility:* > OpenCV 2.0
*Author:* |Author_ElenaG|
You will see how to use the IPP Async with OpenCV.
=============== ======================================================
.. |IPPIma| image:: images/How_To_Use_IPPA.jpg
:height: 90pt
:width: 90pt
.. |Author_ElenaG| unicode:: Elena U+0020 Gvozdeva
=============== ======================================================
.. raw:: latex
@ -219,3 +240,4 @@ Here you will learn the about the basic building blocks of the library. A must r
../discrete_fourier_transform/discrete_fourier_transform
../file_input_output_with_xml_yml/file_input_output_with_xml_yml
../interoperability_with_OpenCV_1/interoperability_with_OpenCV_1
../how_to_use_ippa_conversion/how_to_use_ippa_conversion

@ -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
.. |IntelIIP| replace:: Intel |copy| Integrated Performance Primitives (*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: http://qt.nokia.com/downloads
.. |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.
+ |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.
+ |Eigen|_ is a C++ template library for linear algebra.
@ -168,6 +172,8 @@ Building the library
:alt: The Miktex Install Screen
: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.
#) Same as above with |OpenEXR|_.

@ -16,3 +16,4 @@ core. The Core Functionality
clustering
utility_and_system_functions_and_macros
opengl_interop
ipp_async_converters

@ -0,0 +1,72 @@
Intel® IPP Asynchronous C/C++ Converters
========================================
.. highlight:: cpp
General Information
-------------------
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.
hpp::getHpp
-----------
Create ``hppiMatrix`` from ``Mat``.
.. ocv:function:: hppiMatrix* hpp::getHpp(const Mat& src, hppAccel accel)
: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>`_.
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.
.. seealso:: :ref:`howToUseIPPAconversion`, :ocv:func:`hpp::getMat`
hpp::getMat
-----------
Create ``Mat`` from ``hppiMatrix``.
.. ocv:function:: Mat hpp::getMat(hppiMatrix* src, hppAccel accel, int cn)
:param src: input hppiMatrix.
:param accel: accelerator instance (see :ocv:func:`hpp::getHpp` for the list of acceleration framework types).
:param cn: number of channels.
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``.
.. seealso:: :ref:`howToUseIPPAconversion`, :ocv:func:`hpp::copyHppToMat`, :ocv:func:`hpp::getHpp`.
hpp::copyHppToMat
-----------------
Convert ``hppiMatrix`` to ``Mat``.
.. ocv:function:: void hpp::copyHppToMat(hppiMatrix* src, Mat& dst, hppAccel accel, int cn)
:param src: input hppiMatrix.
:param dst: output matrix.
:param accel: accelerator instance (see :ocv:func:`hpp::getHpp` for the list of acceleration framework types).
:param cn: number of channels.
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``.
.. seealso:: :ref:`howToUseIPPAconversion`, :ocv:func:`hpp::getMat`, :ocv:func:`hpp::getHpp`.

@ -0,0 +1,105 @@
#ifndef __OPENCV_CORE_IPPASYNC_HPP__
#define __OPENCV_CORE_IPPASYNC_HPP__
#ifdef HAVE_IPP_A
#include "opencv2/core.hpp"
#include <ipp_async_op.h>
#include <ipp_async_accel.h>
namespace cv
{
namespace hpp
{
//convert OpenCV data type to hppDataType
inline int toHppType(const int cvType)
{
int depth = CV_MAT_DEPTH(cvType);
int hppType = depth == CV_8U ? HPP_DATA_TYPE_8U :
depth == CV_16U ? HPP_DATA_TYPE_16U :
depth == CV_16S ? HPP_DATA_TYPE_16S :
depth == CV_32S ? HPP_DATA_TYPE_32S :
depth == CV_32F ? HPP_DATA_TYPE_32F :
depth == CV_64F ? HPP_DATA_TYPE_64F : -1;
CV_Assert( hppType >= 0 );
return hppType;
}
//convert hppDataType to OpenCV data type
inline int toCvType(const int hppType)
{
int cvType = hppType == HPP_DATA_TYPE_8U ? CV_8U :
hppType == HPP_DATA_TYPE_16U ? CV_16U :
hppType == HPP_DATA_TYPE_16S ? CV_16S :
hppType == HPP_DATA_TYPE_32S ? CV_32S :
hppType == HPP_DATA_TYPE_32F ? CV_32F :
hppType == HPP_DATA_TYPE_64F ? CV_64F : -1;
CV_Assert( cvType >= 0 );
return cvType;
}
inline void copyHppToMat(hppiMatrix* src, Mat& dst, hppAccel accel, int cn)
{
hppDataType type;
hpp32u width, height;
hppStatus sts;
if (src == NULL)
return dst.release();
sts = hppiInquireMatrix(src, &type, &width, &height);
CV_Assert( sts == HPP_STATUS_NO_ERROR);
int matType = CV_MAKETYPE(toCvType(type), cn);
CV_Assert(width%cn == 0);
width /= cn;
dst.create((int)height, (int)width, (int)matType);
size_t newSize = (size_t)(height*(hpp32u)(dst.step));
sts = hppiGetMatrixData(accel,src,(hpp32u)(dst.step),dst.data,&newSize);
CV_Assert( sts == HPP_STATUS_NO_ERROR);
}
//create cv::Mat from hppiMatrix
inline Mat getMat(hppiMatrix* src, hppAccel accel, int cn)
{
Mat dst;
copyHppToMat(src, dst, accel, cn);
return dst;
}
//create hppiMatrix from cv::Mat
inline hppiMatrix* getHpp(const Mat& src, hppAccel accel)
{
int htype = toHppType(src.type());
int cn = src.channels();
CV_Assert(src.data);
hppAccelType accelType = hppQueryAccelType(accel);
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

@ -0,0 +1,179 @@
#include "test_precomp.hpp"
#include "opencv2/ts/ocl_test.hpp"
#ifdef HAVE_IPP_A
#include "opencv2/core/ippasync.hpp"
using namespace cv;
using namespace std;
using namespace cvtest;
namespace cvtest {
namespace ocl {
PARAM_TEST_CASE(IPPAsync, MatDepth, Channels, hppAccelType)
{
int type;
int cn;
int depth;
hppAccelType accelType;
Mat matrix, result;
hppiMatrix * hppMat;
hppAccel accel;
hppiVirtualMatrix * virtMatrix;
hppStatus sts;
virtual void SetUp()
{
type = CV_MAKE_TYPE(GET_PARAM(0), GET_PARAM(1));
depth = GET_PARAM(0);
cn = GET_PARAM(1);
accelType = GET_PARAM(2);
}
virtual void generateTestData()
{
Size matrix_Size = randomSize(2, 100);
const double upValue = 100;
matrix = randomMat(matrix_Size, type, -upValue, upValue);
}
void Near(double threshold = 0.0)
{
EXPECT_MAT_NEAR(matrix, result, threshold);
}
};
TEST_P(IPPAsync, accuracy)
{
sts = hppCreateInstance(accelType, 0, &accel);
if (sts!=HPP_STATUS_NO_ERROR) printf("hppStatus = %d\n",sts);
CV_Assert(sts==HPP_STATUS_NO_ERROR);
virtMatrix = hppiCreateVirtualMatrices(accel, 2);
for (int j = 0; j < test_loop_times; j++)
{
generateTestData();
hppMat = hpp::getHpp(matrix,accel);
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);
sts = hppWait(accel, HPP_TIME_OUT_INFINITE);
CV_Assert(sts==HPP_STATUS_NO_ERROR);
result = hpp::getMat(virtMatrix[1], accel, cn);
Near(5.0e-6);
sts = hppiFreeMatrix(hppMat);
CV_Assert(sts==HPP_STATUS_NO_ERROR);
}
sts = hppiDeleteVirtualMatrices(accel, virtMatrix);
CV_Assert(sts==HPP_STATUS_NO_ERROR);
sts = hppDeleteInstance(accel);
CV_Assert(sts==HPP_STATUS_NO_ERROR);
}
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);
if (sts!=HPP_STATUS_NO_ERROR) printf("hppStatus = %d\n",sts);
CV_Assert(sts==HPP_STATUS_NO_ERROR);
virtMatrix = hppiCreateVirtualMatrices(accel, 2);
for (int j = 0; j < test_loop_times; j++)
{
generateTestData();
hppMat = hpp::getHpp(matrix,accel);
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);
sts = hppWait(accel, HPP_TIME_OUT_INFINITE);
CV_Assert(sts==HPP_STATUS_NO_ERROR);
result = hpp::getMat(virtMatrix[1], accel, cn);
Near(0);
sts = hppiFreeMatrix(hppMat);
CV_Assert(sts==HPP_STATUS_NO_ERROR);
}
sts = hppiDeleteVirtualMatrices(accel, virtMatrix);
CV_Assert(sts==HPP_STATUS_NO_ERROR);
sts = hppDeleteInstance(accel);
CV_Assert(sts==HPP_STATUS_NO_ERROR);
}
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( HPP_ACCEL_TYPE_CPU, HPP_ACCEL_TYPE_GPU)));
}
}
#endif

@ -0,0 +1,168 @@
#include <stdio.h>
#include "opencv2/core/utility.hpp"
#include "opencv2/imgproc.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)\
if(STATUS!=HPP_STATUS_NO_ERROR){ printf("%s error %d\n", NAME, STATUS);\
if (virtMatrix) {hppStatus delSts = hppiDeleteVirtualMatrices(accel, virtMatrix); CHECK_DEL_STATUS(delSts,"hppiDeleteVirtualMatrices");}\
if (accel) {hppStatus delSts = hppDeleteInstance(accel); CHECK_DEL_STATUS(delSts, "hppDeleteInstance");}\
return -1;}
#define CHECK_DEL_STATUS(STATUS, NAME)\
if(STATUS!=HPP_STATUS_NO_ERROR){ printf("%s error %d\n", NAME, STATUS); return -1;}
#endif
static void help()
{
printf("\nThis program shows how to use the conversion for IPP Async.\n"
"This example uses the Sobel filter.\n"
"You can use cv::Sobel or hppiSobel.\n"
"Usage: \n"
"./ipp_async_sobel [--camera]=<use camera,if this key is present>, \n"
" [--file_name]=<path to movie or image file>\n"
" [--accel]=<accelerator type: auto (default), cpu, gpu>\n\n");
}
const char* keys =
{
"{c camera | | use camera or not}"
"{fn file_name|baboon.jpg | image file }"
"{a accel |auto | accelerator type: auto (default), cpu, gpu}"
};
//this is a sample for hppiSobel functions
int main(int argc, const char** argv)
{
help();
VideoCapture cap;
CommandLineParser parser(argc, argv, keys);
Mat image, gray, result;
#ifdef HAVE_IPP_A
hppiMatrix* src,* dst;
hppAccel accel = 0;
hppAccelType accelType;
hppStatus sts;
hppiVirtualMatrix * virtMatrix;
bool useCamera = parser.has("camera");
string file = parser.get<string>("file_name");
string sAccel = parser.get<string>("accel");
parser.printMessage();
if( useCamera )
{
printf("used camera\n");
cap.open(0);
}
else
{
printf("used image %s\n", file.c_str());
cap.open(file.c_str());
}
if( !cap.isOpened() )
{
printf("can not open camera or video file\n");
return -1;
}
accelType = sAccel == "cpu" ? HPP_ACCEL_TYPE_CPU:
sAccel == "gpu" ? HPP_ACCEL_TYPE_GPU:
HPP_ACCEL_TYPE_ANY;
//Create accelerator instance
sts = hppCreateInstance(accelType, 0, &accel);
CHECK_STATUS(sts, "hppCreateInstance");
accelType = hppQueryAccelType(accel);
sAccel = accelType == HPP_ACCEL_TYPE_CPU ? "cpu":
accelType == HPP_ACCEL_TYPE_GPU ? "gpu":
accelType == HPP_ACCEL_TYPE_GPU_VIA_DX9 ? "gpu dx9": "?";
printf("accelType %s\n", sAccel.c_str());
virtMatrix = hppiCreateVirtualMatrices(accel, 1);
for(;;)
{
cap >> image;
if(image.empty())
break;
cvtColor( image, gray, COLOR_BGR2GRAY );
result.create( image.rows, image.cols, CV_8U);
double execTime = (double)getTickCount();
//convert Mat to hppiMatrix
src = hpp::getHpp(gray,accel);
dst = hpp::getHpp(result,accel);
sts = hppiSobel(accel,src, HPP_MASK_SIZE_3X3,HPP_NORM_L1,virtMatrix[0]);
CHECK_STATUS(sts,"hppiSobel");
sts = hppiConvert(accel, virtMatrix[0], 0, HPP_RND_MODE_NEAR, dst, HPP_DATA_TYPE_8U);
CHECK_STATUS(sts,"hppiConvert");
// Wait for tasks to complete
sts = hppWait(accel, HPP_TIME_OUT_INFINITE);
CHECK_STATUS(sts, "hppWait");
execTime = ((double)getTickCount() - execTime)*1000./getTickFrequency();
printf("Time : %0.3fms\n", execTime);
imshow("image", image);
imshow("rez", result);
waitKey(15);
sts = hppiFreeMatrix(src);
CHECK_DEL_STATUS(sts,"hppiFreeMatrix");
sts = hppiFreeMatrix(dst);
CHECK_DEL_STATUS(sts,"hppiFreeMatrix");
}
if (!useCamera)
waitKey(0);
if (virtMatrix)
{
sts = hppiDeleteVirtualMatrices(accel, virtMatrix);
CHECK_DEL_STATUS(sts,"hppiDeleteVirtualMatrices");
}
if (accel)
{
sts = hppDeleteInstance(accel);
CHECK_DEL_STATUS(sts, "hppDeleteInstance");
}
printf("SUCCESS\n");
#else
printf("IPP Async not supported\n");
#endif
return 0;
}
Loading…
Cancel
Save