LegacyRGBOpenPoseEstimation.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 
26 
27 namespace visionx
28 {
31  {
33 
34  def->optional(providerName, "ImageProviderName");
35  OpenPoseEstimationComponent::setupPropertyDefinitions(def);
36  return def;
37  }
38 
40  {
41  usingImageProvider(providerName);
42 
43  timeoutCounter2d = 0;
44  readErrorCounter2d = 0;
45  sucessCounter2d = 0;
46  }
47 
49  {
50  visionx::ImageType imageDisplayType = visionx::tools::typeNameToImageType("rgb");
51  imageProviderInfo = getImageProvider(providerName, imageDisplayType);
52  rgbImageFormat = imageProviderInfo.imageFormat;
53 
54  OpenPoseEstimationComponent::onConnect();
55 
56  numImages = static_cast<unsigned int>(imageProviderInfo.numberImages);
57  if (numImages != 1)
58  {
59  ARMARX_FATAL << "invalid number of images. aborting";
60  return;
61  }
62 
63  imageBuffer = new CByteImage*[1];
64  imageBuffer[0] = visionx::tools::createByteImage(imageProviderInfo);
65  rgbImageBuffer = visionx::tools::createByteImage(imageProviderInfo);
66 
67  enableResultImages(1, imageProviderInfo.imageFormat.dimension, imageProviderInfo.imageFormat.type);
68 
69  ARMARX_INFO << getName() << " connect done";
70  }
71 
73  {
74  delete[] imageBuffer;
75 
76  OpenPoseEstimationComponent::onDisconnect();
77  }
78 
80  {
81 
82  }
83 
85  {
86  if (running2D)
87  {
88  if (!waitForImages(providerName))
89  {
90  ++timeoutCounter2d;
91  ARMARX_WARNING << "Timeout or error in wait for images"
92  << " (#timeout " << timeoutCounter2d
93  << ", #read error " << readErrorCounter2d
94  << ", #success " << sucessCounter2d << ")";
95  }
96  else
97  {
98  std::lock_guard lock_images(imageBufferMutex);
99  if (static_cast<unsigned int>(getImages(providerName, imageBuffer, imageMetaInfo)) != numImages)
100  {
101  ++readErrorCounter2d;
102  ARMARX_WARNING << "Unable to transfer or read images"
103  << " (#timeout " << timeoutCounter2d
104  << ", #read error " << readErrorCounter2d
105  << ", #success " << sucessCounter2d << ")";
106  return;
107  }
108  else
109  {
110  ++sucessCounter2d;
111 
112  std::lock_guard lock_rgb(rgbImageBufferMutex);
113  ::ImageProcessor::CopyImage(imageBuffer[0], rgbImageBuffer);
114 
115  timestamp_of_update = imageMetaInfo->timeProvided;
116  update_ready = true;
117  }
118  }
119  }
120  else
121  {
122  ARMARX_DEBUG << deactivateSpam() << "Not running. Wait until start signal comes";
123  usleep(10000);
124  }
125  }
126 }
127 
visionx::LegacyRGBOpenPoseEstimation::onExitImageProcessor
virtual void onExitImageProcessor() override
Exit the ImapeProcessor component.
Definition: LegacyRGBOpenPoseEstimation.cpp:79
visionx::LegacyRGBOpenPoseEstimation::onDisconnectImageProcessor
virtual void onDisconnectImageProcessor() override
Implement this method in the ImageProcessor in order execute parts when the component looses network ...
Definition: LegacyRGBOpenPoseEstimation.cpp:72
visionx
ArmarX headers.
Definition: OpenPoseStressTest.h:38
visionx::ImageProcessor::getImageProvider
ImageProviderInfo getImageProvider(std::string name, ImageType destinationImageType=eRgb, bool waitForProxy=false)
Select an ImageProvider.
Definition: ImageProcessor.cpp:152
visionx::LegacyRGBOpenPoseEstimation::onConnectImageProcessor
virtual void onConnectImageProcessor() override
Implement this method in the ImageProcessor in order execute parts when the component is fully initia...
Definition: LegacyRGBOpenPoseEstimation.cpp:48
visionx::tools::createByteImage
CByteImage * createByteImage(const ImageFormatInfo &imageFormat, const ImageType imageType)
Creates a ByteImage for the destination type specified in the given imageProviderInfo.
ARMARX_FATAL
#define ARMARX_FATAL
Definition: Logging.h:192
LegacyRGBOpenPoseEstimation.h
visionx::LegacyRGBOpenPoseEstimation::onInitImageProcessor
virtual void onInitImageProcessor() override
Setup the vision component.
Definition: LegacyRGBOpenPoseEstimation.cpp:39
visionx::LegacyRGBOpenPoseEstimation::createPropertyDefinitions
virtual armarx::PropertyDefinitionsPtr createPropertyDefinitions() override
Definition: LegacyRGBOpenPoseEstimation.cpp:30
visionx::LegacyRGBOpenPoseEstimation::process
virtual void process() override
Process the vision component.
Definition: LegacyRGBOpenPoseEstimation.cpp:84
ARMARX_DEBUG
#define ARMARX_DEBUG
Definition: Logging.h:177
visionx::ImageProcessor::usingImageProvider
void usingImageProvider(std::string name)
Registers a delayed topic subscription and a delayed provider proxy retrieval which all will be avail...
Definition: ImageProcessor.cpp:117
visionx::ImageProcessor::getImages
int getImages(CByteImage **ppImages)
Poll images from provider.
Definition: ImageProcessor.cpp:351
armarx::Component::getConfigIdentifier
std::string getConfigIdentifier()
Retrieve config identifier for this component as set in constructor.
Definition: Component.cpp:74
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::ImageProcessor::enableResultImages
void enableResultImages(int numberImages, ImageDimension imageDimension, ImageType imageType, const std::string &name="")
Enables visualization.
Definition: ImageProcessor.cpp:227
visionx::tools::typeNameToImageType
ImageType typeNameToImageType(const std::string &imageTypeName)
Converts an image type name as string into an ImageType integer.
Definition: TypeMapping.cpp:42
ImageUtil.h
armarx::Logging::deactivateSpam
SpamFilterDataPtr deactivateSpam(float deactivationDurationSec=10.0f, const std::string &identifier="", bool deactivate=true) const
disables the logging for the current line for the given amount of seconds.
Definition: Logging.cpp:92
armarx::ManagedIceObject::getName
std::string getName() const
Retrieve name of object.
Definition: ManagedIceObject.cpp:107
TypeMapping.h
ARMARX_WARNING
#define ARMARX_WARNING
Definition: Logging.h:186
visionx::ImageProcessor::waitForImages
bool waitForImages(int milliseconds=1000)
Wait for new images.
Definition: ImageProcessor.cpp:275