camera_markers.cpp
Go to the documentation of this file.
1 /*
2  * Visualization marker for camera alignment
3  * Copyright (C) 2018 Copter Express Technologies
4  *
5  * Author: Oleg Kalachev <okalachev@gmail.com>
6  *
7  * Distributed under MIT License (available at https://opensource.org/licenses/MIT).
8  * The above copyright notice and this permission notice shall be included in all
9  * copies or substantial portions of the Software.
10  */
11 
12 #include <string>
13 #include <ros/ros.h>
14 #include <sensor_msgs/CameraInfo.h>
15 #include <visualization_msgs/Marker.h>
16 #include <visualization_msgs/MarkerArray.h>
17 
18 using namespace visualization_msgs;
19 
21 std::string camera_frame;
22 
23 MarkerArray createMarkers() {
24  MarkerArray markers;
25 
26  Marker lens;
27  lens.header.frame_id = camera_frame;
28  lens.ns = "camera_markers";
29  lens.id = 0;
30  lens.action = Marker::ADD;
31  lens.type = visualization_msgs::Marker::CYLINDER;
32  lens.frame_locked = true;
33  lens.scale.x = 0.013 * markers_scale;
34  lens.scale.y = 0.013 * markers_scale;
35  lens.scale.z = 0.015 * markers_scale;
36  lens.color.r = 0.3;
37  lens.color.g = 0.3;
38  lens.color.b = 0.3;
39  lens.color.a = 0.9;
40  lens.pose.position.z = 0.0075 * markers_scale;
41  lens.pose.orientation.w = 1;
42 
43  Marker board;
44  board.header.frame_id = camera_frame;
45  board.ns = "camera_markers";
46  board.id = 1;
47  board.action = Marker::ADD;
48  board.type = Marker::CUBE;
49  board.frame_locked = true;
50  board.scale.x = 0.024 * markers_scale;
51  board.scale.y = 0.024 * markers_scale;
52  board.scale.z = 0.001 * markers_scale;
53  board.color.r = 0.0;
54  board.color.g = 0.8;
55  board.color.b = 0.0;
56  board.color.a = 0.9;
57  board.pose.orientation.w = 1;
58 
59  Marker wire;
60  wire.header.frame_id = camera_frame;
61  wire.ns = "camera_markers";
62  wire.id = 2;
63  wire.action = Marker::ADD;
64  wire.type = Marker::CUBE;
65  wire.frame_locked = true;
66  wire.scale.x = 0.014 * markers_scale;
67  wire.scale.y = 0.04 * markers_scale;
68  wire.scale.z = 0.001 * markers_scale;
69  wire.color.r = 0.9;
70  wire.color.g = 0.9;
71  wire.color.b = 1.0;
72  wire.color.a = 0.8;
73  wire.pose.position.x = 0;
74  wire.pose.position.y = (0.01 + 0.02) * markers_scale;
75  wire.pose.position.z = 0.002 * markers_scale;
76  wire.pose.orientation.w = 1;
77 
78  markers.markers.push_back(lens);
79  markers.markers.push_back(board);
80  markers.markers.push_back(wire);
81 
82  return markers;
83 }
84 
85 int main(int argc, char **argv)
86 {
87  ros::init(argc, argv, "camera_markers", ros::init_options::AnonymousName);
88  ros::NodeHandle nh, nh_priv("~");
89 
90  nh_priv.param("scale", markers_scale, 1.0);
91 
92  // wait for camera info
93  auto camera_info = ros::topic::waitForMessage<sensor_msgs::CameraInfo>("camera_info", nh);
94  camera_frame = camera_info->header.frame_id;
95 
96  ros::Publisher markers_pub = nh.advertise<visualization_msgs::MarkerArray>("camera_markers", 1, true);
97  markers_pub.publish(createMarkers());
98 
99  ROS_INFO("Camera markers initialized");
100  ros::spin();
101 }
ros::NodeHandle nh
double markers_scale
ROSCPP_DECL void init(int &argc, char **argv, const std::string &name, uint32_t options=0)
bool param(const std::string &param_name, T &param_val, const T &default_val) const
void publish(const boost::shared_ptr< M > &message) const
std::string camera_frame
#define ROS_INFO(...)
Publisher advertise(const std::string &topic, uint32_t queue_size, bool latch=false)
ROSCPP_DECL void spin()
MarkerArray createMarkers()
int main(int argc, char **argv)


clover
Author(s): Oleg Kalachev , Artem Smirnov
autogenerated on Mon Feb 28 2022 22:08:29