相机时间戳 赋值逻辑错误
demo 的MVcam.cpp文件 相机时间戳写入到head里面的时候你们居然放在receive函数里面 这就导致传输延迟也被计算进去 应该放到trigger里面 我只能说这个错误有点低级了 我说我跑FAST-LIVO2怎么图片老是延迟一秒左右
void MvCam::Receive(void *handle, const std::string &name) { unsigned int last_count = 0; MV_FRAME_OUT st_out_frame; CamData cam_data; Messenger &messenger = Messenger::GetInstance(); while (is_running) { memset(&st_out_frame, 0, sizeof(MV_FRAME_OUT)); int n_ret = MV_CC_GetImageBuffer(handle, &st_out_frame, 10); if (n_ret == MV_OK) { MVCC_FLOATVALUE expose_time; n_ret = MV_CC_GetExposureTime(handle, &expose_time); if (n_ret != MV_OK) { LOG(ERROR) << "Get ExposureTime fail! n_ret [0x" << std::hex << n_ret << "]"; } // 这里的time_stamp_us是相机触发时间,需要加上曝光时间的一半,以获得相机拍摄的时间 if (params.find(name) == params.end()) { LOG(ERROR) << "cam: " << name << " not found!"; } else { if (uint64_t time; GET_LAST_TRIGGER_STATUS(params[name], time)) { cam_data.time_stamp_us = time + static_cast<uint64_t>(expose_time.fCurValue / 2.); } else { LOG(ERROR) << "Trigger cam: " << name << " not found!"; } } MvGvspPixelType en_dst_pixel_type = PixelType_Gvsp_Undefined; unsigned int n_channel_num = 0; // 如果是彩色则转成RGB8 if (IsColor(st_out_frame.stFrameInfo.enPixelType)) { n_channel_num = 3; en_dst_pixel_type = PixelType_Gvsp_RGB8_Packed; } // 如果是黑白则转换成Mono8 else if (IsMono(st_out_frame.stFrameInfo.enPixelType)) { n_channel_num = 1; en_dst_pixel_type = PixelType_Gvsp_Mono8; } if (n_channel_num != 0) { cam_data.name = name; if (en_dst_pixel_type == PixelType_Gvsp_Mono8) { cam_data.image = GMat(st_out_frame.stFrameInfo.nHeight, st_out_frame.stFrameInfo.nWidth, GMatType<uint8_t, 1>::Type, st_out_frame.pBufAddr) .Clone(); } if (en_dst_pixel_type == PixelType_Gvsp_RGB8_Packed) { cam_data.image = GMat(st_out_frame.stFrameInfo.nHeight, st_out_frame.stFrameInfo.nWidth, GMatType<uint8_t, 3>::Type, st_out_frame.pBufAddr) .Clone(); } messenger.PubStruct(name, &cam_data, sizeof(cam_data)); if (last_count == 0) { last_count = st_out_frame.stFrameInfo.nFrameNum; } else { last_count++; if (last_count != st_out_frame.stFrameInfo.nFrameNum) { LOG(WARNING) << "Loss of data from cam connection : " << last_count; last_count = 0; } } } } if (nullptr != st_out_frame.pBufAddr) { n_ret = MV_CC_FreeImageBuffer(handle, &st_out_frame); if (n_ret != MV_OK) { LOG(ERROR) << "Free Image Buffer fail! n_ret [0x" << std::hex << n_ret << "]"; } } std::this_thread::sleep_for(std::chrono::milliseconds{2}); } }
目前读取图像的一个单独的逻辑。读取到图像后,使用同步板的时间戳赋值。这样相机图像的时间戳与传输图像时间无关。这里默认同步板传输时间戳的时间快于相机传输相机照片的时间。 @cyn4676086 有问题说问题,不要攻击。