27#include <opencv2/calib3d.hpp>
41#include <Calibration/Calibration.h>
42#include <Image/IplImageAdaptor.h>
54 "ReferenceFrameName",
"DepthCamera",
"Name of the ReferenceFrameName");
57 "ImageProviderName",
"ImageProvider",
"name of the image provider to use");
66 defs->optional(visuEnabled,
"visu.enabled",
"If true, visualize marker position.");
74 return "ArMarkerLocalizer";
90 StereoCalibrationInterfacePrx calibrationProvider =
91 StereoCalibrationInterfacePrx::checkedCast(imageProviderInfo.
proxy);
93 std::unique_ptr<CStereoCalibration> stereoCalibration(
95 CCalibration::CCameraParameters ivtCameraParameters =
96 stereoCalibration->GetLeftCalibration()->GetCameraParameters();
97 cv::Mat cameraMatrix(3, 3, cv::DataType<float>::type);
98 cameraMatrix.at<
float>(0, 0) = ivtCameraParameters.focalLength.x;
99 cameraMatrix.at<
float>(0, 1) = 0;
100 cameraMatrix.at<
float>(0, 2) = ivtCameraParameters.principalPoint.x;
101 cameraMatrix.at<
float>(1, 0) = 0;
102 cameraMatrix.at<
float>(1, 1) = ivtCameraParameters.focalLength.y;
103 cameraMatrix.at<
float>(1, 2) = ivtCameraParameters.principalPoint.y;
104 cameraMatrix.at<
float>(2, 0) = 0;
105 cameraMatrix.at<
float>(2, 1) = 0;
106 cameraMatrix.at<
float>(2, 2) = 1;
108 cv::Mat distortionParameters(4, 1, cv::DataType<float>::type);
110 if (!calibrationProvider->getImagesAreUndistorted())
112 distortionParameters.at<
float>(0, 0) = ivtCameraParameters.distortion[0];
113 distortionParameters.at<
float>(1, 0) = ivtCameraParameters.distortion[1];
114 distortionParameters.at<
float>(2, 0) = ivtCameraParameters.distortion[2];
115 distortionParameters.at<
float>(3, 0) = ivtCameraParameters.distortion[3];
119 distortionParameters.at<
float>(0, 0) = distortionParameters.at<
float>(1, 0) =
120 distortionParameters.at<
float>(2, 0) = distortionParameters.at<
float>(3, 0) = 0;
124 imageSize.width = ivtCameraParameters.width;
125 imageSize.height = ivtCameraParameters.height;
126 arucoCameraParameters.setParams(cameraMatrix, distortionParameters, imageSize);
129 startingTime = IceUtil::Time::now();
131 cameraImages =
new CByteImage*[2];
150 ArMarkerLocalizationResultList result = localizeAllMarkersInternal();
152 std::unique_lock lock(resultMutex);
153 lastLocalizationResult = result;
159 for (
const auto& r : result)
162 .
pose(FramedPosePtr::dynamicCast(r.pose)->toEigen()));
169ArMarkerLocalizationResultList
170ArMarkerLocalizer::localizeAllMarkersInternal()
172 IplImage* imageIpl = IplImageAdaptor::Adapt(cameraImages[0]);
173 cv::Mat imageOpenCV = cv::cvarrToMat(imageIpl);
176 std::vector<aruco::Marker> markers;
177 markerDetector.detect(imageOpenCV, markers, arucoCameraParameters, markerSize);
182 for (
const auto& m : markers)
192 visionx::ArMarkerLocalizationResultList resultList;
194 for (aruco::Marker marker : markers)
197 visionx::ArMarkerLocalizationResult result;
200 marker.calculateExtrinsics(
201 markerSize, arucoCameraParameters.CameraMatrix, arucoCameraParameters.Distorsion);
202 Eigen::Vector3f position(
203 marker.Tvec.at<
float>(0, 0), marker.Tvec.at<
float>(1, 0), marker.Tvec.at<
float>(2, 0));
204 Eigen::Matrix3f orientation;
207 cv::Matx33f cvOrientation;
209 cv::Rodrigues(marker.Rvec, cvOrientation);
212 orientation << cvOrientation(0, 2), cvOrientation(0, 0), cvOrientation(0, 1),
213 cvOrientation(1, 2), cvOrientation(1, 0), cvOrientation(1, 1), cvOrientation(2, 2),
214 cvOrientation(2, 0), cvOrientation(2, 1);
219 result.pose =
new armarx::FramedPose(orientation, position, refFrame, agentName);
220 result.id = marker.id;
232 resultList.push_back(result);
238visionx::ArMarkerLocalizationResultList
244 return visionx::ArMarkerLocalizationResultList();
247 return localizeAllMarkersInternal();
250ArMarkerLocalizationResultList
253 std::unique_lock lock(resultMutex);
254 return lastLocalizationResult;
268 tab.markerSize.setRange(1.0, 1000.0);
269 tab.markerSize.setSteps(1000);
270 tab.markerSize.setDecimals(1);
271 tab.markerSize.setValue(this->markerSize);
273 grid.
add(
Label(
"Marker size:"), {row, 0}).add(tab.markerSize, {row, 1});
283 if (tab.markerSize.hasValueChanged())
285 this->markerSize = tab.markerSize.getValue();
int Label(int n[], int size, int *curLabel, MiscLib::Vector< std::pair< int, size_t > > *labels)
#define ARMARX_STREAM_PRINTER
use this macro to write output code that is executed when printed and thus not executed if the debug ...
armarx::viz::Client arviz
std::string getConfigIdentifier()
Retrieve config identifier for this component as set in constructor.
Property< PropertyType > getProperty(const std::string &name)
SpamFilterDataPtr deactivateSpam(float deactivationDurationSec=10.0f, const std::string &identifier="", bool deactivate=true) const
disables the logging for the current line for the given amount of seconds.
std::string getName() const
Retrieve name of object.
std::string prefix
Prefix of the properties such as namespace, domain, component name, etc.
PropertyDefinition< PropertyType > & defineOptionalProperty(const std::string &name, PropertyType defaultValue, const std::string &description="", PropertyDefinitionBase::PropertyConstness constness=PropertyDefinitionBase::eConstant)
DerivedT & pose(Eigen::Matrix4f const &pose)
ArMarkerLocalizerPropertyDefinitions(std::string prefix)
void onConnectImageProcessor() override
Implement this method in the ImageProcessor in order execute parts when the component is fully initia...
void RemoteGui_update() override
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 createRemoteGuiTab()
std::string getDefaultName() const override
ImageProcessorPropertyDefinitions(std::string prefix)
bool waitForImages(int milliseconds=1000)
Wait for new images.
ImageProviderInfo getImageProvider(std::string name, ImageType destinationImageType=eRgb, bool waitForProxy=false)
Select an ImageProvider.
int getImages(CByteImage **ppImages)
Poll images from provider.
ImageProviderInterfacePrx proxy
proxy to image provider
#define ARMARX_INFO
The normal logging level.
#define ARMARX_WARNING
The logging level for unexpected behaviour, but not a serious problem.
#define ARMARX_VERBOSE
The logging level for verbose information.
This file offers overloads of toIce() and fromIce() functions for STL container types.
IceUtil::Handle< class PropertyDefinitionContainer > PropertyDefinitionsPtr
PropertyDefinitions smart pointer type.
void RemoteGui_startRunningTask()
void RemoteGui_createTab(std::string const &name, RemoteGui::Client::Widget const &rootWidget, RemoteGui::Client::Tab *tab)
GridLayout & add(Widget const &child, Pos pos, Span span=Span{1, 1})
void add(ElementT const &element)