34 BosonCamera::~BosonCamera()
43 camera_info = std::shared_ptr<camera_info_manager::CameraInfoManager>(
46 image_pub = it->advertiseCamera(
"image_raw", 1);
58 ROS_INFO(
"flir_boson_usb - Got frame_id: %s.", frame_id.c_str());
59 ROS_INFO(
"flir_boson_usb - Got dev: %s.", dev_path.c_str());
60 ROS_INFO(
"flir_boson_usb - Got frame rate: %f.", frame_rate);
61 ROS_INFO(
"flir_boson_usb - Got video mode: %s.", video_mode_str.c_str());
62 ROS_INFO(
"flir_boson_usb - Got zoom enable: %s.", (zoom_enable ?
"true" :
"false"));
63 ROS_INFO(
"flir_boson_usb - Got sensor type: %s.", sensor_type_str.c_str());
64 ROS_INFO(
"flir_boson_usb - Got camera_info_url: %s.", camera_info_url.c_str());
66 if (video_mode_str ==
"RAW16")
70 else if (video_mode_str ==
"YUV")
77 ROS_ERROR(
"flir_boson_usb - Invalid video_mode value provided. Exiting.");
80 if (sensor_type_str ==
"Boson_320" ||
81 sensor_type_str ==
"boson_320")
86 else if (sensor_type_str ==
"Boson_640" ||
87 sensor_type_str ==
"boson_640")
95 ROS_ERROR(
"flir_boson_usb - Invalid sensor_type value provided. Exiting.");
104 ROS_INFO(
"flir_boson_usb - camera_info_url could not be validated. Publishing with unconfigured camera.");
133 unsigned int max1 = 0;
134 unsigned int min1 = 0xFFFF;
135 unsigned int value1, value2, value3, value4;
138 for (i = 0; i <
height; i++)
140 for (j = 0; j <
width; j++)
142 value1 = input_16.at<uchar>(
i, j * 2 + 1) & 0xFF;
143 value2 = input_16.at<uchar>(
i, j * 2) & 0xFF;
144 value3 = (value1 << 8) + value2;
154 for (
int i = 0; i <
height; i++)
156 for (
int j = 0; j <
width; j++)
158 value1 = input_16.at<uchar>(
i, j * 2 + 1) & 0xFF;
159 value2 = input_16.at<uchar>(
i, j * 2) & 0xFF;
160 value3 = (value1 << 8) + value2;
161 value4 = ((255 * (value3 - min1))) / (max1 - min1);
163 output_8->at<uchar>(
i, j) = static_cast<uint8_t>(value4 & 0xFF);
171 if ((
fd = open(
dev_path.c_str(), O_RDWR)) < 0)
173 ROS_ERROR(
"flir_boson_usb - ERROR : OPEN. Invalid Video Device.");
178 if (ioctl(
fd, VIDIOC_QUERYCAP, &
cap) < 0)
180 ROS_ERROR(
"flir_boson_usb - ERROR : VIDIOC_QUERYCAP. Video Capture is not available.");
184 if (!(
cap.capabilities & V4L2_CAP_VIDEO_CAPTURE))
186 ROS_ERROR(
"flir_boson_usb - The device does not handle single-planar video capture.");
190 struct v4l2_format format;
196 format.fmt.pix.pixelformat = V4L2_PIX_FMT_Y16;
217 format.fmt.pix.pixelformat = V4L2_PIX_FMT_YVU420;
223 format.type = V4L2_BUF_TYPE_VIDEO_CAPTURE;
224 format.fmt.pix.width =
width;
225 format.fmt.pix.height =
height;
228 if (ioctl(
fd, VIDIOC_S_FMT, &format) < 0)
230 ROS_ERROR(
"flir_boson_usb - VIDIOC_S_FMT error. The camera does not support the requested video format.");
239 struct v4l2_requestbuffers bufrequest;
240 bufrequest.type = V4L2_BUF_TYPE_VIDEO_CAPTURE;
241 bufrequest.memory = V4L2_MEMORY_MMAP;
242 bufrequest.count = 1;
244 if (ioctl(
fd, VIDIOC_REQBUFS, &bufrequest) < 0)
246 ROS_ERROR(
"flir_boson_usb - VIDIOC_REQBUFS error. The camera failed to allocate a buffer.");
257 bufferinfo.type = V4L2_BUF_TYPE_VIDEO_CAPTURE;
263 ROS_ERROR(
"flir_boson_usb - VIDIOC_QUERYBUF error. Failed to retreive buffer information.");
273 ROS_ERROR(
"flir_boson_usb - mmap error. Failed to create a memory map for buffer.");
282 if (ioctl(
fd, VIDIOC_STREAMON, &type) < 0)
284 ROS_ERROR(
"flir_boson_usb - VIDIOC_STREAMON error. Failed to activate streaming on the camera.");
300 int luma_width =
width;
301 int color_space = CV_8UC1;
318 if (ioctl(
fd, VIDIOC_STREAMOFF, &type) < 0 )
320 ROS_ERROR(
"flir_boson_usb - VIDIOC_STREAMOFF error. Failed to disable streaming on the camera.");
333 sensor_msgs::CameraInfoPtr
334 ci(
new sensor_msgs::CameraInfo(
camera_info->getCameraInfo()));
341 ROS_ERROR(
"flir_boson_usb - VIDIOC_QBUF error. Failed to queue the image buffer.");
348 ROS_ERROR(
"flir_boson_usb - VIDIOC_DQBUF error. Failed to dequeue the image buffer.");
362 Mat mask_mat, masked_img;
363 threshold(
thermal16_linear, mask_mat, 0, 255, CV_THRESH_BINARY|CV_THRESH_OTSU);
367 Mat d_out_img, norm_image, d_norm_image, gamma_corrected_image, d_gamma_corrected_image;
369 masked_img.convertTo(d_out_img, CV_64FC1);
370 normalize(d_out_img, d_norm_image, 0, 1, NORM_MINMAX, CV_64FC1);
371 pow(d_out_img, gamma, d_gamma_corrected_image);
372 d_gamma_corrected_image.convertTo(gamma_corrected_image, CV_8UC1);
373 normalize(gamma_corrected_image, gamma_corrected_image, 0, 255, NORM_MINMAX, CV_8UC1);
376 int erosion_size = 5;
377 Mat top_hat_img, kernel = getStructuringElement(MORPH_ELLIPSE,
378 Size(2 * erosion_size + 1, 2 * erosion_size + 1));
379 morphologyEx(gamma_corrected_image, top_hat_img, MORPH_TOPHAT, kernel);
387 ci->header.stamp =
pub_image->header.stamp;
400 ci->header.stamp =
pub_image->header.stamp;
416 ci->header.stamp =
pub_image->header.stamp;
cv::Mat thermal16_linear_zoom
void publish(const sensor_msgs::Image &image, const sensor_msgs::CameraInfo &info) const
void agcBasicLinear(const cv::Mat &input_16, cv::Mat *output_8, const int &height, const int &width)
std::shared_ptr< image_transport::ImageTransport > it
void captureAndPublish(const ros::TimerEvent &evt)
cv_bridge::CvImage cv_img
std::string sensor_type_str
struct v4l2_buffer bufferinfo
ros::NodeHandle & getPrivateNodeHandle() const
std::string video_mode_str
CvImagePtr cvtColor(const CvImageConstPtr &source, const std::string &encoding)
bool param(const std::string ¶m_name, T ¶m_val, const T &default_val) const
Timer createTimer(Rate r, Handler h, Obj o, bool oneshot=false, bool autostart=true) const
ros::NodeHandle & getNodeHandle() const
std::string camera_info_url
sensor_msgs::ImagePtr pub_image
ROSCPP_DECL void shutdown()
struct v4l2_capability cap
#define PLUGINLIB_EXPORT_CLASS(class_type, base_class_type)
sensor_msgs::ImagePtr toImageMsg() const
image_transport::CameraPublisher image_pub
std::shared_ptr< camera_info_manager::CameraInfoManager > camera_info