From 00d96bcfe15c20e1339b0ab7c8cbad2e5645476e Mon Sep 17 00:00:00 2001 From: Rainer Kartmann <rainer.kartmann@kit.edu> Date: Wed, 1 Sep 2021 14:46:48 +0200 Subject: [PATCH] Add image to example data --- .../client/ExampleMemoryClient/CMakeLists.txt | 6 ++ .../ExampleMemoryClient.cpp | 57 +++++++++++++++++-- .../server/ExampleMemory/aron/ExampleData.xml | 7 +++ 3 files changed, 66 insertions(+), 4 deletions(-) diff --git a/source/RobotAPI/components/armem/client/ExampleMemoryClient/CMakeLists.txt b/source/RobotAPI/components/armem/client/ExampleMemoryClient/CMakeLists.txt index d699638cd..96cb0013a 100644 --- a/source/RobotAPI/components/armem/client/ExampleMemoryClient/CMakeLists.txt +++ b/source/RobotAPI/components/armem/client/ExampleMemoryClient/CMakeLists.txt @@ -3,11 +3,17 @@ armarx_component_set_name("ExampleMemoryClient") find_package(IVT QUIET) armarx_build_if(IVT_FOUND "IVT not available") +find_package(OpenCV QUIET) +armarx_build_if(OpenCV_FOUND "OpenCV not available") + + set(COMPONENT_LIBS ArmarXCore ArmarXCoreInterfaces # for DebugObserverInterface ArmarXGuiComponentPlugins RobotAPICore RobotAPIInterfaces armem + ${IVT_LIBRARIES} + ${OpenCV_LIBS} ) set(SOURCES diff --git a/source/RobotAPI/components/armem/client/ExampleMemoryClient/ExampleMemoryClient.cpp b/source/RobotAPI/components/armem/client/ExampleMemoryClient/ExampleMemoryClient.cpp index acf354925..2fc185edc 100644 --- a/source/RobotAPI/components/armem/client/ExampleMemoryClient/ExampleMemoryClient.cpp +++ b/source/RobotAPI/components/armem/client/ExampleMemoryClient/ExampleMemoryClient.cpp @@ -39,6 +39,9 @@ #include <RobotAPI/components/armem/server/ExampleMemory/aron/ExampleData.aron.generated.h> +#include <opencv2/imgcodecs.hpp> +#include <opencv2/imgproc.hpp> + namespace armarx { @@ -381,17 +384,17 @@ namespace armarx toAron(data.memoryLink, armem::MemoryID()); + simox::ColorMap cmap = simox::color::cmaps::plasma(); { data.the_ivt_image = std::make_shared<CByteImage>(); CByteImage& image = *data.the_ivt_image; - image.Set(20, 10, CByteImage::ImageType::eRGB24); - simox::ColorMap cmap = simox::color::cmaps::plasma(); - cmap.set_vmax(image.width + image.height); + image.Set(15, 35, CByteImage::ImageType::eRGB24); + cmap.set_vlimits(0, float(image.width + image.height)); for (int row = 0; row < image.height; ++row) { for (int col = 0; col < image.width; ++col) { - simox::Color color = cmap(row + col); + simox::Color color = cmap(float(row + col)); unsigned char* p = &image.pixels[(row * image.width + col) * image.bytesPerPixel]; p[0] = color.r; p[1] = color.g; @@ -399,6 +402,52 @@ namespace armarx } } } + { + cv::Mat& image = data.the_rgb24_image; + image.create(10, 20, image.type()); + cmap.set_vlimits(0, float(image.cols + image.rows)); + using Pixel = cv::Point3_<uint8_t>; + image.forEach<Pixel>([&cmap](Pixel& pixel, const int position[]) -> void + { + simox::Color color = cmap(float(position[0] + position[1])); + pixel.x = color.r; + pixel.y = color.g; + pixel.z = color.b; + }); + + if (true) + { + cv::Mat out; + cv::cvtColor(image, out, CV_RGB2BGR); + cv::imwrite("the_rgb24_image.png", out); + } + } + { + cv::Mat& image = data.the_depth32_image; + image.create(20, 10, image.type()); + image.forEach<float>([&image](float& pixel, const int position[]) -> void + { + pixel = 100 * float(position[0] + position[1]) / float(image.rows + image.cols); + }); + + cmap.set_vlimits(0, 100); + cv::Mat rgb(image.rows, image.cols, CV_8UC3); + using Pixel = cv::Point3_<uint8_t>; + rgb.forEach<Pixel>([&image, &cmap](Pixel& pixel, const int position[]) -> void + { + simox::Color color = cmap(image.at<float>(position)); + pixel.x = color.r; + pixel.y = color.g; + pixel.z = color.b; + }); + + if (true) + { + cv::Mat out; + cv::cvtColor(rgb, out, CV_RGB2BGR); + cv::imwrite("the_depth32_image.png", out); + } + } update.instancesData = { data.toAron() }; } diff --git a/source/RobotAPI/components/armem/server/ExampleMemory/aron/ExampleData.xml b/source/RobotAPI/components/armem/server/ExampleMemory/aron/ExampleData.xml index edd34d36d..5c49bef16 100644 --- a/source/RobotAPI/components/armem/server/ExampleMemory/aron/ExampleData.xml +++ b/source/RobotAPI/components/armem/server/ExampleMemory/aron/ExampleData.xml @@ -5,6 +5,7 @@ <CodeIncludes> <Include include="<Eigen/Core>" /> <Include include="<Image/ByteImage.h>" /> + <Include include="<opencv2/core/core.hpp>" /> <Include include="<RobotAPI/libraries/armem/aron/MemoryID.aron.generated.h>" /> </CodeIncludes> @@ -43,6 +44,12 @@ <ObjectChild key='the_ivt_image'> <IVTCByteImage type="GrayScale" shared_ptr="true"/> </ObjectChild> + <ObjectChild key='the_rgb24_image'> + <Image pixelType="rgb24"/> + </ObjectChild> + <ObjectChild key='the_depth32_image'> + <Image pixelType="depth32"/> + </ObjectChild> <ObjectChild key='the_float_list'> <List> -- GitLab