当前位置:网站首页>R3live notes: image processing section
R3live notes: image processing section
2022-07-06 21:17:00 【How much is the code? Oneortwo】
1. IMAGE_topic
subscribe :
sub_img = m_ros_node_handle.subscribe(IMAGE_topic.c_str(), 1000000, &R3LIVE::image_callback, this, ros::TransportHints().tcpNoDelay());
Images topic When data is transferred in , Callback function image_callback:
void R3LIVE::image_callback( const sensor_msgs::ImageConstPtr &msg )
{
std::unique_lock< std::mutex > lock( mutex_image_callback );
if ( sub_image_typed == 2 )
{
return; // Avoid subscribe the same image twice.
}
sub_image_typed = 1;
// Determine whether it is the first frame
if ( g_flag_if_first_rec_img )
{
g_flag_if_first_rec_img = 0;
m_thread_pool_ptr->commit_task( &R3LIVE::service_process_img_buffer, this );
}
// Convert the image encoding to BGR8
cv::Mat temp_img = cv_bridge::toCvCopy( msg, sensor_msgs::image_encodings::BGR8 )->image.clone();
// Image data processing
process_image( temp_img, msg->header.stamp.toSec() );
}
Image data processing process_image:
void R3LIVE::process_image( cv::Mat &temp_img, double msg_time )
{
cv::Mat img_get;
if ( temp_img.rows == 0 )
{
cout << "Process image error, image rows =0 " << endl;
return;
}
// The timestamp of this frame is smaller than that of the previous frame error
if ( msg_time < last_accept_time )
{
cout << "Error, image time revert!!" << endl;
return;
}
// The interval between the timestamp of this frame and the timestamp of the previous frame is less than the release frequency error
if ( ( msg_time - last_accept_time ) < ( 1.0 / m_control_image_freq ) * 0.9 )
{
cout << "Error, image time interval wrong!!" << endl;
return;
}
last_accept_time = msg_time;
// In fact, it is the initialization operation when the first image comes in
if ( m_camera_start_ros_tim < 0 )
{
m_camera_start_ros_tim = msg_time;
m_vio_scale_factor = 1280 * m_image_downsample_ratio / temp_img.cols; // 320 * 24
// load_vio_parameters();
// Camera parameter initialization , Including internal reference 、 External reference 、 Distortion parameters, etc
set_initial_camera_parameter( g_lio_state, m_camera_intrinsic.data(), m_camera_dist_coeffs.data(), m_camera_ext_R.data(),
m_camera_ext_t.data(), m_vio_scale_factor );
cv::eigen2cv( g_cam_K, intrinsic );
cv::eigen2cv( g_cam_dist, dist_coeffs );
// TODO QJF: Distortion correction ,opencv Provided correction algorithm that can be used directly , and remap() Combine to handle
// This function is used to calculate the distortion free and corrected conversion relationship , To remap , Express the result in the form of mapping . The undistorted image looks like the original image , It's like this image uses internal parameters as newCameraMatrix And distortion free camera acquisition .
initUndistortRectifyMap( intrinsic, dist_coeffs, cv::Mat(), intrinsic, cv::Size( 1280 / m_vio_scale_factor, 1024 / m_vio_scale_factor ),
CV_16SC2, m_ud_map1, m_ud_map2 );
m_thread_pool_ptr->commit_task( &R3LIVE::service_pub_rgb_maps, this);
m_thread_pool_ptr->commit_task( &R3LIVE::service_VIO_update, this);
m_mvs_recorder.init( g_cam_K, 1280 / m_vio_scale_factor, &m_map_rgb_pts );
m_mvs_recorder.set_working_dir( m_map_output_dir );
}
// Downsampling => Image size again Set up
if ( m_image_downsample_ratio != 1.0 )
{
// Image size again Set up
cv::resize( temp_img, img_get, cv::Size( 1280 / m_vio_scale_factor, 1024 / m_vio_scale_factor ) );
}
else
{
img_get = temp_img; // clone ?
}
std::shared_ptr< Image_frame > img_pose = std::make_shared< Image_frame >( g_cam_K );
// Copy the original image to img_pose
if ( m_if_pub_raw_img )
{
img_pose->m_raw_img = img_get;
}
// Remap , It is the process of placing a pixel at a certain position in an image to a specified position in another image .
// TODO What's the role ?
// INTER_LINEAR – Bilinear interpolation
cv::remap( img_get, img_pose->m_img, m_ud_map1, m_ud_map2, cv::INTER_LINEAR );
cv::imshow("sub Img", img_pose->m_img);
img_pose->m_timestamp = msg_time;
img_pose->init_cubic_interpolation();// Cubic interpolation Cubic interpolation initialization
img_pose->image_equalize();// Histogram equalization processing
m_camera_data_mutex.lock();
m_queue_image_with_pose.push_back( img_pose );
m_camera_data_mutex.unlock();
total_frame_count++;
if ( m_queue_image_with_pose.size() > buffer_max_frame )
{
buffer_max_frame = m_queue_image_with_pose.size();
}
// cout << "Image queue size = " << m_queue_image_with_pose.size() << endl;
}
2. IMAGE_topic_compressed
decompression compressed Format image
subscribe :
sub_img_comp = m_ros_node_handle.subscribe(IMAGE_topic_compressed.c_str(), 1000000, &R3LIVE::image_comp_callback, this, ros::TransportHints().tcpNoDelay());
Callback :
void R3LIVE::image_comp_callback( const sensor_msgs::CompressedImageConstPtr &msg )
{
// The mutex
std::unique_lock< std::mutex > lock2( mutex_image_callback );
if ( sub_image_typed == 1 ) // 0: TBD 1: sub_raw, 2: sub_comp
{
return; // Avoid subscribe the same image twice.
}
sub_image_typed = 2;
g_received_compressed_img_msg.push_back( msg );
if ( g_flag_if_first_rec_img )
{
g_flag_if_first_rec_img = 0;
m_thread_pool_ptr->commit_task( &R3LIVE::service_process_img_buffer, this );
}
return;
}
边栏推荐
- OSPF多区域配置
- Redis insert data garbled solution
- 【滑动窗口】第九届蓝桥杯省赛B组:日志统计
- KDD 2022 | realize unified conversational recommendation through knowledge enhanced prompt learning
- VIM basic configuration and frequently used commands
- MLP (multilayer perceptron neural network) is a multilayer fully connected neural network model.
- Is this the feeling of being spoiled by bytes?
- R語言可視化兩個以上的分類(類別)變量之間的關系、使用vcd包中的Mosaic函數創建馬賽克圖( Mosaic plots)、分別可視化兩個、三個、四個分類變量的關系的馬賽克圖
- 2022 fields Award Announced! The first Korean Xu Long'er was on the list, and four post-80s women won the prize. Ukrainian female mathematicians became the only two women to win the prize in history
- 如何实现常见框架
猜你喜欢
Deployment of external server area and dual machine hot standby of firewall Foundation
【深度学习】PyTorch 1.12发布,正式支持苹果M1芯片GPU加速,修复众多Bug
Infrared thermometer based on STM32 single chip microcomputer (with face detection)
The difference between break and continue in the for loop -- break completely end the loop & continue terminate this loop
对话阿里巴巴副总裁贾扬清:追求大模型,并不是一件坏事
15million employees are easy to manage, and the cloud native database gaussdb makes HR office more efficient
愛可可AI前沿推介(7.6)
Swagger UI教程 API 文档神器
What is the problem with the SQL group by statement
2017 8th Blue Bridge Cup group a provincial tournament
随机推荐
R语言可视化两个以上的分类(类别)变量之间的关系、使用vcd包中的Mosaic函数创建马赛克图( Mosaic plots)、分别可视化两个、三个、四个分类变量的关系的马赛克图
HMS Core 机器学习服务打造同传翻译新“声”态,AI让国际交流更顺畅
R language visualizes the relationship between more than two classification (category) variables, uses mosaic function in VCD package to create mosaic plots, and visualizes the relationship between tw
The biggest pain point of traffic management - the resource utilization rate cannot go up
@GetMapping、@PostMapping 和 @RequestMapping详细区别附实战代码(全)
OneNote 深度评测:使用资源、插件、模版
3D人脸重建:从基础知识到识别/重建方法!
js 根据汉字首字母排序(省份排序) 或 根据英文首字母排序——za排序 & az排序
Performance test process and plan
Reviewer dis's whole research direction is not just reviewing my manuscript. What should I do?
966 minimum path sum
ICML 2022 | Flowformer: 任务通用的线性复杂度Transformer
Opencv learning example code 3.2.3 image binarization
[MySQL] basic use of cursor
愛可可AI前沿推介(7.6)
OSPF multi zone configuration
@PathVariable
R語言可視化兩個以上的分類(類別)變量之間的關系、使用vcd包中的Mosaic函數創建馬賽克圖( Mosaic plots)、分別可視化兩個、三個、四個分類變量的關系的馬賽克圖
15 millions d'employés sont faciles à gérer et la base de données native du cloud gaussdb rend le Bureau des RH plus efficace
嵌入式开发的7大原罪