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>
32 
36 
38 
40 
42 #include <VisionX/interface/components/ArMarkerLocalizerInterface.h>
43 
44 
45 // forward declarations
46 class CByteImage;
47 
48 namespace visionx
49 {
52  {
53  public:
55  };
56 
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
66  , virtual public armarx::ArVizComponentPluginUser
68  {
69  public:
70 
72 
73  /// @see PropertyUser::createPropertyDefinitions()
75 
76  /// @see Component::getDefaultName()
77  std::string getDefaultName() const override;
78 
79  protected:
80 
81  void onInitImageProcessor() override;
82  void onConnectImageProcessor() override;
83  void onDisconnectImageProcessor() override {}
84  void onExitImageProcessor() override {}
85 
86  void process() override;
87 
88  void createRemoteGuiTab();
89  void RemoteGui_update() override;
90 
91 
92  public:
93  // ArMarkerLocalizerOpenCVInterface interface
94  visionx::ArMarkerLocalizationResultList LocalizeAllMarkersNow(const Ice::Current&) override;
95  visionx::ArMarkerLocalizationResultList GetLatestLocalizationResult(const Ice::Current&) override;
96 
97 
98  private:
99 
100  visionx::ArMarkerLocalizationResultList localizeAllMarkersInternal();
101 
102 
103  private:
104 
105  struct Properties
106  {
107  std::atomic<float> markerSize = 40.0;
108  int dictionary = cv::aruco::DICT_ARUCO_ORIGINAL;
109 
110  std::string referenceFrame = "DepthCamera";
111  std::string agentName = "Armar6";
112  std::string imageProviderName = "ImageProvider";
113 
114  std::size_t cameraIndex = 0;
115 
116  // "Vector of distortion coefficients (k1,k2,p1,p2 [,k3 [,k4,k5,k6], [s1,s2,s3,s4]]) of 4, 5, 8 or 12 elements"
117  std::vector<float> extraDistortionCoeffs;
118 
119  std::atomic_bool visuEnabled = false;
120  };
121  Properties p;
122 
123  struct RemoteGuiTab : armarx::RemoteGui::Client::Tab
124  {
127  };
128  RemoteGuiTab tab;
129 
130 
131  CByteImage** cameraImages;
132  cv::Mat cameraMatrix, distortionCoeffs;
133 
134  cv::Ptr<cv::aruco::DetectorParameters> arucoParameters = new cv::aruco::DetectorParameters();
135  cv::Ptr<cv::aruco::Dictionary> arucoDictionary = new cv::aruco::Dictionary();
136 
137  std::mutex resultMutex;
138  visionx::ArMarkerLocalizationResultList lastLocalizationResult;
139 
140 
141  template <typename T>
143 
144  template <typename T>
145  using obs_ptr = std::experimental::observer_ptr<T>;
146 
147  obs_ptr<rw_plugin<armarx::armem::robot_state::VirtualRobotReader>> virtualRobotReaderPlugin =
148  nullptr;
149 
151  VirtualRobot::RobotNodePtr referenceNode;
152 
153 
154  };
155 
156 }
visionx::ArMarkerLocalizerOpenCV::onInitImageProcessor
void onInitImageProcessor() override
Setup the vision component.
Definition: ArMarkerLocalizerOpenCV.cpp:127
ArVizComponentPlugin.h
visionx::ArMarkerLocalizerOpenCV::getDefaultName
std::string getDefaultName() const override
Definition: ArMarkerLocalizerOpenCV.cpp:121
visionx::ArMarkerLocalizerOpenCV::createRemoteGuiTab
void createRemoteGuiTab()
Definition: ArMarkerLocalizerOpenCV.cpp:396
visionx
ArmarX headers.
Definition: OpenPoseStressTest.h:38
visionx::ArMarkerLocalizerOpenCVPropertyDefinitions
Definition: ArMarkerLocalizerOpenCV.h:50
visionx::ArMarkerLocalizerOpenCV::RemoteGui_update
void RemoteGui_update() override
Definition: ArMarkerLocalizerOpenCV.cpp:420
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:240
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:374
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:63
visionx::ArMarkerLocalizerOpenCV::createPropertyDefinitions
armarx::PropertyDefinitionsPtr createPropertyDefinitions() override
Definition: ArMarkerLocalizerOpenCV.cpp:58
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:160
LightweightRemoteGuiComponentPlugin.h
ObjectLocalizerProcessor.h
armarx::ArVizComponentPluginUser
Provides a ready-to-use ArViz client arviz as member variable.
Definition: ArVizComponentPlugin.h:36
visionx::ArMarkerLocalizerOpenCV::GetLatestLocalizationResult
visionx::ArMarkerLocalizationResultList GetLatestLocalizationResult(const Ice::Current &) override
Definition: ArMarkerLocalizerOpenCV.cpp:389
VirtualRobotReader.h
armarx::LightweightRemoteGuiComponentPluginUser
Definition: LightweightRemoteGuiComponentPlugin.h:73
plugins.h
visionx::ArMarkerLocalizerOpenCV::onDisconnectImageProcessor
void onDisconnectImageProcessor() override
Implement this method in the ImageProcessor in order execute parts when the component looses network ...
Definition: ArMarkerLocalizerOpenCV.h:83
IceUtil::Handle< class PropertyDefinitionContainer >
visionx::ArMarkerLocalizerOpenCV::onExitImageProcessor
void onExitImageProcessor() override
Exit the ImapeProcessor component.
Definition: ArMarkerLocalizerOpenCV.h:84
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:115
VirtualRobot::RobotPtr
std::shared_ptr< class Robot > RobotPtr
Definition: Bus.h:18
visionx::ArMarkerLocalizerOpenCVPropertyDefinitions::ArMarkerLocalizerOpenCVPropertyDefinitions
ArMarkerLocalizerOpenCVPropertyDefinitions(std::string prefix)
Definition: ArMarkerLocalizerOpenCV.cpp:51