7 std::string cameraFrame, std::string targetFrame, std::string linkFrame)
8 :
Camera(nh,
std::move(serial),
std::move(fileCameraPath), fixed,
std::move(cameraFrame),
std::move(targetFrame),
11 cameraInfo = boost::make_shared<sensor_msgs::CameraInfo>();
29 capture.parameters()[itmCameras] =
serial;
32 NxLibItem imageNode =
cameraNode[itmImages][itmRaw];
33 if (imageNode.isArray())
35 imageNode = imageNode[0];
68 NxLibItem calibrationNode =
cameraNode[itmCalibration];
82 for (
int row = 0; row < 3; row++)
84 for (
int column = 0; column < 3; column++)
86 info->K[3 * row + column] = calibrationNode[itmCamera][column][row].asDouble();
87 info->P[4 * row + column] = info->K[3 * row + column];
90 info->R[3 * row + column] = 1.0f;
107 ensenso_camera_msgs::RequestDataMonoResult result;
108 ensenso_camera_msgs::RequestDataMonoFeedback feedback;
110 bool publishResults = goal->publish_results;
111 if (!goal->publish_results && !goal->include_results_in_response)
113 publishResults =
true;
116 bool requestRectified = goal->request_rectified_images;
117 if (!goal->request_rectified_images && !goal->request_raw_images)
119 requestRectified =
true;
126 feedback.images_acquired =
true;
129 if (goal->request_raw_images)
132 cameraInfo->header.stamp = rawImages[0]->header.stamp;
134 if (goal->include_results_in_response)
136 for (
auto const& image : rawImages)
138 result.raw_images.push_back(*image);
150 if (requestRectified)
152 NxLibCommand rectify(cmdRectifyImages,
serial);
153 rectify.parameters()[itmCameras] =
serial;
159 if (goal->include_results_in_response)
161 for (
auto const& image : rectifiedImages)
163 result.rectified_images.push_back(*image);
182 ensenso_camera_msgs::SetParameterResult result;
186 result.parameter_file_applied =
false;
187 if (!goal->parameter_file.empty())
189 result.parameter_file_applied =
loadSettings(goal->parameter_file);
190 if (!result.parameter_file_applied)
192 server->setAborted(result);
198 NxLibCommand synchronize(cmdSynchronize,
serial);
199 synchronize.parameters()[itmCameras] =
serial;
200 synchronize.execute();
208 for (
auto const& parameter : goal->parameters)
222 ensenso_camera_msgs::LocatePatternMonoResult result;
223 ensenso_camera_msgs::LocatePatternMonoFeedback feedback;
227 int numberOfShots = goal->number_of_shots;
228 if (numberOfShots < 1)
233 std::vector<MonoCalibrationPattern> patterns;
235 for (
int i = 0; i < numberOfShots; i++)
241 imageTimestamp = timestamp;
245 if (i == (numberOfShots - 1))
248 feedback.images_acquired =
true;
252 bool clearBuffer = (i == 0);
254 if (patterns.empty())
256 result.found_pattern =
false;
261 if (patterns.size() > 1)
269 result.found_pattern =
true;
270 result.mono_patterns.resize(patterns.size());
271 for (
size_t i = 0; i < patterns.size(); i++)
273 patterns[i].writeToMessage(result.mono_patterns[i]);
279 if (!goal->target_frame.empty())
281 patternFrame = goal->target_frame;
284 result.frame = patternFrame;
286 if (patterns.size() > 1)
291 result.mono_pattern_poses.resize(patternPoses.size());
292 for (
size_t i = 0; i < patternPoses.size(); i++)
303 result.mono_pattern_poses.resize(1);
307 if (!goal->tf_frame.empty())
309 if (patterns.size() == 1)
311 geometry_msgs::TransformStamped transform =
transformFromPose(result.mono_pattern_poses[0], goal->tf_frame);
316 ROS_WARN(
"Cannot publish the pattern pose in TF, because there are " 317 "multiple patterns!");
330 NxLibCommand(cmdDiscardPatterns,
serial).execute();
334 collectPattern.parameters()[itmCameras] =
serial;
335 collectPattern.parameters()[itmDecodeData] =
true;
338 collectPattern.execute();
340 catch (NxLibException& e)
342 if (e.getErrorCode() == NxLibExecutionFailed)
344 if (collectPattern.result()[itmErrorSymbol] == errPatternNotFound ||
345 collectPattern.result()[itmErrorSymbol] == errPatternNotDecodable)
353 std::vector<MonoCalibrationPattern> result;
355 for (
int i = 0; i < collectPattern.result()[itmPatterns][0][
serial].count(); i++)
357 result.emplace_back(collectPattern.result()[itmPatterns][0][
serial][i][itmPattern]);
361 NxLibItem pattern = collectPattern.result()[itmPatterns][0][
serial];
363 for (
size_t i = 0; i < result.size(); i++)
365 for (
int j = 0; j < pattern[i][itmPoints].count(); j++)
367 NxLibItem pointNode = pattern[i][itmPoints][j];
369 ensenso_camera_msgs::ImagePoint point;
370 point.x = pointNode[0].asDouble();
371 point.y = pointNode[1].asDouble();
372 result[i].points.push_back(point);
381 bool latestPatternOnly)
const 386 estimatePatternPose.parameters()[itmType] = itmMonocular;
387 if (latestPatternOnly)
389 estimatePatternPose.parameters()[itmAverage] =
false;
391 int patternCount = NxLibItem()[itmParameters][itmPatternCount].asInt();
392 estimatePatternPose.parameters()[itmFilter][itmOr][0][itmAnd][0][itmType] = valIndex;
393 estimatePatternPose.parameters()[itmFilter][itmOr][0][itmAnd][0][itmValue] = patternCount - 1;
397 estimatePatternPose.parameters()[itmAverage] =
true;
399 estimatePatternPose.execute();
401 ROS_ASSERT(estimatePatternPose.result()[itmPatterns].count() == 1);
412 estimatePatternPose.parameters()[itmAverage] =
false;
413 estimatePatternPose.parameters()[itmType] = itmMonocular;
414 estimatePatternPose.parameters()[itmFilter][itmCameras] =
serial;
416 estimatePatternPose.execute();
418 int numberOfPatterns = estimatePatternPose.result()[itmPatterns].count();
420 std::vector<geometry_msgs::TransformStamped> result;
421 result.reserve(numberOfPatterns);
423 for (
int i = 0; i < numberOfPatterns; i++)
void fillDistortionParamsFromNxLib(NxLibItem const &distortionItem, sensor_msgs::CameraInfoPtr const &info)
void publish(const sensor_msgs::Image &image, const sensor_msgs::CameraInfo &info) const
void onRequestData(ensenso_camera_msgs::RequestDataMonoGoalConstPtr const &goal)
ros::Time timestampFromNxLibNode(NxLibItem const &node)
std::unique_ptr< LocatePatternMonoServer > locatePatternServer
MonoCamera(ros::NodeHandle nh, std::string serial, std::string fileCameraPath, bool fixed, std::string cameraFrame, std::string targetFrame, std::string linkFrame)
void updateGlobalLink(ros::Time time=ros::Time::now(), std::string frame="", bool useCachedTransformation=false) const
ros::Time capture() const override
void fillCameraInfoFromNxLib(sensor_msgs::CameraInfoPtr const &info, bool rectified=false)
sensor_msgs::CameraInfoPtr rectifiedCameraInfo
image_transport::CameraPublisher rectifiedImagePublisher
std::unique_ptr< SetParameterServer > setParameterServer
void onSetParameter(ensenso_camera_msgs::SetParameterGoalConstPtr const &goal) override
std::vector< geometry_msgs::TransformStamped > estimatePatternPoses(ros::Time imageTimestamp=ros::Time::now(), std::string const &targetFrame="") const override
std::vector< MonoCalibrationPattern > collectPattern(bool clearBuffer=false) const
void onLocatePattern(ensenso_camera_msgs::LocatePatternMonoGoalConstPtr const &goal)
const std::string PLUMB_BOB
geometry_msgs::TransformStamped estimatePatternPose(ros::Time imageTimestamp=ros::Time::now(), std::string const &targetFrame="", bool latestPatternOnly=false) const override
geometry_msgs::TransformStamped transformFromPose(geometry_msgs::PoseStamped const &pose, std::string const &childFrame)
std::unique_ptr< RequestDataMonoServer > requestDataServer
virtual void startServers() const
void startServers() const override
void loadParameterSet(std::string name)
geometry_msgs::PoseStamped stampedPoseFromTransform(geometry_msgs::TransformStamped const &transform)
image_transport::CameraPublisher rawImagePublisher
tf2::Transform poseFromNxLib(NxLibItem const &node)
#define START_NXLIB_ACTION(ACTION_NAME, ACTION_SERVER)
#define PREEMPT_ACTION_IF_REQUESTED
sensor_msgs::CameraInfoPtr cameraInfo
void updateCameraInfo() override
std::vector< sensor_msgs::ImagePtr > imagesFromNxLibNode(NxLibItem const &node, std::string const &frame)
void saveParameterSet(std::string name)
void fillBasicCameraInfoFromNxLib(sensor_msgs::CameraInfoPtr const &info) const
virtual ensenso_camera_msgs::ParameterPtr readParameter(std::string const &key) const
#define FINISH_NXLIB_ACTION(ACTION_NAME)
bool loadSettings(std::string const &jsonFile, bool saveAsDefaultParameters=false)
std::unique_ptr< tf2_ros::TransformBroadcaster > transformBroadcaster