recorder/camera.cpp
Go to the documentation of this file.
1 /*
2  * Copyright 2015 Aldebaran
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  * http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  *
16 */
17 
18 /*
19 * LOCAL includes
20 */
21 #include "camera.hpp"
22 
23 namespace naoqi
24 {
25 namespace recorder
26 {
27 
28 CameraRecorder::CameraRecorder( const std::string& topic_, float buffer_frequency ):
29  buffer_frequency_(buffer_frequency),
30  buffer_duration_( helpers::recorder::bufferDefaultDuration ),
31  counter_(1)
32 {
33  topic_info_ = topic_ + "/camera_info";
34  topic_img_ = topic_ + "/image_raw";
35 }
36 
37 void CameraRecorder::write(const sensor_msgs::ImagePtr& img, const sensor_msgs::CameraInfo& camera_info)
38 {
39  if (!img->header.stamp.isZero()) {
40  gr_->write(topic_img_, *img, img->header.stamp);
41  }
42  else {
43  gr_->write(topic_img_, *img);
44  }
45  if (!camera_info.header.stamp.isZero()) {
46  gr_->write(topic_info_, camera_info, camera_info.header.stamp);
47  }
48  else {
49  gr_->write(topic_info_, camera_info);
50  }
51 }
52 
54 {
55  boost::mutex::scoped_lock lock_write_buffer( mutex_ );
56  boost::circular_buffer< std::pair<sensor_msgs::ImagePtr, sensor_msgs::CameraInfo> >::iterator it;
57  for (it = buffer_.begin(); it != buffer_.end(); it++)
58  {
59  if (it->first != NULL)
60  {
61  write(it->first, it->second);
62  }
63  }
64 }
65 
67 {
68  gr_ = gr;
69  conv_frequency_ = conv_frequency;
70  max_counter_ = static_cast<int>(conv_frequency/buffer_frequency_);
71  buffer_size_ = static_cast<size_t>(buffer_duration_*(conv_frequency/max_counter_));
72  buffer_.resize(buffer_size_);
73  is_initialized_ = true;
74 }
75 
76 void CameraRecorder::bufferize( const sensor_msgs::ImagePtr& img, const sensor_msgs::CameraInfo& camera_info )
77 {
78  boost::mutex::scoped_lock lock_bufferize( mutex_ );
79  if (counter_ < max_counter_)
80  {
81  counter_++;
82  }
83  else
84  {
85  counter_ = 1;
86  buffer_.push_back(std::make_pair(img, camera_info));
87  }
88 }
89 
91 {
92  boost::mutex::scoped_lock lock_bufferize( mutex_ );
93  buffer_size_ = static_cast<size_t>(duration*(conv_frequency_/max_counter_));
94  buffer_duration_ = duration;
95  buffer_.set_capacity(buffer_size_);
96 }
97 
98 } //publisher
99 } // naoqi
CameraRecorder(const std::string &topic, float buffer_frequency)
void setBufferDuration(float duration)
void writeDump(const ros::Time &time)
void bufferize(const sensor_msgs::ImagePtr &img, const sensor_msgs::CameraInfo &camera_info)
void write(const sensor_msgs::ImagePtr &img, const sensor_msgs::CameraInfo &camera_info)
boost::shared_ptr< naoqi::recorder::GlobalRecorder > gr_
static const float bufferDefaultDuration
void reset(boost::shared_ptr< naoqi::recorder::GlobalRecorder > gr, float conv_frequency)
boost::circular_buffer< std::pair< sensor_msgs::ImagePtr, sensor_msgs::CameraInfo > > buffer_


naoqi_driver
Author(s): Karsten Knese
autogenerated on Sat Feb 15 2020 03:24:26