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 static std::string GetDefaultName();
78
79 protected:
80 void onInitImageProcessor() override;
81 void onConnectImageProcessor() override;
82
83 void
85 {
86 }
87
88 void
90 {
91 }
92
93 void process() override;
94
95 void createRemoteGuiTab();
96 void RemoteGui_update() override;
97
98
99 public:
100 // ArMarkerLocalizerOpenCVInterface interface
101 visionx::ArMarkerLocalizationResultList LocalizeAllMarkersNow(const Ice::Current&) override;
102 visionx::ArMarkerLocalizationResultList
103 GetLatestLocalizationResult(const Ice::Current&) override;
104
105
106 private:
107 visionx::ArMarkerLocalizationResultList localizeAllMarkersInternal();
108
109
110 private:
111 struct Properties
112 {
113 std::atomic<float> markerSize = 40.0;
114 int dictionary = cv::aruco::DICT_ARUCO_ORIGINAL;
115
116 std::string referenceFrame = "DepthCamera";
117 std::string agentName = "Armar6";
118 std::string imageProviderName = "ImageProvider";
119
120 std::size_t cameraIndex = 0;
121
122 // "Vector of distortion coefficients (k1,k2,p1,p2 [,k3 [,k4,k5,k6], [s1,s2,s3,s4]]) of 4, 5, 8 or 12 elements"
123 std::vector<float> extraDistortionCoeffs;
124
125 std::atomic_bool visuEnabled = false;
126 };
127
128 Properties p;
129
130 struct RemoteGuiTab : armarx::RemoteGui::Client::Tab
131 {
134 };
135
136 RemoteGuiTab tab;
137
138
139 armarx::DateTime m_timestamp_last_image;
140 CByteImage** cameraImages;
141 cv::Mat cameraMatrix, distortionCoeffs;
142
143 cv::Ptr<cv::aruco::DetectorParameters> arucoParameters =
144 new cv::aruco::DetectorParameters();
145 cv::Ptr<cv::aruco::Dictionary> arucoDictionary = new cv::aruco::Dictionary();
146
147 std::mutex resultMutex;
148 visionx::ArMarkerLocalizationResultList lastLocalizationResult;
149 // armarx::DateTime m_timestamp_last_result;
150
151
152 template <typename T>
153 using rw_plugin = armarx::armem::client::plugins::ReaderWriterPlugin<T>;
154
155 template <typename T>
156 using obs_ptr = std::experimental::observer_ptr<T>;
157
158 obs_ptr<rw_plugin<armarx::armem::robot_state::VirtualRobotReader>>
159 virtualRobotReaderPlugin = nullptr;
160
162 VirtualRobot::RobotNodePtr referenceNode;
163 };
164
165} // 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.