-
Notifications
You must be signed in to change notification settings - Fork 4
/
driver.cpp
189 lines (147 loc) · 5.92 KB
/
driver.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
// Copyright [2015] Takashi Ogura<[email protected]>
#include "driver.h"
#include <string>
namespace
{
const double DEFAULT_RATE = 30.0;
const int32_t PUBLISHER_BUFFER_SIZE = 1;
}
boost::shared_ptr<cv_camera::MVCameraCapture> sCamera;
namespace cv_camera
{
void configure_callback(mv_camera::CameraConfig &config, uint32_t level);
Driver::Driver(ros::NodeHandle &private_node, ros::NodeHandle &camera_node)
: private_node_(private_node),
camera_node_(camera_node)
{
}
void Driver::setup()
{
double hz(DEFAULT_RATE);
int32_t device_id(0);
std::string device_path("");
std::string frame_id("camera");
std::string file_path("");
private_node_.getParam("device_id", device_id);
private_node_.getParam("frame_id", frame_id);
private_node_.getParam("rate", hz);
int32_t image_width(640);
int32_t image_height(480);
camera_.reset(new MVCameraCapture(camera_node_,
"image_raw",
PUBLISHER_BUFFER_SIZE,
frame_id));
sCamera = camera_;
std::cout << "openin the camera device id \n";
camera_->open(device_id);
if (private_node_.getParam("image_width", image_width))
{
if (!camera_->setWidth(image_width))
{
ROS_WARN("fail to set image_width");
}
}
if (private_node_.getParam("image_height", image_height))
{
if (!camera_->setHeight(image_height))
{
ROS_WARN("fail to set image_height");
}
}
dynamic_reconfigure::Server<mv_camera::CameraConfig>::CallbackType f;
f = boost::bind(&configure_callback, _1, _2);
server_.setCallback(f);
/*
camera_->setPropertyFromParam(CV_CAP_PROP_POS_MSEC, "cv_cap_prop_pos_msec");
camera_->setPropertyFromParam(CV_CAP_PROP_POS_AVI_RATIO, "cv_cap_prop_pos_avi_ratio");
camera_->setPropertyFromParam(CV_CAP_PROP_FRAME_WIDTH, "cv_cap_prop_frame_width");
camera_->setPropertyFromParam(CV_CAP_PROP_FRAME_HEIGHT, "cv_cap_prop_frame_height");
camera_->setPropertyFromParam(CV_CAP_PROP_FPS, "cv_cap_prop_fps");
camera_->setPropertyFromParam(CV_CAP_PROP_FOURCC, "cv_cap_prop_fourcc");
camera_->setPropertyFromParam(CV_CAP_PROP_FRAME_COUNT, "cv_cap_prop_frame_count");
camera_->setPropertyFromParam(CV_CAP_PROP_FORMAT, "cv_cap_prop_format");
camera_->setPropertyFromParam(CV_CAP_PROP_MODE, "cv_cap_prop_mode");
camera_->setPropertyFromParam(CV_CAP_PROP_BRIGHTNESS, "cv_cap_prop_brightness");
camera_->setPropertyFromParam(CV_CAP_PROP_CONTRAST, "cv_cap_prop_contrast");
camera_->setPropertyFromParam(CV_CAP_PROP_SATURATION, "cv_cap_prop_saturation");
camera_->setPropertyFromParam(CV_CAP_PROP_HUE, "cv_cap_prop_hue");
camera_->setPropertyFromParam(CV_CAP_PROP_GAIN, "cv_cap_prop_gain");
camera_->setPropertyFromParam(CV_CAP_PROP_EXPOSURE, "cv_cap_prop_exposure");
camera_->setPropertyFromParam(CV_CAP_PROP_CONVERT_RGB, "cv_cap_prop_convert_rgb");
camera_->setPropertyFromParam(CV_CAP_PROP_RECTIFICATION, "cv_cap_prop_rectification");
camera_->setPropertyFromParam(CV_CAP_PROP_ISO_SPEED, "cv_cap_prop_iso_speed");
#ifdef CV_CAP_PROP_WHITE_BALANCE_U
camera_->setPropertyFromParam(CV_CAP_PROP_WHITE_BALANCE_U, "cv_cap_prop_white_balance_u");
#endif // CV_CAP_PROP_WHITE_BALANCE_U
#ifdef CV_CAP_PROP_WHITE_BALANCE_V
camera_->setPropertyFromParam(CV_CAP_PROP_WHITE_BALANCE_V, "cv_cap_prop_white_balance_v");
#endif // CV_CAP_PROP_WHITE_BALANCE_V
#ifdef CV_CAP_PROP_BUFFERSIZE
camera_->setPropertyFromParam(CV_CAP_PROP_BUFFERSIZE, "cv_cap_prop_buffersize");
#endif // CV_CAP_PROP_BUFFERSIZE
*/
rate_.reset(new ros::Rate(hz));
}
void configure_callback(mv_camera::CameraConfig &config, uint32_t level)
{
ROS_INFO("Reconfiguring...");
double exposure = config.Exposure_time;
double gain = config.Gain;
cv::Vec3b colorGain(config.Red_gain, config.Green_gain, config.Blue_gain);
sCamera->setExposure(exposure);
sCamera->setGain(gain);
if (config.Trigger_WB)
sCamera->triggerWhiteBalance();
else
{
sCamera->setColorGain(colorGain);
}
bool autoExposureMode = config.Exposure_auto != "Manual";
bool autoGainMode = config.Gain_auto != "Manual";
sCamera->setAutoExposureMode(autoExposureMode);
std::cout << "AutoExposure: " << autoExposureMode << std::endl;
std::cout << "AutoGain: " << autoGainMode << std::endl;
/*
// Set relative intensity of LEDs.
ROS_DEBUG("INTENSITY: %d", config.intensity);
LeddarSetProperty(handler, PID_LED_INTENSITY, 0, config.intensity);
// Set automatic LED intensity.
ROS_DEBUG("AUTO INTENSITY: %s", config.auto_intensity ? "true" : "false");
LeddarSetProperty(handler, PID_AUTOMATIC_LED_INTENSITY, 0,
config.auto_intensity);
// Set number of accumulations to perform.
ROS_DEBUG("ACCUMULATIONS: %d", config.accumulations);
LeddarSetProperty(handler, PID_ACCUMULATION_EXPONENT, 0,
config.accumulations);
// Set number of oversamplings to perform between base samples.
ROS_DEBUG("OVERSAMPLING: %d", config.oversampling);
LeddarSetProperty(handler, PID_OVERSAMPLING_EXPONENT, 0,
config.oversampling);
// Set number of base samples acquired.
ROS_DEBUG("BASE SAMPLES: %d", config.base_point_count);
LeddarSetProperty(handler, PID_BASE_POINT_COUNT, 0,
config.base_point_count);
// Set offset to increase detection threshold.
ROS_DEBUG("THRESHOLD OFFSET: %d", config.threshold_offset);
LeddarSetProperty(handler, PID_THRESHOLD_OFFSET, 0,
config.threshold_offset);
// Set detection of 2 objects close to each other.
ROS_DEBUG("DEMERGING: %s", config.object_demerging ? "true" : "false");
LeddarSetProperty(handler, PID_OBJECT_DEMERGING, 0,
config.object_demerging);
// Write changes to Leddar.
LeddarWriteConfiguration(handler);
*/
}
void Driver::proceed()
{
if (camera_->capture())
{
camera_->publish();
}
rate_->sleep();
}
Driver::~Driver()
{
}
} // namespace cv_camera