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 <mutex>
28 #include <experimental/memory>
29 
30 #include <opencv2/aruco.hpp>
31 #include <VirtualRobot/VirtualRobot.h>
33 
37 
39 
41 
43 #include <VisionX/interface/components/ArMarkerLocalizerInterface.h>
44 
45 
46 // forward declarations
47 class CByteImage;
48 
49 namespace visionx
50 {
53  {
54  public:
56  };
57 
58 
59  /**
60  * ArMarkerLocalizerOpenCV uses CTexturedRecognition of IVTRecognition in order to recognize and localize objects.
61  * The object data is read from PriorKnowledge and CommonStorage via MemoryX.
62  * The object localization is invoked automatically by the working memory if the object has been requested there.
63  */
65  virtual public ImageProcessor
66  , virtual public ArMarkerLocalizerInterface
67  , virtual public armarx::ArVizComponentPluginUser
69  {
70  public:
71 
73 
74  /// @see PropertyUser::createPropertyDefinitions()
76 
77  /// @see Component::getDefaultName()
78  std::string getDefaultName() const override;
79 
80  protected:
81 
82  void onInitImageProcessor() override;
83  void onConnectImageProcessor() override;
84  void onDisconnectImageProcessor() override {}
85  void onExitImageProcessor() override {}
86 
87  void process() override;
88 
89  void createRemoteGuiTab();
90  void RemoteGui_update() override;
91 
92 
93  public:
94  // ArMarkerLocalizerOpenCVInterface interface
95  visionx::ArMarkerLocalizationResultList LocalizeAllMarkersNow(const Ice::Current&) override;
96  visionx::ArMarkerLocalizationResultList GetLatestLocalizationResult(const Ice::Current&) override;
97 
98 
99  private:
100 
101  visionx::ArMarkerLocalizationResultList localizeAllMarkersInternal();
102 
103 
104  private:
105 
106  struct Properties
107  {
108  std::atomic<float> markerSize = 40.0;
109  int dictionary = cv::aruco::DICT_ARUCO_ORIGINAL;
110 
111  std::string referenceFrame = "DepthCamera";
112  std::string agentName = "Armar6";
113  std::string imageProviderName = "ImageProvider";
114 
115  std::size_t cameraIndex = 0;
116 
117  // "Vector of distortion coefficients (k1,k2,p1,p2 [,k3 [,k4,k5,k6], [s1,s2,s3,s4]]) of 4, 5, 8 or 12 elements"
118  std::vector<float> extraDistortionCoeffs;
119 
120  std::atomic_bool visuEnabled = false;
121  };
122  Properties p;
123 
124  struct RemoteGuiTab : armarx::RemoteGui::Client::Tab
125  {
128  };
129  RemoteGuiTab tab;
130 
131 
132  armarx::DateTime m_timestamp_last_image;
133  CByteImage** cameraImages;
134  cv::Mat cameraMatrix, distortionCoeffs;
135 
136  cv::Ptr<cv::aruco::DetectorParameters> arucoParameters = new cv::aruco::DetectorParameters();
137  cv::Ptr<cv::aruco::Dictionary> arucoDictionary = new cv::aruco::Dictionary();
138 
139  std::mutex resultMutex;
140  visionx::ArMarkerLocalizationResultList lastLocalizationResult;
141  // armarx::DateTime m_timestamp_last_result;
142 
143 
144 
145  template <typename T>
147 
148  template <typename T>
149  using obs_ptr = std::experimental::observer_ptr<T>;
150 
151  obs_ptr<rw_plugin<armarx::armem::robot_state::VirtualRobotReader>> virtualRobotReaderPlugin =
152  nullptr;
153 
155  VirtualRobot::RobotNodePtr referenceNode;
156 
157 
158  };
159 
160 }
visionx::ArMarkerLocalizerOpenCV::onInitImageProcessor
void onInitImageProcessor() override
Setup the vision component.
Definition: ArMarkerLocalizerOpenCV.cpp:130
ArVizComponentPlugin.h
visionx::ArMarkerLocalizerOpenCV::getDefaultName
std::string getDefaultName() const override
Definition: ArMarkerLocalizerOpenCV.cpp:124
visionx::ArMarkerLocalizerOpenCV::createRemoteGuiTab
void createRemoteGuiTab()
Definition: ArMarkerLocalizerOpenCV.cpp:406
visionx
ArmarX headers.
Definition: OpenPoseStressTest.h:38
visionx::ArMarkerLocalizerOpenCVPropertyDefinitions
Definition: ArMarkerLocalizerOpenCV.h:51
visionx::ArMarkerLocalizerOpenCV::RemoteGui_update
void RemoteGui_update() override
Definition: ArMarkerLocalizerOpenCV.cpp:430
visionx::ImageProcessor
The ImageProcessor class provides an interface for access to ImageProviders via Ice and shared memory...
Definition: ImageProcessor.h:87
visionx::ArMarkerLocalizerOpenCV::process
void process() override
Process the vision component.
Definition: ArMarkerLocalizerOpenCV.cpp:243
DateTime.h
armarx::armem::client::plugins::ReaderWriterPlugin
A component plugin offering client-side access to a reader or writer and manages the lifecycle,...
Definition: ReaderWriterPlugin.h:44
visionx::ArMarkerLocalizerOpenCV::LocalizeAllMarkersNow
visionx::ArMarkerLocalizationResultList LocalizeAllMarkersNow(const Ice::Current &) override
Definition: ArMarkerLocalizerOpenCV.cpp:384
armarx::RemoteGui::Client::Tab
Definition: Tab.h:15
armarx::PropertyDefinitionContainer::prefix
std::string prefix
Prefix of the properties such as namespace, domain, component name, etc.
Definition: PropertyDefinitionContainer.h:333
visionx::ArMarkerLocalizerOpenCV
ArMarkerLocalizerOpenCV uses CTexturedRecognition of IVTRecognition in order to recognize and localiz...
Definition: ArMarkerLocalizerOpenCV.h:64
visionx::ArMarkerLocalizerOpenCV::createPropertyDefinitions
armarx::PropertyDefinitionsPtr createPropertyDefinitions() override
Definition: ArMarkerLocalizerOpenCV.cpp:61
ReaderWriterPlugin.h
std::experimental::fundamentals_v2::observer_ptr
Definition: ManagedIceObject.h:53
visionx::ArMarkerLocalizerOpenCV::onConnectImageProcessor
void onConnectImageProcessor() override
Implement this method in the ImageProcessor in order execute parts when the component is fully initia...
Definition: ArMarkerLocalizerOpenCV.cpp:163
LightweightRemoteGuiComponentPlugin.h
armarx::ArVizComponentPluginUser
Provides a ready-to-use ArViz client arviz as member variable.
Definition: ArVizComponentPlugin.h:36
ImageProcessor.h
visionx::ArMarkerLocalizerOpenCV::GetLatestLocalizationResult
visionx::ArMarkerLocalizationResultList GetLatestLocalizationResult(const Ice::Current &) override
Definition: ArMarkerLocalizerOpenCV.cpp:399
VirtualRobotReader.h
armarx::LightweightRemoteGuiComponentPluginUser
Definition: LightweightRemoteGuiComponentPlugin.h:73
plugins.h
armarx::core::time::DateTime
Represents a point in time.
Definition: DateTime.h:24
visionx::ArMarkerLocalizerOpenCV::onDisconnectImageProcessor
void onDisconnectImageProcessor() override
Implement this method in the ImageProcessor in order execute parts when the component looses network ...
Definition: ArMarkerLocalizerOpenCV.h:84
IceUtil::Handle< class PropertyDefinitionContainer >
visionx::ArMarkerLocalizerOpenCV::onExitImageProcessor
void onExitImageProcessor() override
Exit the ImapeProcessor component.
Definition: ArMarkerLocalizerOpenCV.h:85
visionx::ImageProcessorPropertyDefinitions
Definition: ImageProcessor.h:61
armarx::RemoteGui::Client::CheckBox
Definition: Widgets.h:129
armarx::RemoteGui::Client::FloatSpinBox
Definition: Widgets.h:93
visionx::ArMarkerLocalizerOpenCV::ArMarkerLocalizerOpenCV
ArMarkerLocalizerOpenCV()
Definition: ArMarkerLocalizerOpenCV.cpp:118
VirtualRobot::RobotPtr
std::shared_ptr< class Robot > RobotPtr
Definition: Bus.h:18
visionx::ArMarkerLocalizerOpenCVPropertyDefinitions::ArMarkerLocalizerOpenCVPropertyDefinitions
ArMarkerLocalizerOpenCVPropertyDefinitions(std::string prefix)
Definition: ArMarkerLocalizerOpenCV.cpp:54