1 .. _howToUseIPPAconversion:
3 Intel® IPP Asynchronous C/C++ library in OpenCV
4 ***********************************************
9 .. _hppiSobel: http://software.intel.com/en-us/node/474701
10 .. _hppiMatrix: http://software.intel.com/en-us/node/501660
12 The tutorial demonstrates the `Intel® IPP Asynchronous C/C++ <http://software.intel.com/en-us/intel-ipp-preview>`_ library usage with OpenCV.
13 The code example below illustrates implementation of the Sobel operation, accelerated with Intel® IPP Asynchronous C/C++ functions.
14 In this code example, :ippa_convert:`hpp::getMat <>` and :ippa_convert:`hpp::getHpp <>` functions are used for data conversion between hppiMatrix_ and ``Mat`` matrices.
19 You may also find the source code in the :file:`samples/cpp/tutorial_code/core/ippasync/ippasync_sample.cpp`
20 file of the OpenCV source library or :download:`download it from here
21 <../../../../samples/cpp/tutorial_code/core/ippasync/ippasync_sample.cpp>`.
23 .. literalinclude:: ../../../../samples/cpp/tutorial_code/core/ippasync/ippasync_sample.cpp
31 #. Create parameters for OpenCV:
36 Mat image, gray, result;
42 hppiMatrix* src,* dst;
44 hppAccelType accelType;
46 hppiVirtualMatrix * virtMatrix;
48 #. Load input image or video. How to open and read video stream you can see in the :ref:`videoInputPSNRMSSIM` tutorial.
54 printf("used camera\n");
59 printf("used image %s\n", file.c_str());
60 cap.open(file.c_str());
65 printf("can not open camera or video file\n");
69 #. Create accelerator instance using `hppCreateInstance <http://software.intel.com/en-us/node/501686>`_:
73 accelType = sAccel == "cpu" ? HPP_ACCEL_TYPE_CPU:
74 sAccel == "gpu" ? HPP_ACCEL_TYPE_GPU:
77 //Create accelerator instance
78 sts = hppCreateInstance(accelType, 0, &accel);
79 CHECK_STATUS(sts, "hppCreateInstance");
81 #. Create an array of virtual matrices using `hppiCreateVirtualMatrices <http://software.intel.com/en-us/node/501700>`_ function.
85 virtMatrix = hppiCreateVirtualMatrices(accel, 1);
87 #. Prepare a matrix for input and output data:
95 cvtColor( image, gray, COLOR_BGR2GRAY );
97 result.create( image.rows, image.cols, CV_8U);
99 #. Convert ``Mat`` to hppiMatrix_ using :ippa_convert:`getHpp <>` and call hppiSobel_ function.
103 //convert Mat to hppiMatrix
104 src = getHpp(gray, accel);
105 dst = getHpp(result, accel);
107 sts = hppiSobel(accel,src, HPP_MASK_SIZE_3X3,HPP_NORM_L1,virtMatrix[0]);
108 CHECK_STATUS(sts,"hppiSobel");
110 sts = hppiConvert(accel, virtMatrix[0], 0, HPP_RND_MODE_NEAR, dst, HPP_DATA_TYPE_8U);
111 CHECK_STATUS(sts,"hppiConvert");
113 // Wait for tasks to complete
114 sts = hppWait(accel, HPP_TIME_OUT_INFINITE);
115 CHECK_STATUS(sts, "hppWait");
117 We use `hppiConvert <http://software.intel.com/en-us/node/501746>`_ because hppiSobel_ returns destination
118 matrix with ``HPP_DATA_TYPE_16S`` data type for source matrix with ``HPP_DATA_TYPE_8U`` type.
119 You should check ``hppStatus`` after each call IPP Async function.
121 #. Create windows and show the images, the usual way.
125 imshow("image", image);
126 imshow("rez", result);
130 #. Delete hpp matrices.
134 sts = hppiFreeMatrix(src);
135 CHECK_DEL_STATUS(sts,"hppiFreeMatrix");
137 sts = hppiFreeMatrix(dst);
138 CHECK_DEL_STATUS(sts,"hppiFreeMatrix");
140 #. Delete virtual matrices and accelerator instance.
146 sts = hppiDeleteVirtualMatrices(accel, virtMatrix);
147 CHECK_DEL_STATUS(sts,"hppiDeleteVirtualMatrices");
152 sts = hppDeleteInstance(accel);
153 CHECK_DEL_STATUS(sts, "hppDeleteInstance");
159 After compiling the code above we can execute it giving an image or video path and accelerator type as an argument.
160 For this tutorial we use baboon.png image as input. The result is below.
162 .. image:: images/How_To_Use_IPPA_Result.jpg