28#include <pcl/common/transforms.h>
29#include <pcl/point_types.h>
36#include <VisionX/interface/components/Calibration.h>
39static constexpr auto InMaskSuff =
"_in_mask";
40static constexpr auto OutOfMaskSuff =
"_out_of_mask";
41static constexpr auto OutOfMaskImgSuff =
"_out_of_image";
42static constexpr auto MaskVisuSuff =
"_mask_visu";
43static constexpr auto MaskAsCloudSuff =
"_mask_as_cloud";
45#define call_template_function(F) \
46 switch (_pointCloudProviderInfo.pointCloudFormat->type) \
49 case visionx::PointContentType::eColoredPoints: \
50 F<pcl::PointXYZRGBA>(); \
52 case visionx::PointContentType::eColoredOrientedPoints: \
53 F<pcl::PointXYZRGBNormal>(); \
56 case visionx::PointContentType::eColoredLabeledPoints: \
57 F<pcl::PointXYZRGBL>(); \
60 case visionx::PointContentType::eOrientedPoints: \
61 ARMARX_ERROR << "eOrientedPoints NOT HANDLED IN VISIONX"; \
64 ARMARX_ERROR << "Could not process point cloud, because format '" \
65 << _pointCloudProviderInfo.pointCloudFormat->type << "' is unknown"; \
112 VirtualRobot::RobotIO::eStructure);
187 if (calibProviderName.empty())
190 visionx::MonocularCalibrationCapturingProviderInterfacePrx::checkedCast(
198 scalibprov->getStereoCalibration().calibrationLeft.cameraParam.focalLength.at(
201 scalibprov->getStereoCalibration().calibrationLeft.cameraParam.focalLength.at(
207 mcalibprov->getCalibration().cameraParam.focalLength.at(0);
209 mcalibprov->getCalibration().cameraParam.focalLength.at(1);
216 visionx::MonocularCalibrationCapturingProviderInterfacePrx::checkedCast(
218 auto scalibprov = visionx::StereoCalibrationInterfacePrx::checkedCast(calibProvider);
223 scalibprov->getStereoCalibration().calibrationLeft.cameraParam.focalLength.at(
226 scalibprov->getStereoCalibration().calibrationLeft.cameraParam.focalLength.at(
232 mcalibprov->getCalibration().cameraParam.focalLength.at(0);
234 mcalibprov->getCalibration().cameraParam.focalLength.at(1);
243 auto makeSlider = [&](std::string name,
int val,
int min = 0,
int max = 255)
252 auto makeFSlider = [&](std::string name,
int min,
int max,
float val)
258 static_cast<int>(
max -
min)))
264 makeSlider(
"red lo",
_redLo);
265 makeSlider(
"red hi",
_redHi);
268 makeSlider(
"blue lo",
_blueLo);
269 makeSlider(
"blue hi",
_blueHi);
291 const int focaladjrange = 10000;
300 .addOptions({
"Global",
"root"})
306 checkboxBuilder.widget().label =
"Sync using timestamp";
307 rootLayoutBuilder.
addChild(checkboxBuilder);
308 rootLayoutBuilder.
addChild(
new RemoteGui::VSpacer());
315 _redLo =
static_cast<std::uint8_t
>(
_guiTab.getValue<
int>(
"red lo").get());
318 _redHi =
static_cast<std::uint8_t
>(
_guiTab.getValue<
int>(
"red hi").get());
321 _greenLo =
static_cast<std::uint8_t
>(
_guiTab.getValue<
int>(
"green lo").get());
324 _greenHi =
static_cast<std::uint8_t
>(
_guiTab.getValue<
int>(
"green hi").get());
327 _blueLo =
static_cast<std::uint8_t
>(
_guiTab.getValue<
int>(
"blue lo").get());
330 _blueHi =
static_cast<std::uint8_t
>(
_guiTab.getValue<
int>(
"blue hi").get());
355 RemoteGui::WidgetPtr rootLayout = rootLayoutBuilder;
372std::pair<float, float>
383 const float s = std::sin(alpha);
384 const float c = std::cos(alpha);
390 const float ushifted = u - +width / 2.f +
_offsetX;
391 const float vshifted = v - +height / 2.f +
_offsetY;
393 const float rotatedU =
c * ushifted + s * vshifted;
394 const float rotatedV = -s * ushifted +
c * vshifted;
396 const float x = (
_flipX ? 1 : -1) * rotatedU;
397 const float y = (
_flipY ? 1 : -1) * rotatedV;
402std::array<std::int64_t, 2>
406 const float s = std::sin(alpha);
407 const float c = std::cos(alpha);
410 const float u = (
_flipX ? 1 : -1) * (
x / z) * fx;
411 const float v = (
_flipY ? 1 : -1) * (y / z) * fy;
413 const float rotatedU =
c * u + -s * v;
414 const float rotatedV = s * u +
c * v;
420 const std::int64_t imgx =
static_cast<std::int64_t
>(rotatedU + width / 2.f) -
_offsetX;
421 const std::int64_t imgy =
static_cast<std::int64_t
>(rotatedV + height / 2.f) -
_offsetY;
433template <
typename Po
intType>
459 typename pcl::PointCloud<PointType>::Ptr inputCloud(
new pcl::PointCloud<PointType>());
478 Eigen::Matrix4f pclInCamFrame = Eigen::Matrix4f::Identity();
479 Eigen::Matrix4f camInReportFrame = Eigen::Matrix4f::Identity();
490 camInReportFrame = fp.toEigen();
496 pclInCamFrame = fp.toEigen();
501 typename pcl::PointCloud<PointType>::Ptr tmpCloud(
new pcl::PointCloud<PointType>());
502 pcl::transformPointCloud(*inputCloud, *tmpCloud, pclInCamFrame);
503 tmpCloud.swap(inputCloud);
510 std::uint64_t pointsInImage = 0;
511 std::uint64_t pointsOutOfImage = 0;
512 _maskedCloud.reset(
new pcl::PointCloud<pcl::PointXYZRGBA>());
513 _inputCloud.reset(
new pcl::PointCloud<pcl::PointXYZRGBA>());
514 pcl::PointCloud<pcl::PointXYZRGBA>::Ptr unmaskedCloud(
new pcl::PointCloud<pcl::PointXYZRGBA>());
515 pcl::PointCloud<pcl::PointXYZRGBA>::Ptr outOfImageCloud(
516 new pcl::PointCloud<pcl::PointXYZRGBA>());
517 pcl::PointCloud<pcl::PointXYZRGBA>::Ptr visuCloud(
new pcl::PointCloud<pcl::PointXYZRGBA>());
521 for (
const auto& point : inputCloud->points)
529 static_assert(std::is_same<PointType, pcl::PointXYZRGBA>::value ||
530 std::is_same<PointType, pcl::PointXYZRGB>::value ||
531 std::is_same<PointType, pcl::PointXYZRGBL>::value ||
532 std::is_same<PointType, pcl::PointXYZRGBNormal>::value,
549 const auto uv =
xyz2uv(p.x, p.y, p.z, fx, fy);
550 const std::int64_t u = uv.at(0);
551 const std::int64_t v = uv.at(1);
552 if (u < 0 || u >= img.width || v < 0 || v >= img.height)
556 p.r = p.b = p.a = 255;
558 outOfImageCloud->push_back(p);
563 p.r = img.pixels[(u + v * img.width) * 3 + 0];
564 p.g = img.pixels[(u + v * img.width) * 3 + 1];
565 p.b = img.pixels[(u + v * img.width) * 3 + 2];
569 const bool okR = r.first <= p.r && r.second >= p.r;
570 const bool okG = g.first <= p.g && g.second >= p.g;
571 const bool okB = b.first <= p.b && b.second >= p.b;
579 unmaskedCloud->push_back(p);
581 visuCloud->push_back(p);
585 pcl::PointCloud<pcl::PointXYZRGBA>::Ptr tmpCloud(
new pcl::PointCloud<pcl::PointXYZRGBA>());
587 pcl::transformPointCloud(*
_maskedCloud, *tmpCloud, camInReportFrame);
590 pcl::transformPointCloud(*unmaskedCloud, *tmpCloud, camInReportFrame);
593 pcl::transformPointCloud(*outOfImageCloud, *tmpCloud, camInReportFrame);
596 pcl::transformPointCloud(*visuCloud, *tmpCloud, camInReportFrame);
601 for (
int u = 0; u < img.width; ++u)
603 for (
int v = 0; v < img.height; ++v)
606 auto xyz =
uvz2xyz(u, v, (fx + fy) / 2, fx, fy);
612 p.r = img.pixels[(u + v * img.width) * 3 + 0];
613 p.g = img.pixels[(u + v * img.width) * 3 + 1];
614 p.b = img.pixels[(u + v * img.width) * 3 + 2];
615 visuCloud->push_back(p);
618 pcl::transformPointCloud(*visuCloud, *tmpCloud, camInReportFrame);
628 return "MaskFilterPointCloudProcessor";
#define ARMARX_REGISTER_COMPONENT_EXECUTABLE(ComponentT, applicationName)
std::string getConfigIdentifier()
Retrieve config identifier for this component as set in constructor.
Property< PropertyType > getProperty(const std::string &name)
void changeFrame(const SharedRobotInterfacePrx &referenceRobot, const std::string &newFrame)
void offeringTopic(const std::string &name)
Registers a topic for retrival after initialization.
TopicProxyType getTopic(const std::string &name)
Returns a proxy of the specified topic.
bool usingProxy(const std::string &name, const std::string &endpoints="")
Registers a proxy for retrieval after initialization and adds it to the dependency list.
std::string getName() const
Retrieve name of object.
Ice::ObjectPrx getProxy(long timeoutMs=0, bool waitForScheduler=true) const
Returns the proxy of this object (optionally it waits for the proxy)
Brief description of class MaskFilterPointCloudProcessor.
visionx::PointCloudProviderInterfacePrx _pointCloudProvider
VirtualRobot::RobotPtr _localRobot
visionx::ImageProviderInterfacePrx _maskImageProvider
visionx::ImageProviderInfo _maskImageProviderInfo
void onDisconnectPointCloudAndImageProcessor() override
Implement this method in the PointCloudAndImageProcessor in order to execute parts when the component...
std::string _remoteGuiName
pcl::PointCloud< pcl::PointXYZRGBA >::Ptr _maskedCloud
void onConnectPointCloudAndImageProcessor() override
Implement this method in your PointCloudAndImageProcessor in order execute parts when the component i...
std::atomic< std::uint8_t > _greenLo
std::atomic< std::int64_t > _offsetY
std::string _pointCloudReportFrame
armarx::PropertyDefinitionsPtr createPropertyDefinitions() override
std::mutex _pointCloudReportFrameMutex
void process() override
Process the vision component.
RemoteGui::TabProxy _guiTab
std::array< float, 3 > uvz2xyz(int u, int v, float z, float fx, float fy) const
std::string _pointCloudProviderRefFrame
std::atomic< std::uint8_t > _blueHi
float _maskImageProviderFocalLengthY
std::string _pointCloudProviderName
std::atomic_bool _syncRobotWithTimestamp
std::atomic< std::uint8_t > _blueLo
std::atomic< std::uint8_t > _redLo
std::vector< visionx::CByteImageUPtr > _maskImageProviderImageOwner
std::string _maskImageProviderName
float _maskImageProviderFocalLengthX
RobotStateComponentInterfacePrx _robotStateComponent
void onInitPointCloudAndImageProcessor() override
Setup the vision component.
std::atomic< std::uint8_t > _greenHi
static std::string GetDefaultName()
visionx::PointCloudProviderInfo _pointCloudProviderInfo
std::string _maskImageProviderRefFrame
DebugDrawerInterfacePrx _debugDrawerTopic
RemoteGuiInterfacePrx _remoteGui
std::string _robotStateComponentName
std::pair< float, float > maskImageProviderFocalLength() const
std::atomic< std::int64_t > _guiParamUpdated
SimplePeriodicTask ::pointer_type _guiTask
std::vector< void * > _maskImageProviderImages
std::atomic< float > _focalLengthAdjustment
pcl::PointCloud< pcl::PointXYZRGBA >::Ptr _inputCloud
std::atomic_bool _maskMatchOneRangeInsteadOfAll
std::string _debugDrawerTopicName
std::atomic< std::uint8_t > _redHi
std::atomic< float > _maskZRotation
std::atomic< std::int64_t > _offsetX
std::array< std::int64_t, 2 > xyz2uv(float x, float y, float z, float fx, float fy) const
static VirtualRobot::RobotPtr createLocalCloneFromFile(RobotStateComponentInterfacePrx robotStatePrx, VirtualRobot::RobotIO::RobotDescription loadMode=VirtualRobot::RobotIO::eFull)
This is a convenience function for createLocalClone, which automatically gets the filename from the R...
static bool synchronizeLocalClone(VirtualRobot::RobotPtr robot, RobotStateComponentInterfacePrx robotStatePrx)
static bool synchronizeLocalCloneToTimestamp(VirtualRobot::RobotPtr robot, RobotStateComponentInterfacePrx robotStatePrx, Ice::Long timestamp)
Synchronizes a local robot to a robot state at timestamp.
void usingImageProvider(std::string name)
Registers a delayed topic subscription and a delayed provider proxy retrieval which all will be avail...
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.
void enableResultPointClouds(std::string resultProviderName="")
Enables visualization.
int getPointClouds(const PointCloudPtrT &pointCloudPtr)
Poll PointClouds from provider.
MetaPointCloudFormatPtr getPointCloudFormat(std::string providerName)
void usingPointCloudProvider(std::string providerName)
Registers a delayed topic subscription and a delayed provider proxy retrieval which will be available...
PointCloudProviderInfo getPointCloudProvider(std::string name, bool waitForProxy=false)
Select an PointCloudProvider.
bool waitForPointClouds(int milliseconds=1000)
Wait for new PointClouds.
void provideResultPointClouds(const PointCloudPtrT &pointClouds, std::string providerName="")
sends result PointClouds for visualization
#define ARMARX_CHECK_EXPRESSION(expression)
This macro evaluates the expression and if it turns out to be false it will throw an ExpressionExcept...
#define ARMARX_CHECK_GREATER_EQUAL(lhs, rhs)
This macro evaluates whether lhs is greater or equal (>=) rhs and if it turns out to be false it will...
#define ARMARX_CHECK_EQUAL(lhs, rhs)
This macro evaluates whether lhs is equal (==) rhs and if it turns out to be false it will throw an E...
#define ARMARX_INFO
The normal logging level.
detail::IntSpinBoxBuilder makeIntSpinBox(std::string const &name)
detail::CheckBoxBuilder makeCheckBox(std::string const &name)
detail::ComboBoxBuilder makeComboBox(std::string const &name)
detail::FloatSliderBuilder makeFloatSlider(std::string const &name)
detail::VBoxLayoutBuilder makeVBoxLayout(std::string const &name="")
detail::FloatSpinBoxBuilder makeFloatSpinBox(std::string const &name)
detail::LabelBuilder makeTextLabel(std::string const &text)
detail::HBoxLayoutBuilder makeHBoxLayout(std::string const &name="")
detail::IntSliderBuilder makeIntSlider(std::string const &name)
This file offers overloads of toIce() and fromIce() functions for STL container types.
IceUtil::Handle< class PropertyDefinitionContainer > PropertyDefinitionsPtr
PropertyDefinitions smart pointer type.
std::vector< T > max(const std::vector< T > &v1, const std::vector< T > &v2)
SimplePeriodicTask(Ts...) -> SimplePeriodicTask< std::function< void(void)> >
std::vector< T > min(const std::vector< T > &v1, const std::vector< T > &v2)
Derived & addChild(WidgetPtr const &child)