From 9032a7ab8145c5907e2029fbb9319c7b5c2a376b Mon Sep 17 00:00:00 2001 From: Rostislav Vasilikhin Date: Thu, 17 Nov 2016 15:58:23 +0300 Subject: [PATCH] minor fixes in samples and ivx.hpp --- 3rdparty/openvx/include/ivx.hpp | 9 +++++++-- samples/openvx/no_wrappers.cpp | 16 ++++++---------- samples/openvx/wrappers.cpp | 20 ++++++++++---------- samples/openvx/wrappers_video.cpp | 29 ++++++++++++++--------------- 4 files changed, 37 insertions(+), 37 deletions(-) diff --git a/3rdparty/openvx/include/ivx.hpp b/3rdparty/openvx/include/ivx.hpp index c6602e4b99..eafac4c6dc 100644 --- a/3rdparty/openvx/include/ivx.hpp +++ b/3rdparty/openvx/include/ivx.hpp @@ -58,6 +58,11 @@ Details: TBD #ifndef IVX_USE_CXX98 #include + namespace ivx + { + using std::is_same; + using std::is_pointer; + } #else namespace ivx { @@ -1517,8 +1522,8 @@ static const vx_enum static Threshold createRange(vx_context c, vx_enum dataType, vx_int32 valLower, vx_int32 valUpper) { Threshold thr = create(c, VX_THRESHOLD_TYPE_RANGE, dataType); - IVX_CHECK_STATUS( vxSetThresholdAttribute(thr.ref, VX_THRESHOLD_THRESHOLD_LOWER, &val1, sizeof(val1)) ); - IVX_CHECK_STATUS( vxSetThresholdAttribute(thr.ref, VX_THRESHOLD_THRESHOLD_UPPER, &val2, sizeof(val2)) ); + IVX_CHECK_STATUS( vxSetThresholdAttribute(thr.ref, VX_THRESHOLD_THRESHOLD_LOWER, &valLower, sizeof(valLower)) ); + IVX_CHECK_STATUS( vxSetThresholdAttribute(thr.ref, VX_THRESHOLD_THRESHOLD_UPPER, &valUpper, sizeof(valUpper)) ); return thr; } diff --git a/samples/openvx/no_wrappers.cpp b/samples/openvx/no_wrappers.cpp index c15367a526..99a8ecab82 100644 --- a/samples/openvx/no_wrappers.cpp +++ b/samples/openvx/no_wrappers.cpp @@ -24,7 +24,7 @@ typedef uintptr_t vx_map_id; enum UserMemoryMode { - COPY, MAP_TO_VX + COPY, USER_MEM }; vx_image convertCvMatToVxImage(vx_context context, cv::Mat image, bool toCopy) @@ -89,11 +89,7 @@ vx_image convertCvMatToVxImage(vx_context context, cv::Mat image, bool toCopy) } else { -#ifdef VX_VERSION_1_1 - ovxImage = vxCreateImageFromHandle(context, color, &addr, (void*const*)&ovxData, VX_MEMORY_TYPE_HOST); -#else ovxImage = vxCreateImageFromHandle(context, color, &addr, (void**)&ovxData, VX_MEMORY_TYPE_HOST); -#endif if (vxGetStatus((vx_reference)ovxImage) != VX_SUCCESS) throw std::runtime_error("Failed to create image from handle"); } @@ -322,7 +318,7 @@ int ovxDemo(std::string inputPath, UserMemoryMode mode) cv::waitKey(0); //we need to take user memory back before releasing the image - if (mode == MAP_TO_VX) + if (mode == USER_MEM) swapVxImage(ovxImage); cv::destroyAllWindows(); @@ -339,7 +335,7 @@ int main(int argc, char *argv[]) "{image | | image to be processed}" "{mode | copy | user memory interaction mode: \n" "copy: create VX images and copy data to/from them\n" - "map_to_vx: use handles to user-allocated memory}" + "user_mem: use handles to user-allocated memory}" ; cv::CommandLineParser parser(argc, argv, keys); @@ -357,11 +353,11 @@ int main(int argc, char *argv[]) { mode = COPY; } - else if(modeString == "map_to_vx") + else if(modeString == "user_mem") { - mode = MAP_TO_VX; + mode = USER_MEM; } - else if(modeString == "map_from_vx") + else if(modeString == "map") { std::cerr << modeString << " is not implemented in this sample" << std::endl; return -1; diff --git a/samples/openvx/wrappers.cpp b/samples/openvx/wrappers.cpp index 5dd7da17c7..6655d3fd24 100644 --- a/samples/openvx/wrappers.cpp +++ b/samples/openvx/wrappers.cpp @@ -12,7 +12,7 @@ enum UserMemoryMode { - COPY, MAP_TO_VX, MAP_FROM_VX + COPY, USER_MEM, MAP }; ivx::Graph createProcessingGraph(ivx::Image& inputImage, ivx::Image& outputImage) @@ -91,7 +91,7 @@ int ovxDemo(std::string inputPath, UserMemoryMode mode) Image ivxResult; Image::Patch resultPatch; Mat output; - if (mode == COPY || mode == MAP_FROM_VX) + if (mode == COPY || mode == MAP) { //we will copy or map data from vx_image to cv::Mat ivxResult = ivx::Image::create(context, width, height, VX_DF_IMAGE_U8); @@ -116,7 +116,7 @@ int ovxDemo(std::string inputPath, UserMemoryMode mode) { ivxResult.copyTo(0, output); } - else if (mode == MAP_FROM_VX) + else if (mode == MAP) { //create cv::Mat based on vx_image mapped data resultPatch.map(ivxResult, 0, ivxResult.getValidRegion()); @@ -144,7 +144,7 @@ int ovxDemo(std::string inputPath, UserMemoryMode mode) //we should take user memory back before release //(it's not done automatically according to standard) ivxImage.swapHandle(); - if (mode == MAP_TO_VX) ivxResult.swapHandle(); + if (mode == USER_MEM) ivxResult.swapHandle(); } #endif @@ -173,8 +173,8 @@ int main(int argc, char *argv[]) "{image | | image to be processed}" "{mode | copy | user memory interaction mode: \n" "copy: create VX images and copy data to/from them\n" - "map_to_vx: use handles to user-allocated memory\n" - "map_from_vx: map resulting VX image to user memory}" + "user_mem: use handles to user-allocated memory\n" + "map: map resulting VX image to user memory}" ; cv::CommandLineParser parser(argc, argv, keys); @@ -192,13 +192,13 @@ int main(int argc, char *argv[]) { mode = COPY; } - else if(modeString == "map_to_vx") + else if(modeString == "user_mem") { - mode = MAP_TO_VX; + mode = USER_MEM; } - else if(modeString == "map_from_vx") + else if(modeString == "map") { - mode = MAP_FROM_VX; + mode = MAP; } else { diff --git a/samples/openvx/wrappers_video.cpp b/samples/openvx/wrappers_video.cpp index df7be472db..c24d8ceedb 100644 --- a/samples/openvx/wrappers_video.cpp +++ b/samples/openvx/wrappers_video.cpp @@ -12,7 +12,7 @@ enum UserMemoryMode { - COPY, MAP_TO_VX, MAP_FROM_VX + COPY, USER_MEM, MAP }; ivx::Graph createProcessingGraph(ivx::Image& inputImage, ivx::Image& outputImage) @@ -100,7 +100,7 @@ int ovxDemo(std::string inputPath, UserMemoryMode mode) Image ivxResult; Mat output; - if (mode == COPY || mode == MAP_FROM_VX) + if (mode == COPY || mode == MAP) { //we will copy or map data from vx_image to cv::Mat ivxResult = ivx::Image::create(context, width, height, VX_DF_IMAGE_U8); @@ -117,8 +117,6 @@ int ovxDemo(std::string inputPath, UserMemoryMode mode) Graph graph = createProcessingGraph(ivxImage, ivxResult); - std::vector ptrs; - bool stop = false; while (!stop) { @@ -129,12 +127,13 @@ int ovxDemo(std::string inputPath, UserMemoryMode mode) //getting resulting image in cv::Mat Image::Patch resultPatch; - std::vector prevPtrs; + std::vector ptrs; + std::vector prevPtrs(ivxResult.planes()); if (mode == COPY) { ivxResult.copyTo(0, output); } - else if (mode == MAP_FROM_VX) + else if (mode == MAP) { //create cv::Mat based on vx_image mapped data resultPatch.map(ivxResult, 0, ivxResult.getValidRegion(), VX_READ_AND_WRITE); @@ -156,9 +155,9 @@ int ovxDemo(std::string inputPath, UserMemoryMode mode) #ifdef VX_VERSION_1_1 //restore handle - if (mode == MAP_TO_VX) + if (mode == USER_MEM) { - ivxResult.swapHandle(prevPtrs); + ivxResult.swapHandle(prevPtrs, ptrs); } #endif @@ -184,7 +183,7 @@ int ovxDemo(std::string inputPath, UserMemoryMode mode) //we should take user memory back before release //(it's not done automatically according to standard) ivxImage.swapHandle(); - if (mode == MAP_TO_VX) ivxResult.swapHandle(); + if (mode == USER_MEM) ivxResult.swapHandle(); } #endif } @@ -210,8 +209,8 @@ int main(int argc, char *argv[]) "{video | | video file to be processed}" "{mode | copy | user memory interaction mode: \n" "copy: create VX images and copy data to/from them\n" - "map_to_vx: use handles to user-allocated memory\n" - "map_from_vx: map resulting VX image to user memory}" + "user_mem: use handles to user-allocated memory\n" + "map: map resulting VX image to user memory}" ; cv::CommandLineParser parser(argc, argv, keys); @@ -229,13 +228,13 @@ int main(int argc, char *argv[]) { mode = COPY; } - else if(modeString == "map_to_vx") + else if(modeString == "user_mem") { - mode = MAP_TO_VX; + mode = USER_MEM; } - else if(modeString == "map_from_vx") + else if(modeString == "map") { - mode = MAP_FROM_VX; + mode = MAP; } else {