ArMarkerLocalizerOpenCV.h
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 Rainer Kartmann (rainer dot kartmann at kit dot edu)
20 * @date 2020
21 * @copyright http://www.gnu.org/licenses/gpl-2.0.txt
22 * GNU General Public License
23 */
24
25#pragma once
26
27#include <experimental/memory>
28#include <mutex>
29
30#include <opencv2/aruco.hpp>
31
32#include <VirtualRobot/VirtualRobot.h>
33
35
37
42
44#include <VisionX/interface/components/ArMarkerLocalizerInterface.h>
45
46
47// forward declarations
48class CByteImage;
49
50namespace visionx
51{
57
58 /**
59 * ArMarkerLocalizerOpenCV uses CTexturedRecognition of IVTRecognition in order to recognize and localize objects.
60 * The object data is read from PriorKnowledge and CommonStorage via MemoryX.
61 * The object localization is invoked automatically by the working memory if the object has been requested there.
62 */
64 virtual public ImageProcessor,
65 virtual public ArMarkerLocalizerInterface,
68 {
69 public:
71
72 /// @see PropertyUser::createPropertyDefinitions()
74
75 /// @see Component::getDefaultName()
76 std::string getDefaultName() const override;
77
78 protected:
79 void onInitImageProcessor() override;
80 void onConnectImageProcessor() override;
81
82 void
84 {
85 }
86
87 void
89 {
90 }
91
92 void process() override;
93
94 void createRemoteGuiTab();
95 void RemoteGui_update() override;
96
97
98 public:
99 // ArMarkerLocalizerOpenCVInterface interface
100 visionx::ArMarkerLocalizationResultList LocalizeAllMarkersNow(const Ice::Current&) override;
101 visionx::ArMarkerLocalizationResultList
102 GetLatestLocalizationResult(const Ice::Current&) override;
103
104
105 private:
106 visionx::ArMarkerLocalizationResultList localizeAllMarkersInternal();
107
108
109 private:
110 struct Properties
111 {
112 std::atomic<float> markerSize = 40.0;
113 int dictionary = cv::aruco::DICT_ARUCO_ORIGINAL;
114
115 std::string referenceFrame = "DepthCamera";
116 std::string agentName = "Armar6";
117 std::string imageProviderName = "ImageProvider";
118
119 std::size_t cameraIndex = 0;
120
121 // "Vector of distortion coefficients (k1,k2,p1,p2 [,k3 [,k4,k5,k6], [s1,s2,s3,s4]]) of 4, 5, 8 or 12 elements"
122 std::vector<float> extraDistortionCoeffs;
123
124 std::atomic_bool visuEnabled = false;
125 };
126
127 Properties p;
128
129 struct RemoteGuiTab : armarx::RemoteGui::Client::Tab
130 {
133 };
134
135 RemoteGuiTab tab;
136
137
138 armarx::DateTime m_timestamp_last_image;
139 CByteImage** cameraImages;
140 cv::Mat cameraMatrix, distortionCoeffs;
141
142 cv::Ptr<cv::aruco::DetectorParameters> arucoParameters =
143 new cv::aruco::DetectorParameters();
144 cv::Ptr<cv::aruco::Dictionary> arucoDictionary = new cv::aruco::Dictionary();
145
146 std::mutex resultMutex;
147 visionx::ArMarkerLocalizationResultList lastLocalizationResult;
148 // armarx::DateTime m_timestamp_last_result;
149
150
151 template <typename T>
152 using rw_plugin = armarx::armem::client::plugins::ReaderWriterPlugin<T>;
153
154 template <typename T>
155 using obs_ptr = std::experimental::observer_ptr<T>;
156
157 obs_ptr<rw_plugin<armarx::armem::robot_state::VirtualRobotReader>>
158 virtualRobotReaderPlugin = nullptr;
159
161 VirtualRobot::RobotNodePtr referenceNode;
162 };
163
164} // namespace visionx
Provides a ready-to-use ArViz client arviz as member variable.
std::string prefix
Prefix of the properties such as namespace, domain, component name, etc.
void onConnectImageProcessor() override
Implement this method in the ImageProcessor in order execute parts when the component is fully initia...
void onExitImageProcessor() override
Exit the ImapeProcessor component.
armarx::PropertyDefinitionsPtr createPropertyDefinitions() override
void process() override
Process the vision component.
void onInitImageProcessor() override
Setup the vision component.
visionx::ArMarkerLocalizationResultList LocalizeAllMarkersNow(const Ice::Current &) override
visionx::ArMarkerLocalizationResultList GetLatestLocalizationResult(const Ice::Current &) override
void onDisconnectImageProcessor() override
Implement this method in the ImageProcessor in order execute parts when the component looses network ...
std::string getDefaultName() const override
ImageProcessorPropertyDefinitions(std::string prefix)
The ImageProcessor class provides an interface for access to ImageProviders via Ice and shared memory...
std::shared_ptr< class Robot > RobotPtr
Definition Bus.h:19
IceUtil::Handle< class PropertyDefinitionContainer > PropertyDefinitionsPtr
PropertyDefinitions smart pointer type.
ArmarX headers.