MemoryRGBDOpenPoseEstimation.cpp
Go to the documentation of this file.
1 /*
2  * This file is part of ArmarX.
3  *
4  * ArmarX is free software; you can redistribute it and/or modify
5  * it under the terms of the GNU General Public License version 2 as
6  * published by the Free Software Foundation.
7  *
8  * ArmarX is distributed in the hope that it will be useful, but
9  * WITHOUT ANY WARRANTY; without even the implied warranty of
10  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11  * GNU General Public License for more details.
12  *
13  * You should have received a copy of the GNU General Public License
14  * along with this program. If not, see <http://www.gnu.org/licenses/>.
15  *
16  * @package VisionX::RGBDOpenPoseEstimation
17  * @author Fabian Peller <fabian.peller@kit.edu>
18  * @date 2020
19  * @copyright http://www.gnu.org/licenses/gpl-2.0.txt
20  * GNU General Public License
21  */
22 
24 
25 
26 using namespace visionx;
27 using namespace armarx;
28 
29 
32 {
34 
35 
36  setupPropertyDefinitions(def);
37  def->optional(providerName, "ImageProviderName");
38  return def;
39 }
40 
42 {
43  usingImageProvider(providerName);
44 
45  timeoutCounter2d = 0;
46  readErrorCounter2d = 0;
47  sucessCounter2d = 0;
48 }
49 
51 {
52  visionx::ImageType imageDisplayType = visionx::tools::typeNameToImageType("rgb");
53  imageProviderInfo = getImageProvider(providerName, imageDisplayType);
54  openposeInputImageFormat = imageProviderInfo.imageFormat;
55 
56  setupLocalVariables();
57 
58  numImages = static_cast<unsigned int>(imageProviderInfo.numberImages);
59  if (numImages < 1 || numImages > 2)
60  {
61  ARMARX_FATAL << "invalid number of images. aborting";
62  return;
63  }
64 
65  imageBuffer = new CByteImage*[numImages];
66  for (unsigned int i = 0 ; i < numImages ; i++)
67  {
68  imageBuffer[i] = visionx::tools::createByteImage(imageProviderInfo);
69  }
70 
71  enableResultImages(1, imageProviderInfo.imageFormat.dimension, imageProviderInfo.imageFormat.type);
72 
73  ARMARX_INFO << "OpenPoseEstimationImageProcessor connect done";
74 }
75 
77 {
78  delete[] imageBuffer;
79 
80  destroyLocalVariables();
81 }
82 
84 {
85 
86 }
87 
89 {
90  if (running2D)
91  {
92  if (!waitForImages(providerName))
93  {
94  ++timeoutCounter2d;
95  ARMARX_WARNING << "Timeout or error in wait for images"
96  << " (#timeout " << timeoutCounter2d
97  << ", #read error " << readErrorCounter2d
98  << ", #success " << sucessCounter2d << ")";
99  }
100  else
101  {
102  if (static_cast<unsigned int>(getImages(providerName, imageBuffer, imageMetaInfo)) != numImages)
103  {
104  ++readErrorCounter2d;
105  ARMARX_WARNING << "Unable to transfer or read images"
106  << " (#timeout " << timeoutCounter2d
107  << ", #read error " << readErrorCounter2d
108  << ", #success " << sucessCounter2d << ")";
109  return;
110  }
111  else
112  {
113  ++sucessCounter2d;
114 
115  {
116  std::unique_lock lock_rgb(rgbImageBufferMutex);
117  ::ImageProcessor::CopyImage(imageBuffer[0], rgbImageBuffer);
118  }
119 
120  {
121  std::unique_lock lock_depth(depthImageBufferMutex);
122  ::ImageProcessor::CopyImage(imageBuffer[1], depthImageBuffer);
123  }
124 
125  timestamp_of_update = imageMetaInfo->timeProvided;
126  update_ready = true;
127  }
128  }
129  }
130  else
131  {
132  usleep(10000);
133  }
134 }
135 
visionx::RGBDOpenPoseEstimation::onExitImageProcessor
virtual void onExitImageProcessor() override
Exit the ImapeProcessor component.
Definition: MemoryRGBDOpenPoseEstimation.cpp:83
visionx
ArmarX headers.
Definition: OpenPoseStressTest.h:38
visionx::tools::createByteImage
CByteImage * createByteImage(const ImageFormatInfo &imageFormat, const ImageType imageType)
Creates a ByteImage for the destination type specified in the given imageProviderInfo.
visionx::RGBDOpenPoseEstimation::onConnectImageProcessor
virtual void onConnectImageProcessor() override
Implement this method in the ImageProcessor in order execute parts when the component is fully initia...
Definition: MemoryRGBDOpenPoseEstimation.cpp:50
MemoryRGBDOpenPoseEstimation.h
ARMARX_FATAL
#define ARMARX_FATAL
Definition: Logging.h:192
visionx::RGBDOpenPoseEstimation::onInitImageProcessor
virtual void onInitImageProcessor() override
Setup the vision component.
Definition: MemoryRGBDOpenPoseEstimation.cpp:41
visionx::RGBDOpenPoseEstimation::process
virtual void process() override
Process the vision component.
Definition: MemoryRGBDOpenPoseEstimation.cpp:88
armarx::ComponentPropertyDefinitions
Default component property definition container.
Definition: Component.h:70
ARMARX_INFO
#define ARMARX_INFO
Definition: Logging.h:174
IceUtil::Handle< class PropertyDefinitionContainer >
visionx::tools::typeNameToImageType
ImageType typeNameToImageType(const std::string &imageTypeName)
Converts an image type name as string into an ImageType integer.
Definition: TypeMapping.cpp:42
visionx::RGBDOpenPoseEstimation::createPropertyDefinitions
virtual armarx::PropertyDefinitionsPtr createPropertyDefinitions() override
Definition: MemoryRGBDOpenPoseEstimation.cpp:31
ARMARX_WARNING
#define ARMARX_WARNING
Definition: Logging.h:186
armarx
This file offers overloads of toIce() and fromIce() functions for STL container types.
Definition: ArmarXTimeserver.cpp:28
visionx::RGBDOpenPoseEstimation::onDisconnectImageProcessor
virtual void onDisconnectImageProcessor() override
Implement this method in the ImageProcessor in order execute parts when the component looses network ...
Definition: MemoryRGBDOpenPoseEstimation.cpp:76