当前位置:网站首页>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;
}
边栏推荐
- Is this the feeling of being spoiled by bytes?
- 3D face reconstruction: from basic knowledge to recognition / reconstruction methods!
- 代理和反向代理
- 如何实现常见框架
- Replace Internet TV set-top box application through digital TV and broadband network
- Aiko ai Frontier promotion (7.6)
- [MySQL] basic use of cursor
- PG基础篇--逻辑结构管理(事务)
- How do I remove duplicates from the list- How to remove duplicates from a list?
- Notes - detailed steps of training, testing and verification of yolo-v4-tiny source code
猜你喜欢
【力扣刷题】一维动态规划记录(53零钱兑换、300最长递增子序列、53最大子数组和)
【mysql】触发器
每个程序员必须掌握的常用英语词汇(建议收藏)
请问sql group by 语句问题
1500萬員工輕松管理,雲原生數據庫GaussDB讓HR辦公更高效
【力扣刷题】32. 最长有效括号
全网最全的新型数据库、多维表格平台盘点 Notion、FlowUs、Airtable、SeaTable、维格表 Vika、飞书多维表格、黑帕云、织信 Informat、语雀
[MySQL] trigger
ICML 2022 | Flowformer: 任务通用的线性复杂度Transformer
爱可可AI前沿推介(7.6)
随机推荐
JS get array subscript through array content
967- letter combination of telephone number
OneNote 深度评测:使用资源、插件、模版
【力扣刷题】32. 最长有效括号
Nodejs教程之让我们用 typescript 创建你的第一个 expressjs 应用程序
在最长的距离二叉树结点
3D face reconstruction: from basic knowledge to recognition / reconstruction methods!
ACdreamoj1110(多重背包)
'class file has wrong version 52.0, should be 50.0' - class file has wrong version 52.0, should be 50.0
[MySQL] basic use of cursor
基于深度学习的参考帧生成
什么是RDB和AOF
Why does MySQL index fail? When do I use indexes?
面试官:Redis中有序集合的内部实现方式是什么?
Regular expression collection
Yyds dry goods count re comb this of arrow function
968 edit distance
启动嵌入式间:资源有限的系统启动
@Detailed differences among getmapping, @postmapping and @requestmapping, with actual combat code (all)
What is the problem with the SQL group by statement