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 
31 {
33  new armarx::ComponentPropertyDefinitions{getConfigIdentifier()}};
34 
35 
36  setupPropertyDefinitions(def);
37  def->optional(providerName, "ImageProviderName");
38  return def;
39 }
40 
41 void
43 {
44  usingImageProvider(providerName);
45 
46  timeoutCounter2d = 0;
47  readErrorCounter2d = 0;
48  sucessCounter2d = 0;
49 }
50 
51 void
53 {
54  visionx::ImageType imageDisplayType = visionx::tools::typeNameToImageType("rgb");
55  imageProviderInfo = getImageProvider(providerName, imageDisplayType);
56  openposeInputImageFormat = imageProviderInfo.imageFormat;
57 
58  setupLocalVariables();
59 
60  numImages = static_cast<unsigned int>(imageProviderInfo.numberImages);
61  if (numImages < 1 || numImages > 2)
62  {
63  ARMARX_FATAL << "invalid number of images. aborting";
64  return;
65  }
66 
67  imageBuffer = new CByteImage*[numImages];
68  for (unsigned int i = 0; i < numImages; i++)
69  {
70  imageBuffer[i] = visionx::tools::createByteImage(imageProviderInfo);
71  }
72 
73  enableResultImages(
74  1, imageProviderInfo.imageFormat.dimension, imageProviderInfo.imageFormat.type);
75 
76  ARMARX_INFO << "OpenPoseEstimationImageProcessor connect done";
77 }
78 
79 void
81 {
82  delete[] imageBuffer;
83 
84  destroyLocalVariables();
85 }
86 
87 void
89 {
90 }
91 
92 void
94 {
95  if (running2D)
96  {
97  if (!waitForImages(providerName))
98  {
99  ++timeoutCounter2d;
100  ARMARX_WARNING << "Timeout or error in wait for images"
101  << " (#timeout " << timeoutCounter2d << ", #read error "
102  << readErrorCounter2d << ", #success " << sucessCounter2d << ")";
103  }
104  else
105  {
106  if (static_cast<unsigned int>(getImages(providerName, imageBuffer, imageMetaInfo)) !=
107  numImages)
108  {
109  ++readErrorCounter2d;
110  ARMARX_WARNING << "Unable to transfer or read images"
111  << " (#timeout " << timeoutCounter2d << ", #read error "
112  << readErrorCounter2d << ", #success " << sucessCounter2d << ")";
113  return;
114  }
115  else
116  {
117  ++sucessCounter2d;
118 
119  {
120  std::unique_lock lock_rgb(rgbImageBufferMutex);
121  ::ImageProcessor::CopyImage(imageBuffer[0], rgbImageBuffer);
122  }
123 
124  {
125  std::unique_lock lock_depth(depthImageBufferMutex);
126  ::ImageProcessor::CopyImage(imageBuffer[1], depthImageBuffer);
127  }
128 
129  timestamp_of_update = imageMetaInfo->timeProvided;
130  update_ready = true;
131  }
132  }
133  }
134  else
135  {
136  usleep(10000);
137  }
138 }
visionx::RGBDOpenPoseEstimation::onExitImageProcessor
virtual void onExitImageProcessor() override
Exit the ImapeProcessor component.
Definition: MemoryRGBDOpenPoseEstimation.cpp:88
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:52
MemoryRGBDOpenPoseEstimation.h
ARMARX_FATAL
#define ARMARX_FATAL
Definition: Logging.h:199
visionx::RGBDOpenPoseEstimation::onInitImageProcessor
virtual void onInitImageProcessor() override
Setup the vision component.
Definition: MemoryRGBDOpenPoseEstimation.cpp:42
visionx::RGBDOpenPoseEstimation::process
virtual void process() override
Process the vision component.
Definition: MemoryRGBDOpenPoseEstimation.cpp:93
armarx::ComponentPropertyDefinitions
Default component property definition container.
Definition: Component.h:69
ARMARX_INFO
#define ARMARX_INFO
Definition: Logging.h:181
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:30
ARMARX_WARNING
#define ARMARX_WARNING
Definition: Logging.h:193
armarx
This file offers overloads of toIce() and fromIce() functions for STL container types.
Definition: ArmarXTimeserver.cpp:27
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:80