Package: cyber-record
cyber_recordcyber_recordis a cyber record file offline parse tool. You can usecyber_recordto read messages from record file, or write messages to the record file.Quick startFirst install "cyber_record" by the following command.pip3installcyber_record
//orupdateversion
pip3installcyber_record-Upython versionIf protobuf prompt requires python>=3.7, you can install python3.7+ and switch default python versionsudo apt install python3.8
sudo update-alternatives --install /usr/bin/python3 python3 /usr/bin/python3.8 2demo recordYou can download a apollo demo record fromdemo_sensor_data_for_visionCommand line modeYou can easily get the information in the record file by the following command.Infocyber_record infowill output the statistics of the record file.$cyber_recordinfo-fexample.record.00000

record_file:example.record.00000
version:1.0
begin_time:2021-07-2317:12:15.114944
end_time:2021-07-2317:12:15.253911
duration:0.14s
size:477.55KByte
message_number:34channel_number:8/apollo/planning,apollo.planning.ADCTrajectory,1/apollo/routing_request,apollo.routing.RoutingRequest,0/apollo/monitor,apollo.common.monitor.MonitorMessage,0/apollo/routing_response,apollo.routing.RoutingResponse,0/apollo/routing_response_history,apollo.routing.RoutingResponse,1/apollo/localization/pose,apollo.localization.LocalizationEstimate,15/apollo/canbus/chassis,apollo.canbus.Chassis,15/apollo/prediction,apollo.prediction.PredictionObstacles,2Echocyber_record echowill print the message of the specified topic to the terminal.$cyber_recordecho-fexample.record.00000-t/apollo/canbus/chassis

engine_started:truespeed_mps:0.0
throttle_percentage:0.0
brake_percentage:0.0
driving_mode:COMPLETE_AUTO_DRIVE
gear_location:GEAR_DRIVE
header{timestamp_sec:1627031535.112813module_name:"SimControl"sequence_num:76636}Or you can reference thecyber_recordin the python file byfromcyber_record.recordimportRecordrecoverIf you find record file is missing index, you can recover the file bycyber_record recover.It is best to backup the file before recover!!!Generate the file descriptor set. Must be executed in theapollodirectory.descriptor_set_outis the descriptor file namemodules/drivers/proto/sensor_image.protothe message define proto fileprotoc --include_imports --descriptor_set_out=tmp modules/drivers/proto/sensor_image.protoor you can use absolute path.descriptor_set_outis the descriptor file nameproto_paththe apollo home path/home/zero/01opencode/apollo/modules/drivers/proto/sensor_image.protoproto file absolute pathprotoc --include_imports --descriptor_set_out=tmp --proto_path=/home/zero/01opencode/apollo /home/zero/01opencode/apollo/modules/drivers/proto/sensor_image.protoRecover the record file.broken.recordis the file need repair/apollo/sensor/camera/front_6mm/imagethe topic of the need repair messagetmpthe descriptor file generated in the previous stepapollo.drivers.Imagethe message type of the need repair messagecyber_record recover -f broken.record -t /apollo/sensor/camera/front_6mm/image -d tmp -m apollo.drivers.ImageExamplesBelow are some examples to help you read and write messages from record files.1. Read messagesYou can read messages directly from the record file in the following ways.fromcyber_record.recordimportRecordfile_name="20210521122747.record.00000"record=Record(file_name)fortopic,message,tinrecord.read_messages():print("{},{},{}".format(topic,type(message),t))The following is the output log of the program/apollo/localization/pose, <class 'LocalizationEstimate'>, 1627031535246897752
/apollo/canbus/chassis, <class 'Chassis'>, 1627031535246913234
/apollo/canbus/chassis, <class 'Chassis'>, 1627031535253680838Filter ReadYou can also read messages filtered by topics and time. This will improve the speed of parsing messages.defread_filter_by_both():record=Record(file_name)fortopic,message,tinrecord.read_messages('/apollo/canbus/chassis',\start_time=1627031535164278940,end_time=1627031535215164773):print("{},{},{}".format(topic,type(message),t))2. Parse messagesTo avoid introducing too many dependencies, you can save messages byrecord_msg.pip3 install record_msg -Urecord_msgprovides 3 types of interfacescsv formatyou can useto_csvto format objects so that they can be easily saved in csv format.f=open("message.csv",'w')writer=csv.writer(f)defparse_pose(pose):'''save pose to csv file'''line=to_csv([pose.header.timestamp_sec,pose.pose])writer.writerow(line)f.close()imageyou can useImageParserto parse and save images.image_parser=ImageParser(output_path='../test')fortopic,message,tinrecord.read_messages():iftopic=="/apollo/sensor/camera/front_6mm/image":image_parser.parse(message)# or use timestamp as image file name# image_parser.parse(image, t)lidaryou can usePointCloudParserto parse and save pointclouds.pointcloud_parser=PointCloudParser('../test')fortopic,message,tinrecord.read_messages():iftopic=="/apollo/sensor/lidar32/compensator/PointCloud2":pointcloud_parser.parse(message)# other modes, default is 'ascii'# pointcloud_parser.parse(message, mode='binary')# pointcloud_parser.parse(message, mode='binary_compressed')3. Write messagesYou can now also build record by messages. You can write pb_message byrecord.write.defwrite_message():pb_map=map_pb2.Map()pb_map.header.version='hello'.encode()withRecord(write_file_name,mode='w')asrecord:record.write('/apollo/map',pb_map,int(time.time()*1e9))Its application scenario is to convert dataset into record files. Please note that it must be written in chronological order.If you want to write raw message, you should first useBuilderto help convert raw data to pb_message.imageYou can write image to record file like below.ImageBuilderwill help you convert image to pb_image.encodingshould bergb8,bgr8orgray,y.defwrite_image():image_builder=ImageBuilder()write_file_name="example_w.record.00002"withRecord(write_file_name,mode='w')asrecord:img_path='test.jpg'pb_image=image_builder.build(img_path,encoding='rgb8')record.write('/apollo/sensor/camera/front_6mm/image',pb_image,int(time.time()*1e9))lidarYou can write image to record file like below.PointCloudBuilderwill help you convert pcd file to pb_point_cloud.defwrite_point_cloud():point_cloud_builder=PointCloudBuilder()write_file_name="example_w.record.00003"withRecord(write_file_name,mode='w')asrecord:pcd_path='test.pcd'pb_point_cloud=point_cloud_builder.build(pcd_path)record.write('/apollo/sensor/lidar32/compensator/PointCloud2',pb_point_cloud,int(time.time()*1e9))