mirror of https://github.com/opencv/opencv.git
Merge pull request #2538 from ElenaGvozdeva:ipp_async_convert
commit
9ec823d800
15 changed files with 784 additions and 2 deletions
@ -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) |
@ -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 |
After Width: | Height: | Size: 61 KiB |
After Width: | Height: | Size: 6.8 KiB |
@ -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…
Reference in new issue