ObjectLocalizerProcessorJob.cpp
Go to the documentation of this file.
1/*
2 * This file is part of ArmarX.
3 *
4 * Copyright (C) 2011-2016, High Performance Humanoid Technologies (H2T), Karlsruhe Institute of Technology (KIT), all rights reserved.
5 *
6 * ArmarX is free software; you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License version 2 as
8 * published by the Free Software Foundation.
9 *
10 * ArmarX is distributed in the hope that it will be useful, but
11 * WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * GNU General Public License for more details.
14 *
15 * You should have received a copy of the GNU General Public License
16 * along with this program. If not, see <http://www.gnu.org/licenses/>.
17 *
18 * @package VisionX::Component
19 * @author Kai Welke (welke at kit dot edu)
20 * @date 2013
21 * @copyright http://www.gnu.org/licenses/gpl-2.0.txt
22 * GNU General Public License
23 */
24
26
28
29// IVT
30#include <Image/ImageProcessor.h>
31
32
33using namespace visionx;
34
36 processor(processor), jobPending(false), jobFinished(false), abortRequested(false)
37{
38}
39
40void
41ObjectLocalizerProcessorJob::start(std::vector<std::string> objectClassNames)
42{
43 // set data and notify processing thread
44 std::unique_lock lock(jobMutex);
45 this->objectClassNames = objectClassNames;
46 jobPending = true;
47 jobFinished = false;
48}
49
50void
52{
53 abortRequested = false;
54}
55
56memoryx::ObjectLocalizationResultList
58{
59 while (!jobFinished)
60 {
61 usleep(1000);
62 }
63 jobFinished = false;
64 std::unique_lock lock(jobMutex);
65 return result;
66}
67
68void
70{
71 abortRequested = true;
72}
73
74void
76{
77 if (!processor)
78 {
79 ARMARX_ERROR << "No processor set";
80 return;
81 }
82
83 // allow initialization of recognition methods
84 processor->initRecognizer();
85
86 // fill object database with objects from prior knowledge
87 processor->initObjectClasses();
88
89 // main loop
90 memoryx::ObjectLocalizationResultList localResult;
91
92 while (!abortRequested)
93 {
94 try
95 {
96 // wait for new processing job
97 while (!jobPending && !abortRequested)
98 {
99 usleep(1000);
100 }
101 jobPending = false;
102 ARMARX_VERBOSE << "Job received";
103
104 if (abortRequested)
105 {
106 ARMARX_INFO << "ObjectLocalizerProcessorJob::process(): exit requested";
107 continue;
108 }
109
110
111 localResult.clear();
112
113 ARMARX_DEBUG << "ObjectLocalizerProcessorJob::process(): starting localization";
114 int numImages = processor->getImages(
115 processor->imageProviderName, processor->cameraImages, processor->imageMetaInfo);
116 if (numImages > 0)
117 {
118 // recognize
119 if (processor->getResultImagesEnabled())
120 {
121 if (processor->isResultImageMaskEnabled())
122 {
123 Eigen::Vector3i colorMask = processor->getColorMask();
124 for (int n = 0; n < numImages; n++)
125 {
126 for (int j = 0; j < processor->resultImages[n]->height; j++)
127 {
128 for (int i = 0; i < processor->resultImages[n]->width; i++)
129 {
130 processor->resultImages[n]
131 ->pixels[3 * (j * processor->resultImages[n]->width + i) +
132 0] = colorMask(0);
133 processor->resultImages[n]
134 ->pixels[3 * (j * processor->resultImages[n]->width + i) +
135 1] = colorMask(1);
136 processor->resultImages[n]
137 ->pixels[3 * (j * processor->resultImages[n]->width + i) +
138 2] = colorMask(2);
139 }
140 }
141 }
142 }
143 else
144 {
145 ::ImageProcessor::CopyImage(processor->cameraImages[0],
146 processor->resultImages[0]);
147 if (numImages > 1)
148 {
149 ::ImageProcessor::CopyImage(processor->cameraImages[1],
150 processor->resultImages[1]);
151 }
152 }
153 }
154 ARMARX_DEBUG << "starting localization algo";
155 localResult = processor->localizeObjectClasses(objectClassNames,
156 processor->cameraImages,
157 processor->imageMetaInfo,
158 processor->resultImages);
159
160 // visualize
161 if (processor->getResultImagesEnabled())
162 {
163 processor->provideResultImages(processor->resultImages,
164 processor->imageMetaInfo);
165 }
166 ARMARX_DEBUG << "finished localization algo";
167 }
168 else
169 {
170 ARMARX_WARNING << deactivateSpam(1) << "Could not get images";
171 }
172 }
173 catch (std::exception& e)
174 {
175 ARMARX_ERROR << "Localization failed: " << processor->getName();
177 }
178
179 // set result and notify
180 std::unique_lock lock(jobMutex);
181 result = localResult;
182 jobFinished = true;
183 }
184}
SpamFilterDataPtr deactivateSpam(SpamFilterDataPtr const &spamFilter, float deactivationDurationSec, const std::string &identifier, bool deactivate)
Definition Logging.cpp:75
memoryx::ObjectLocalizationResultList waitForResult()
Wait for the localization result.
void start(std::vector< std::string > objectClassNames)
Start a localization job for the given objectClassName.
ObjectLocalizerProcessorJob(ObjectLocalizerProcessor *processor)
Init the job by providing the ObjectLocalizerProcessor that implements the required functionality.
#define ARMARX_INFO
The normal logging level.
Definition Logging.h:181
#define ARMARX_ERROR
The logging level for unexpected behaviour, that must be fixed.
Definition Logging.h:196
#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
#define ARMARX_VERBOSE
The logging level for verbose information.
Definition Logging.h:187
void handleExceptions()
ArmarX headers.