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 
29 #include <opencv2/aruco.hpp>
30 
32 
34 
36 #include <VisionX/interface/components/ArMarkerLocalizerInterface.h>
37 
38 
39 // forward declarations
40 class CByteImage;
41 
42 namespace visionx
43 {
46  {
47  public:
49  };
50 
51 
52  /**
53  * ArMarkerLocalizerOpenCV uses CTexturedRecognition of IVTRecognition in order to recognize and localize objects.
54  * The object data is read from PriorKnowledge and CommonStorage via MemoryX.
55  * The object localization is invoked automatically by the working memory if the object has been requested there.
56  */
58  virtual public ImageProcessor
59  , virtual public ArMarkerLocalizerInterface
60  , virtual public armarx::ArVizComponentPluginUser
62  {
63  public:
64 
65  /// @see PropertyUser::createPropertyDefinitions()
67 
68  /// @see Component::getDefaultName()
69  std::string getDefaultName() const override;
70 
71  protected:
72 
73  void onInitImageProcessor() override;
74  void onConnectImageProcessor() override;
75  void onDisconnectImageProcessor() override {}
76  void onExitImageProcessor() override {}
77 
78  void process() override;
79 
80  void createRemoteGuiTab();
81  void RemoteGui_update() override;
82 
83 
84  public:
85  // ArMarkerLocalizerOpenCVInterface interface
86  visionx::ArMarkerLocalizationResultList LocalizeAllMarkersNow(const Ice::Current&) override;
87  visionx::ArMarkerLocalizationResultList GetLatestLocalizationResult(const Ice::Current&) override;
88 
89 
90  private:
91 
92  visionx::ArMarkerLocalizationResultList localizeAllMarkersInternal();
93 
94 
95  private:
96 
97  struct Properties
98  {
99  std::atomic<float> markerSize = 40.0;
100  int dictionary = cv::aruco::DICT_ARUCO_ORIGINAL;
101 
102  std::string referenceFrame = "DepthCamera";
103  std::string agentName = "Armar6";
104  std::string imageProviderName = "ImageProvider";
105 
106  // "Vector of distortion coefficients (k1,k2,p1,p2 [,k3 [,k4,k5,k6], [s1,s2,s3,s4]]) of 4, 5, 8 or 12 elements"
107  std::vector<float> extraDistortionCoeffs;
108 
109  std::atomic_bool visuEnabled = false;
110  };
111  Properties p;
112 
113  struct RemoteGuiTab : armarx::RemoteGui::Client::Tab
114  {
117  };
118  RemoteGuiTab tab;
119 
120 
121  CByteImage** cameraImages;
122  cv::Mat cameraMatrix, distortionCoeffs;
123 
124  cv::Ptr<cv::aruco::DetectorParameters> arucoParameters = new cv::aruco::DetectorParameters();
125  cv::Ptr<cv::aruco::Dictionary> arucoDictionary = new cv::aruco::Dictionary();
126 
127  std::mutex resultMutex;
128  visionx::ArMarkerLocalizationResultList lastLocalizationResult;
129 
130  };
131 
132 }
133 
visionx::ArMarkerLocalizerOpenCV::onInitImageProcessor
void onInitImageProcessor() override
Setup the vision component.
Definition: ArMarkerLocalizerOpenCV.cpp:109
ArVizComponentPlugin.h
visionx::ArMarkerLocalizerOpenCV::getDefaultName
std::string getDefaultName() const override
Definition: ArMarkerLocalizerOpenCV.cpp:102
visionx::ArMarkerLocalizerOpenCV::createRemoteGuiTab
void createRemoteGuiTab()
Definition: ArMarkerLocalizerOpenCV.cpp:337
visionx
ArmarX headers.
Definition: OpenPoseStressTest.h:38
visionx::ArMarkerLocalizerOpenCVPropertyDefinitions
Definition: ArMarkerLocalizerOpenCV.h:44
visionx::ArMarkerLocalizerOpenCV::RemoteGui_update
void RemoteGui_update() override
Definition: ArMarkerLocalizerOpenCV.cpp:360
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:202
visionx::ArMarkerLocalizerOpenCV::LocalizeAllMarkersNow
visionx::ArMarkerLocalizationResultList LocalizeAllMarkersNow(const Ice::Current &) override
Definition: ArMarkerLocalizerOpenCV.cpp:316
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:57
visionx::ArMarkerLocalizerOpenCV::createPropertyDefinitions
armarx::PropertyDefinitionsPtr createPropertyDefinitions() override
Definition: ArMarkerLocalizerOpenCV.cpp:54
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:139
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:331
armarx::LightweightRemoteGuiComponentPluginUser
Definition: LightweightRemoteGuiComponentPlugin.h:73
visionx::ArMarkerLocalizerOpenCV::onDisconnectImageProcessor
void onDisconnectImageProcessor() override
Implement this method in the ImageProcessor in order execute parts when the component looses network ...
Definition: ArMarkerLocalizerOpenCV.h:75
IceUtil::Handle< class PropertyDefinitionContainer >
visionx::ArMarkerLocalizerOpenCV::onExitImageProcessor
void onExitImageProcessor() override
Exit the ImapeProcessor component.
Definition: ArMarkerLocalizerOpenCV.h:76
visionx::ImageProcessorPropertyDefinitions
Definition: ImageProcessor.h:61
armarx::RemoteGui::Client::CheckBox
Definition: Widgets.h:129
armarx::RemoteGui::Client::FloatSpinBox
Definition: Widgets.h:93
visionx::ArMarkerLocalizerOpenCVPropertyDefinitions::ArMarkerLocalizerOpenCVPropertyDefinitions
ArMarkerLocalizerOpenCVPropertyDefinitions(std::string prefix)
Definition: ArMarkerLocalizerOpenCV.cpp:49