news 2026/6/25 11:07:51

解析图漾相机录制的bag视频文件

作者头像

张小明

前端开发工程师

1.2k 24
文章封面图
解析图漾相机录制的bag视频文件

文章目录

  • 前言
  • 1.PercipioViewer软件操作步骤
    • 1.1 加载录制的bag文件
    • 1.2 设置视频播放速度
  • 2.C++代码解析bag文件
    • 2.1 运行编译后的Demo
  • 3.常见问题FAQ
    • 3.1 编译过程中报错

前言

Percipio Viewer 软件支持录制相机采集图像时的视频。录制视频过程中,支持调整部分参数,不支持关闭/开启数据流。

前提条件
根据录制内容,开启对应数据流。

1.PercipioViewer软件操作步骤

1.1 加载录制的bag文件

1.2 设置视频播放速度


主要有0.2X,0.5X,1X,1.5X和2X五种速度可以设置。

2.C++代码解析bag文件

具体解析bag文件的代码,可从如下链接下载:

git clone git@gitee.com:jet_zou/percipio_viewer_stream_decode.git

详细的代码如下:

/* * @Description: * @Author: zxy * @Date: 2023-09-08 09:07:05 * @LastEditors: zxy * @LastEditTime: 2024-04-16 18:27:04 */#include"utils.hpp"#definePERCIPIO_DPETH_RENDER_ENABLE#ifdefPERCIPIO_DPETH_RENDER_ENABLE#include"DepthRender.hpp"#endif#pragmapack(1)structStreamSize{int32_tm_width;int32_tm_height;};structStreamInfo{floatf_sacle_unit;StreamSize depthSize;StreamSize colorSize;StreamSize irLeftSize;StreamSize irRightSize;int32_tReserved[10];};structRecordInfo{uint32_trecord_info_version;TY_DEVICE_BASE_INFO dev_info;int32_tdepthStreaming;int32_tcolorStreaming;int32_tlIrStreaming;int32_trIrStreaming;int32_tallComps;//TY_CAMERA_CALIB_INFO depth_calib_info;TY_CAMERA_CALIB_INFO color_calib_info;chartycam_version[32];uint64_trecord_duration_start;uint64_trecord_duration_stop;};#pragmapack()#defineIMAGE_HEADER_SIZE(4096)staticintGetFileSize(constchar*file_name,uint64_t*file_byte_size){FILE*fp;if(!(fp=fopen(file_name,"rb"))){return(-1);}#ifdefined(_WIN32)||defined(_WIN64)#if_MSC_VER>=1400if(_fseeki64(fp,(uint64_t)(0),SEEK_END)){fclose(fp);return(-1);}*file_byte_size=_ftelli64(fp);#else#errorVisual Studio version is less than8.0(VS2005)!#endif#elseif(fseeko(fp,(uint64_t)(0),SEEK_END)){fclose(fp);return(-1);}*file_byte_size=ftello(fp);#endiffclose(fp);return0;}staticinlineintparseImage(constTY_IMAGE_DATA&image,cv::Mat*pDepth,cv::Mat*pLeftIR,cv::Mat*pRightIR,cv::Mat*pColor){if(pDepth&&image.componentID==TY_COMPONENT_DEPTH_CAM){if(image.pixelFormat==TY_PIXEL_FORMAT_XYZ48)*pDepth=cv::Mat(image.height,image.width,CV_16SC3,image.buffer).clone();else*pDepth=cv::Mat(image.height,image.width,CV_16U,image.buffer).clone();}elseif(pLeftIR&&image.componentID==TY_COMPONENT_IR_CAM_LEFT)parseIrFrame(&image,pLeftIR);elseif(pRightIR&&image.componentID==TY_COMPONENT_IR_CAM_RIGHT)parseIrFrame(&image,pRightIR);elseif(pColor&&image.componentID==TY_COMPONENT_RGB_CAM)parseColorFrame(&image,pColor);elsereturn-1;return0;}intmain(intargc,char*argv[]){if(argc!=2){printf("Need to specify a file!\n");return-1;}uint64_tfile_length;interror_code=GetFileSize(argv[1],&file_length);if(error_code<0){printf("Could not get file size!\n");return-1;}FILE*fp=fopen(argv[1],"rb");if(fp==NULL){printf("Failed to open file!\n");return-1;}std::vector<char>header_buffer(IMAGE_HEADER_SIZE);size_t cnt=fread(&header_buffer[0],1,IMAGE_HEADER_SIZE,fp);if(cnt<IMAGE_HEADER_SIZE){printf("File format error!\n");fclose(fp);return-1;}RecordInfo*pBagInfo=(RecordInfo*)&header_buffer[0];StreamInfo*pStreamInfo=(StreamInfo*)(&header_buffer[0]+sizeof(RecordInfo));printf("tycam version : %s\n",pBagInfo->tycam_version);printf("deice sn : %s\n",pBagInfo->dev_info.id);booldepthStreaming=pBagInfo->depthStreaming;boolcolorStreaming=pBagInfo->colorStreaming;boollIrStreaming=pBagInfo->lIrStreaming;boolrIrStreaming=pBagInfo->rIrStreaming;boolcomponent=pBagInfo->allComps;int32_tstream_cnt_per_frame=0;//stream_sizeif(depthStreaming)stream_cnt_per_frame++;if(colorStreaming)stream_cnt_per_frame++;if(lIrStreaming)stream_cnt_per_frame++;if(rIrStreaming)stream_cnt_per_frame++;uint64_trecord_duration=pBagInfo->record_duration_stop-pBagInfo->record_duration_start;std::vector<char>stream_header(sizeof(int32_t)*5);uint64_tstream_length=file_length-IMAGE_HEADER_SIZE;uint32_tframe_size=0;for(int32_ti=0;i<stream_cnt_per_frame;i++){cnt=fread(&stream_header[0],sizeof(int32_t)*5,1,fp);frame_size+=((int32_t*)(&stream_header[0]))[4];fseek(fp,((int32_t*)(&stream_header[0]))[4],SEEK_CUR);}uint32_tplayback_frame_rate,playback_total_frames;uint64_tplayback_duration=record_duration*1000*1000;if(record_duration>1000){playback_frame_rate=static_cast<uint32_t>((stream_length/(frame_size+sizeof(int32_t)*5*stream_cnt_per_frame))/(record_duration/1000));playback_total_frames=static_cast<uint32_t>(stream_length/(frame_size+sizeof(int32_t)*5*stream_cnt_per_frame));}else{playback_frame_rate=1;playback_total_frames=1;}fseek(fp,IMAGE_HEADER_SIZE,SEEK_SET);#ifdefPERCIPIO_DPETH_RENDER_ENABLEDepthRender depthViewer;#endifuint64_tstart_time=0;uint64_tend_time=0;TY_IMAGE_DATA image;std::vector<char>framebuffer[4];while(true){start_time=getSystemTime();if(feof(fp)){printf("Repeat!\n");fseek(fp,IMAGE_HEADER_SIZE,SEEK_SET);}fread(&stream_header[0],sizeof(int32_t)*5,1,fp);image.componentID=((int32_t*)(&stream_header[0]))[0];image.width=((int32_t*)(&stream_header[0]))[1];image.height=((int32_t*)(&stream_header[0]))[2];image.pixelFormat=((int32_t*)(&stream_header[0]))[3];image.size=((int32_t*)(&stream_header[0]))[4];if(image.componentID==TY_COMPONENT_DEPTH_CAM){if(framebuffer[0].size()<image.size)framebuffer[0].resize(image.size);fread(&framebuffer[0][0],image.size,1,fp);image.buffer=&framebuffer[0][0];}elseif(image.componentID==TY_COMPONENT_RGB_CAM){if(framebuffer[1].size()<image.size)framebuffer[1].resize(image.size);fread(&framebuffer[1][0],image.size,1,fp);image.buffer=&framebuffer[1][0];}elseif(image.componentID==TY_COMPONENT_IR_CAM_LEFT){if(framebuffer[2].size()<image.size)framebuffer[2].resize(image.size);fread(&framebuffer[2][0],image.size,1,fp);image.buffer=&framebuffer[2][0];}elseif(image.componentID==TY_COMPONENT_IR_CAM_RIGHT){if(framebuffer[3].size()<image.size)framebuffer[3].resize(image.size);fread(&framebuffer[3][0],image.size,1,fp);image.buffer=&framebuffer[3][0];}else{printf("Invalid component id!\n");exit(-1);}cv::Mat depth,leftIR,rightIR,color;parseImage(image,&depth,&leftIR,&rightIR,&color);if(!depth.empty()){#ifdefPERCIPIO_DPETH_RENDER_ENABLEcv::Mat dep_render=depthViewer.Compute(depth);if(!dep_render.empty())cv::imshow("depth",dep_render);#elsecv::imshow("depth",depth*15);#endif}if(!leftIR.empty())cv::imshow("leftIR",leftIR);if(!rightIR.empty())cv::imshow("rightIR",rightIR);if(!color.empty())cv::imshow("color",color);intkey=cv::waitKey(1);if((key&0xff)=='q')break;end_time=getSystemTime();floatdelt=((playback_duration/(uint64_t)playback_total_frames)/(1000*1000)-(end_time-start_time))/(stream_cnt_per_frame);if(delt>0)MSleep(static_cast<uint32_t>(delt));}fclose(fp);printf("Main done!\n");return0;}

2.1 运行编译后的Demo

使用Cmake-gui界面,编译完成后,使用VisualStudio软件生成解决方案后,生成对应的.exe文件,之后使用如下命令,即可解析.bag文件。

.\ decode test.exe.\bag名字

3.常见问题FAQ

3.1 编译过程中报错

在使用Cmake进行编译时,需要引入Opencv路径

版权声明: 本文来自互联网用户投稿,该文观点仅代表作者本人,不代表本站立场。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如若内容造成侵权/违法违规/事实不符,请联系邮箱:809451989@qq.com进行投诉反馈,一经查实,立即删除!
网站建设 2026/6/24 17:16:18

Monorepo架构下管理多个FLUX.1-dev模型实例的最佳实践

Monorepo架构下管理多个FLUX.1-dev模型实例的最佳实践 在当今AIGC&#xff08;人工智能生成内容&#xff09;浪潮中&#xff0c;文生图模型的迭代速度前所未有。像FLUX.1-dev这样基于Flow Transformer架构、拥有120亿参数的大型多模态模型&#xff0c;正被广泛用于创意设计、广…

作者头像 李华
网站建设 2026/6/25 17:20:29

收藏!大模型时代,产品经理如何突破成长天花板?

大模型革命使人机交互从"用户适配机器"转变为"机器适配用户"&#xff0c;颠覆了传统AI产品经理"场景穷举语义适配"的工作范式。产品经理需从"技术边界理解框架性规划"维度升级能力&#xff0c;掌握大模型基础原理、业务域定义和结构化…

作者头像 李华
网站建设 2026/6/26 1:35:59

在Windows环境下部署Seed-Coder-8B-Base的详细步骤

在Windows环境下部署Seed-Coder-8B-Base的详细步骤 在当今软件开发领域&#xff0c;代码生成AI正从云端服务走向本地化、私有化的部署模式。尤其是在金融、军工、教育等对数据安全要求极高的场景中&#xff0c;开发者越来越倾向于将智能编程助手“握在自己手里”——不依赖网络…

作者头像 李华
网站建设 2026/6/25 9:04:53

C语言中的面向对象思想

1.静态数组管理多个结构体变量对于c语言当一个结构体要创建多个变量时&#xff0c;若我们分开管理就会比较难以管理&#xff0c;但是我们可以通过结构体数组&#xff08;对象数组&#xff09;的形式对其进行管理。我们看下面这段程序&#xff1a;#include <stdio.h> #inc…

作者头像 李华
网站建设 2026/6/25 4:51:57

微信视频号直播弹幕抓取技术实现与架构解析

微信视频号直播弹幕抓取技术实现与架构解析 【免费下载链接】wxlivespy 微信视频号直播间弹幕信息抓取工具 项目地址: https://gitcode.com/gh_mirrors/wx/wxlivespy 在直播数据获取领域&#xff0c;微信视频号直播弹幕抓取面临诸多技术挑战&#xff1a;数据加密传输、用…

作者头像 李华
网站建设 2026/6/25 18:00:08

火山引擎AI大模型平台迁移至Qwen3-VL-30B的成本效益分析

火山引擎AI大模型平台迁移至Qwen3-VL-30B的成本效益分析 在智能文档处理、金融投研辅助和医疗影像解读等专业场景中&#xff0c;企业对“能看懂图、会推理、可解释”的AI系统需求正迅速攀升。传统的OCR规则引擎组合早已力不从心——它们能提取数字&#xff0c;却无法理解“为何…

作者头像 李华