29 #include <Image/ImageProcessor.h>
38 getConfigIdentifier()));
43 ARMARX_DEBUG <<
"Initializing SimpleEpisodicMemoryImageConnector";
45 m_image_provider_id = getProperty<std::string>(
"ImageProviderName").getValue();
46 m_image_provider_channel = getProperty<unsigned int>(
"ImageProviderChannel");
47 ARMARX_VERBOSE <<
"Using image provider with ID '" << m_image_provider_id <<
"'.";
49 usingImageProvider(m_image_provider_id);
50 usingProxy(
"SimpleEpisodicMemory");
52 m_image_received =
false;
60 getProxy(m_simple_episodic_memory, m_simple_episodic_memory_proxy_name);
63 m_image_provider_info = getImageProvider(m_image_provider_id);
64 m_image_provider = getProxy<visionx::ImageProviderInterfacePrx>(m_image_provider_id);
67 num_of_received_images =
static_cast<unsigned int>(m_image_provider_info.numberImages);
68 m_input_image_buf = new ::CByteImage*[num_of_received_images];
69 for (
unsigned int i = 0; i < num_of_received_images; ++i)
77 m_periodic_task->start();
84 m_periodic_task->stop();
89 for (
unsigned int i = 0; i < num_of_received_images; ++i)
91 delete m_input_image_buf[i];
93 delete[] m_input_image_buf;
103 const IceUtil::Time timeout = IceUtil::Time::milliSeconds(1000);
104 if (!waitForImages(m_image_provider_id,
static_cast<int>(timeout.toMilliSeconds())))
106 ARMARX_WARNING <<
"Timeout while waiting for camera images (>" << timeout <<
")";
110 ARMARX_DEBUG <<
"Received a new image. Putting image to member variable";
111 std::lock_guard<std::mutex> lock{m_input_image_mutex};
113 int num_images = getImages(m_image_provider_id, m_input_image_buf, m_image_meta_info);
114 m_timestamp_last_image = IceUtil::Time::microSeconds(m_image_meta_info->timeProvided);
116 if (
static_cast<unsigned int>(num_images) != num_of_received_images)
123 ::ImageProcessor::CopyImage(m_input_image_buf[m_image_provider_channel], m_input_image);
124 m_image_received =
true;
129 void visionx::SimpleEpisodicMemoryImageConnector::checkForNewImages()
132 if (!m_image_received)
137 ARMARX_DEBUG <<
"Got a new image for processing. Send image to EpisodicMemory. Image information: Size: " << m_input_image->width <<
", " << m_input_image->height <<
", " << m_input_image->bytesPerPixel;
138 std::lock_guard<std::mutex> lock{m_input_image_mutex};
139 m_image_received =
false;
143 memoryx::ImageEvent memory_image_event;
144 memory_image_event.providerName = m_image_provider_id +
"__" +
std::to_string(m_image_provider_channel);
145 memory_image_event.receivedInMs = m_timestamp_last_image.toMilliSecondsDouble();
146 memory_image_event.height = m_input_image->height;
147 memory_image_event.width = m_input_image->width;
148 memory_image_event.colourType = (m_input_image->bytesPerPixel == 3 ? memoryx::ColourSpace::RGB : memoryx::ColourSpace::GRAYSCALE);
149 memory_image_event.data = std::vector<unsigned char>(m_input_image->pixels, m_input_image->pixels + (m_input_image->height * m_input_image->width * m_input_image->bytesPerPixel));
150 m_simple_episodic_memory->registerImageEvent(memory_image_event);