14 #define CHECK_STATUS(STATUS, NAME)\
15 if(STATUS!=HPP_STATUS_NO_ERROR){ printf("%s error %d\n", NAME, STATUS);\
16 if (virtMatrix) {hppStatus delSts = hppiDeleteVirtualMatrices(accel, virtMatrix); CHECK_DEL_STATUS(delSts,"hppiDeleteVirtualMatrices");}\
17 if (accel) {hppStatus delSts = hppDeleteInstance(accel); CHECK_DEL_STATUS(delSts, "hppDeleteInstance");}\
20 #define CHECK_DEL_STATUS(STATUS, NAME)\
21 if(STATUS!=HPP_STATUS_NO_ERROR){ printf("%s error %d\n", NAME, STATUS); return -1;}
27 printf(
"\nThis program shows how to use the conversion for IPP Async.\n"
28 "This example uses the Sobel filter.\n"
29 "You can use cv::Sobel or hppiSobel.\n"
31 "./ipp_async_sobel [--camera]=<use camera,if this key is present>, \n"
32 " [--file_name]=<path to movie or image file>\n"
33 " [--accel]=<accelerator type: auto (default), cpu, gpu>\n\n");
38 "{c camera | | use camera or not}"
39 "{fn file_name|../data/baboon.jpg | image file }"
40 "{a accel |auto | accelerator type: auto (default), cpu, gpu}"
44 int main(
int argc,
const char** argv)
50 Mat image, gray, result;
54 hppiMatrix* src,* dst;
56 hppAccelType accelType;
58 hppiVirtualMatrix * virtMatrix;
60 bool useCamera = parser.has(
"camera");
61 string file = parser.get<
string>(
"file_name");
62 string sAccel = parser.get<
string>(
"accel");
64 parser.printMessage();
68 printf(
"used camera\n");
73 printf(
"used image %s\n", file.c_str());
74 cap.
open(file.c_str());
79 printf(
"can not open camera or video file\n");
83 accelType = sAccel ==
"cpu" ? HPP_ACCEL_TYPE_CPU:
84 sAccel ==
"gpu" ? HPP_ACCEL_TYPE_GPU:
88 sts = hppCreateInstance(accelType, 0, &accel);
89 CHECK_STATUS(sts,
"hppCreateInstance");
91 accelType = hppQueryAccelType(accel);
93 sAccel = accelType == HPP_ACCEL_TYPE_CPU ?
"cpu":
94 accelType == HPP_ACCEL_TYPE_GPU ?
"gpu":
95 accelType == HPP_ACCEL_TYPE_GPU_VIA_DX9 ?
"gpu dx9":
"?";
97 printf(
"accelType %s\n", sAccel.c_str());
99 virtMatrix = hppiCreateVirtualMatrices(accel, 1);
117 sts = hppiSobel(accel,src, HPP_MASK_SIZE_3X3,HPP_NORM_L1,virtMatrix[0]);
118 CHECK_STATUS(sts,
"hppiSobel");
120 sts = hppiConvert(accel, virtMatrix[0], 0, HPP_RND_MODE_NEAR, dst, HPP_DATA_TYPE_8U);
121 CHECK_STATUS(sts,
"hppiConvert");
124 sts = hppWait(accel, HPP_TIME_OUT_INFINITE);
125 CHECK_STATUS(sts,
"hppWait");
129 printf(
"Time : %0.3fms\n", execTime);
136 sts = hppiFreeMatrix(src);
137 CHECK_DEL_STATUS(sts,
"hppiFreeMatrix");
139 sts = hppiFreeMatrix(dst);
140 CHECK_DEL_STATUS(sts,
"hppiFreeMatrix");
149 sts = hppiDeleteVirtualMatrices(accel, virtMatrix);
150 CHECK_DEL_STATUS(sts,
"hppiDeleteVirtualMatrices");
155 sts = hppDeleteInstance(accel);
156 CHECK_DEL_STATUS(sts,
"hppDeleteInstance");
163 printf(
"IPP Async not supported\n");
hppiMatrix * getHpp(const Mat &src, hppAccel accel)
Create hppiMatrix from Mat.
Definition: ippasync.hpp:168
#define CV_8U
Definition: cvdef.h:101
void cvtColor(InputArray src, OutputArray dst, int code, int dstCn=0)
Converts an image from one color space to another.
virtual bool open(const String &filename)
Open video file or a capturing device for video capturing.
double getTickFrequency()
Returns the number of ticks per second.
void imshow(const String &winname, InputArray mat)
Displays an image in the specified window.
designed for command line arguments parsing
Definition: utility.hpp:594
Class for video capturing from video files, image sequences or cameras. The class provides C++ API fo...
Definition: videoio.hpp:429
virtual bool isOpened() const
Returns true if video capturing has been initialized already.
void create(int rows, int cols, int type)
Allocates new array data if needed.
int main(int argc, const char *argv[])
Definition: facerec_demo.cpp:67
int64 getTickCount()
Returns the number of ticks.
n-dimensional dense array class
Definition: mat.hpp:726
convert between RGB/BGR and grayscale, color conversions
Definition: imgproc.hpp:511
int waitKey(int delay=0)
Waits for a pressed key.
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.