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
24
27
28namespace visionx
29{
32 {
35
36 def->optional(providerName, "ImageProviderName");
37 OpenPoseEstimationComponent::setupPropertyDefinitions(def);
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 rgbImageFormat = imageProviderInfo.imageFormat;
57
58 OpenPoseEstimationComponent::onConnect();
59
60 numImages = static_cast<unsigned int>(imageProviderInfo.numberImages);
61 if (numImages != 1)
62 {
63 ARMARX_FATAL << "invalid number of images. aborting";
64 return;
65 }
66
67 imageBuffer = new CByteImage*[1];
68 imageBuffer[0] = visionx::tools::createByteImage(imageProviderInfo);
69 rgbImageBuffer = visionx::tools::createByteImage(imageProviderInfo);
70
72 1, imageProviderInfo.imageFormat.dimension, imageProviderInfo.imageFormat.type);
73
74 ARMARX_INFO << getName() << " connect done";
75 }
76
77 void
79 {
80 delete[] imageBuffer;
81
82 OpenPoseEstimationComponent::onDisconnect();
83 }
84
85 void
89
90 void
92 {
93 if (running2D)
94 {
95 if (!waitForImages(providerName))
96 {
97 ++timeoutCounter2d;
98 ARMARX_WARNING << "Timeout or error in wait for images"
99 << " (#timeout " << timeoutCounter2d << ", #read error "
100 << readErrorCounter2d << ", #success " << sucessCounter2d << ")";
101 }
102 else
103 {
104 std::lock_guard lock_images(imageBufferMutex);
105 if (static_cast<unsigned int>(
106 getImages(providerName, imageBuffer, imageMetaInfo)) != numImages)
107 {
108 ++readErrorCounter2d;
109 ARMARX_WARNING << "Unable to transfer or read images"
110 << " (#timeout " << timeoutCounter2d << ", #read error "
111 << readErrorCounter2d << ", #success " << sucessCounter2d << ")";
112 return;
113 }
114 else
115 {
116 ++sucessCounter2d;
117
118 std::lock_guard lock_rgb(rgbImageBufferMutex);
119 ::ImageProcessor::CopyImage(imageBuffer[0], rgbImageBuffer);
120
121 timestamp_of_update = imageMetaInfo->timeProvided;
122 update_ready = true;
123 }
124 }
125 }
126 else
127 {
128 ARMARX_DEBUG << deactivateSpam() << "Not running. Wait until start signal comes";
129 usleep(10000);
130 }
131 }
132} // namespace visionx
SpamFilterDataPtr deactivateSpam(SpamFilterDataPtr const &spamFilter, float deactivationDurationSec, const std::string &identifier, bool deactivate)
Definition Logging.cpp:75
Default component property definition container.
Definition Component.h:70
std::string getConfigIdentifier()
Retrieve config identifier for this component as set in constructor.
Definition Component.cpp:90
std::string getName() const
Retrieve name of object.
void enableResultImages(int numberImages, ImageDimension imageDimension, ImageType imageType, const std::string &name="")
Enables visualization.
void usingImageProvider(std::string name)
Registers a delayed topic subscription and a delayed provider proxy retrieval which all will be avail...
bool waitForImages(int milliseconds=1000)
Wait for new images.
ImageProviderInfo getImageProvider(std::string name, ImageType destinationImageType=eRgb, bool waitForProxy=false)
Select an ImageProvider.
int getImages(CByteImage **ppImages)
Poll images from provider.
virtual void onConnectImageProcessor() override
Implement this method in the ImageProcessor in order execute parts when the component is fully initia...
virtual void onExitImageProcessor() override
Exit the ImapeProcessor component.
virtual armarx::PropertyDefinitionsPtr createPropertyDefinitions() override
virtual void process() override
Process the vision component.
virtual void onInitImageProcessor() override
Setup the vision component.
virtual void onDisconnectImageProcessor() override
Implement this method in the ImageProcessor in order execute parts when the component looses network ...
#define ARMARX_INFO
The normal logging level.
Definition Logging.h:181
#define ARMARX_FATAL
The logging level for unexpected behaviour, that will lead to a seriously malfunctioning program and ...
Definition Logging.h:199
#define ARMARX_DEBUG
The logging level for output that is only interesting while debugging.
Definition Logging.h:184
#define ARMARX_WARNING
The logging level for unexpected behaviour, but not a serious problem.
Definition Logging.h:193
IceUtil::Handle< class PropertyDefinitionContainer > PropertyDefinitionsPtr
PropertyDefinitions smart pointer type.
ImageType typeNameToImageType(const std::string &imageTypeName)
Converts an image type name as string into an ImageType integer.
CByteImage * createByteImage(const ImageFormatInfo &imageFormat, const ImageType imageType)
Creates a ByteImage for the destination type specified in the given imageProviderInfo.
ArmarX headers.