Commit 9032a7ab authored by Rostislav Vasilikhin's avatar Rostislav Vasilikhin

minor fixes in samples and ivx.hpp

parent 5c969d19
...@@ -58,6 +58,11 @@ Details: TBD ...@@ -58,6 +58,11 @@ Details: TBD
#ifndef IVX_USE_CXX98 #ifndef IVX_USE_CXX98
#include <type_traits> #include <type_traits>
namespace ivx
{
using std::is_same;
using std::is_pointer;
}
#else #else
namespace ivx namespace ivx
{ {
...@@ -1517,8 +1522,8 @@ static const vx_enum ...@@ -1517,8 +1522,8 @@ static const vx_enum
static Threshold createRange(vx_context c, vx_enum dataType, vx_int32 valLower, vx_int32 valUpper) static Threshold createRange(vx_context c, vx_enum dataType, vx_int32 valLower, vx_int32 valUpper)
{ {
Threshold thr = create(c, VX_THRESHOLD_TYPE_RANGE, dataType); 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_LOWER, &valLower, sizeof(valLower)) );
IVX_CHECK_STATUS( vxSetThresholdAttribute(thr.ref, VX_THRESHOLD_THRESHOLD_UPPER, &val2, sizeof(val2)) ); IVX_CHECK_STATUS( vxSetThresholdAttribute(thr.ref, VX_THRESHOLD_THRESHOLD_UPPER, &valUpper, sizeof(valUpper)) );
return thr; return thr;
} }
......
...@@ -24,7 +24,7 @@ typedef uintptr_t vx_map_id; ...@@ -24,7 +24,7 @@ typedef uintptr_t vx_map_id;
enum UserMemoryMode enum UserMemoryMode
{ {
COPY, MAP_TO_VX COPY, USER_MEM
}; };
vx_image convertCvMatToVxImage(vx_context context, cv::Mat image, bool toCopy) 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) ...@@ -89,11 +89,7 @@ vx_image convertCvMatToVxImage(vx_context context, cv::Mat image, bool toCopy)
} }
else 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); ovxImage = vxCreateImageFromHandle(context, color, &addr, (void**)&ovxData, VX_MEMORY_TYPE_HOST);
#endif
if (vxGetStatus((vx_reference)ovxImage) != VX_SUCCESS) if (vxGetStatus((vx_reference)ovxImage) != VX_SUCCESS)
throw std::runtime_error("Failed to create image from handle"); throw std::runtime_error("Failed to create image from handle");
} }
...@@ -322,7 +318,7 @@ int ovxDemo(std::string inputPath, UserMemoryMode mode) ...@@ -322,7 +318,7 @@ int ovxDemo(std::string inputPath, UserMemoryMode mode)
cv::waitKey(0); cv::waitKey(0);
//we need to take user memory back before releasing the image //we need to take user memory back before releasing the image
if (mode == MAP_TO_VX) if (mode == USER_MEM)
swapVxImage(ovxImage); swapVxImage(ovxImage);
cv::destroyAllWindows(); cv::destroyAllWindows();
...@@ -339,7 +335,7 @@ int main(int argc, char *argv[]) ...@@ -339,7 +335,7 @@ int main(int argc, char *argv[])
"{image | <none> | image to be processed}" "{image | <none> | image to be processed}"
"{mode | copy | user memory interaction mode: \n" "{mode | copy | user memory interaction mode: \n"
"copy: create VX images and copy data to/from them\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); cv::CommandLineParser parser(argc, argv, keys);
...@@ -357,11 +353,11 @@ int main(int argc, char *argv[]) ...@@ -357,11 +353,11 @@ int main(int argc, char *argv[])
{ {
mode = COPY; 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; std::cerr << modeString << " is not implemented in this sample" << std::endl;
return -1; return -1;
......
...@@ -12,7 +12,7 @@ ...@@ -12,7 +12,7 @@
enum UserMemoryMode enum UserMemoryMode
{ {
COPY, MAP_TO_VX, MAP_FROM_VX COPY, USER_MEM, MAP
}; };
ivx::Graph createProcessingGraph(ivx::Image& inputImage, ivx::Image& outputImage) ivx::Graph createProcessingGraph(ivx::Image& inputImage, ivx::Image& outputImage)
...@@ -91,7 +91,7 @@ int ovxDemo(std::string inputPath, UserMemoryMode mode) ...@@ -91,7 +91,7 @@ int ovxDemo(std::string inputPath, UserMemoryMode mode)
Image ivxResult; Image ivxResult;
Image::Patch resultPatch; Image::Patch resultPatch;
Mat output; 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 //we will copy or map data from vx_image to cv::Mat
ivxResult = ivx::Image::create(context, width, height, VX_DF_IMAGE_U8); ivxResult = ivx::Image::create(context, width, height, VX_DF_IMAGE_U8);
...@@ -116,7 +116,7 @@ int ovxDemo(std::string inputPath, UserMemoryMode mode) ...@@ -116,7 +116,7 @@ int ovxDemo(std::string inputPath, UserMemoryMode mode)
{ {
ivxResult.copyTo(0, output); ivxResult.copyTo(0, output);
} }
else if (mode == MAP_FROM_VX) else if (mode == MAP)
{ {
//create cv::Mat based on vx_image mapped data //create cv::Mat based on vx_image mapped data
resultPatch.map(ivxResult, 0, ivxResult.getValidRegion()); resultPatch.map(ivxResult, 0, ivxResult.getValidRegion());
...@@ -144,7 +144,7 @@ int ovxDemo(std::string inputPath, UserMemoryMode mode) ...@@ -144,7 +144,7 @@ int ovxDemo(std::string inputPath, UserMemoryMode mode)
//we should take user memory back before release //we should take user memory back before release
//(it's not done automatically according to standard) //(it's not done automatically according to standard)
ivxImage.swapHandle(); ivxImage.swapHandle();
if (mode == MAP_TO_VX) ivxResult.swapHandle(); if (mode == USER_MEM) ivxResult.swapHandle();
} }
#endif #endif
...@@ -173,8 +173,8 @@ int main(int argc, char *argv[]) ...@@ -173,8 +173,8 @@ int main(int argc, char *argv[])
"{image | <none> | image to be processed}" "{image | <none> | image to be processed}"
"{mode | copy | user memory interaction mode: \n" "{mode | copy | user memory interaction mode: \n"
"copy: create VX images and copy data to/from them\n" "copy: create VX images and copy data to/from them\n"
"map_to_vx: use handles to user-allocated memory\n" "user_mem: use handles to user-allocated memory\n"
"map_from_vx: map resulting VX image to user memory}" "map: map resulting VX image to user memory}"
; ;
cv::CommandLineParser parser(argc, argv, keys); cv::CommandLineParser parser(argc, argv, keys);
...@@ -192,13 +192,13 @@ int main(int argc, char *argv[]) ...@@ -192,13 +192,13 @@ int main(int argc, char *argv[])
{ {
mode = COPY; 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 else
{ {
......
...@@ -12,7 +12,7 @@ ...@@ -12,7 +12,7 @@
enum UserMemoryMode enum UserMemoryMode
{ {
COPY, MAP_TO_VX, MAP_FROM_VX COPY, USER_MEM, MAP
}; };
ivx::Graph createProcessingGraph(ivx::Image& inputImage, ivx::Image& outputImage) ivx::Graph createProcessingGraph(ivx::Image& inputImage, ivx::Image& outputImage)
...@@ -100,7 +100,7 @@ int ovxDemo(std::string inputPath, UserMemoryMode mode) ...@@ -100,7 +100,7 @@ int ovxDemo(std::string inputPath, UserMemoryMode mode)
Image ivxResult; Image ivxResult;
Mat output; 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 //we will copy or map data from vx_image to cv::Mat
ivxResult = ivx::Image::create(context, width, height, VX_DF_IMAGE_U8); ivxResult = ivx::Image::create(context, width, height, VX_DF_IMAGE_U8);
...@@ -117,8 +117,6 @@ int ovxDemo(std::string inputPath, UserMemoryMode mode) ...@@ -117,8 +117,6 @@ int ovxDemo(std::string inputPath, UserMemoryMode mode)
Graph graph = createProcessingGraph(ivxImage, ivxResult); Graph graph = createProcessingGraph(ivxImage, ivxResult);
std::vector<void*> ptrs;
bool stop = false; bool stop = false;
while (!stop) while (!stop)
{ {
...@@ -129,12 +127,13 @@ int ovxDemo(std::string inputPath, UserMemoryMode mode) ...@@ -129,12 +127,13 @@ int ovxDemo(std::string inputPath, UserMemoryMode mode)
//getting resulting image in cv::Mat //getting resulting image in cv::Mat
Image::Patch resultPatch; Image::Patch resultPatch;
std::vector<void*> prevPtrs; std::vector<void*> ptrs;
std::vector<void*> prevPtrs(ivxResult.planes());
if (mode == COPY) if (mode == COPY)
{ {
ivxResult.copyTo(0, output); ivxResult.copyTo(0, output);
} }
else if (mode == MAP_FROM_VX) else if (mode == MAP)
{ {
//create cv::Mat based on vx_image mapped data //create cv::Mat based on vx_image mapped data
resultPatch.map(ivxResult, 0, ivxResult.getValidRegion(), VX_READ_AND_WRITE); resultPatch.map(ivxResult, 0, ivxResult.getValidRegion(), VX_READ_AND_WRITE);
...@@ -156,9 +155,9 @@ int ovxDemo(std::string inputPath, UserMemoryMode mode) ...@@ -156,9 +155,9 @@ int ovxDemo(std::string inputPath, UserMemoryMode mode)
#ifdef VX_VERSION_1_1 #ifdef VX_VERSION_1_1
//restore handle //restore handle
if (mode == MAP_TO_VX) if (mode == USER_MEM)
{ {
ivxResult.swapHandle(prevPtrs); ivxResult.swapHandle(prevPtrs, ptrs);
} }
#endif #endif
...@@ -184,7 +183,7 @@ int ovxDemo(std::string inputPath, UserMemoryMode mode) ...@@ -184,7 +183,7 @@ int ovxDemo(std::string inputPath, UserMemoryMode mode)
//we should take user memory back before release //we should take user memory back before release
//(it's not done automatically according to standard) //(it's not done automatically according to standard)
ivxImage.swapHandle(); ivxImage.swapHandle();
if (mode == MAP_TO_VX) ivxResult.swapHandle(); if (mode == USER_MEM) ivxResult.swapHandle();
} }
#endif #endif
} }
...@@ -210,8 +209,8 @@ int main(int argc, char *argv[]) ...@@ -210,8 +209,8 @@ int main(int argc, char *argv[])
"{video | <none> | video file to be processed}" "{video | <none> | video file to be processed}"
"{mode | copy | user memory interaction mode: \n" "{mode | copy | user memory interaction mode: \n"
"copy: create VX images and copy data to/from them\n" "copy: create VX images and copy data to/from them\n"
"map_to_vx: use handles to user-allocated memory\n" "user_mem: use handles to user-allocated memory\n"
"map_from_vx: map resulting VX image to user memory}" "map: map resulting VX image to user memory}"
; ;
cv::CommandLineParser parser(argc, argv, keys); cv::CommandLineParser parser(argc, argv, keys);
...@@ -229,13 +228,13 @@ int main(int argc, char *argv[]) ...@@ -229,13 +228,13 @@ int main(int argc, char *argv[])
{ {
mode = COPY; 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 else
{ {
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment