已合并
透传imu数据到AR Engine,新增标定参数 #940
wzp111创建于 6月9日
透传imu数据到AR Engine,新增标定参数 #940
已合并
共 4 个文件变更+91-1
| @@ -165,12 +165,14 @@ const int32_t AR_ACC_TYPE = 2; | |||
| 165 | const int32_t AR_GYRO_TYPE = 3; | 165 | const int32_t AR_GYRO_TYPE = 3; |
| 166 | const int32_t AR_DATA_STREAM_WIDTH = 640; | 166 | const int32_t AR_DATA_STREAM_WIDTH = 640; |
| 167 | const int32_t AR_MODE_TAG_OFFSET = 40; | 167 | const int32_t AR_MODE_TAG_OFFSET = 40; |
| 168 | -const uint32_t UNIFORM_METADATA_LEN = 2000; | 168 | +const uint32_t UNIFORM_METADATA_LEN = 3000; |
| 169 | const uint32_t AR_META_DATA_KEY = 8000; | 169 | const uint32_t AR_META_DATA_KEY = 8000; |
| 170 | const uint32_t AR_MODE_ENABLE_IMU = 9; | 170 | const uint32_t AR_MODE_ENABLE_IMU = 9; |
| 171 | const int32_t INT32_T_BYTE_LEN = 4; | 171 | const int32_t INT32_T_BYTE_LEN = 4; |
| 172 | const int32_t UINT64_T_BYTE_LEN = 8; | 172 | const int32_t UINT64_T_BYTE_LEN = 8; |
| 173 | const int32_t FLOAT_T_BYTE_LEN = 4; | 173 | const int32_t FLOAT_T_BYTE_LEN = 4; |
| 174 | +const int32_t CAMERA_EXTRINSIC_NUM = 16; | ||
| 175 | +const int32_t CAMERA_INTRINSIC_NUM = 4; | ||
| 174 | 176 | ||
| 175 | const std::string CHANNEL_DISCONNECTED = "disconnected"; | 177 | const std::string CHANNEL_DISCONNECTED = "disconnected"; |
| 176 | const std::string PRODUCER = "producer"; | 178 | const std::string PRODUCER = "producer"; |
| @@ -76,6 +76,7 @@ private: | |||
| 76 | bool SetIMUTOBuffer(const DCameraBuffer& sharedMemory, const std::shared_ptr<DataBuffer>& buffer); | 76 | bool SetIMUTOBuffer(const DCameraBuffer& sharedMemory, const std::shared_ptr<DataBuffer>& buffer); |
| 77 | bool UnmarshalIMUData(const std::string& jsonStr, std::vector<uint8_t>& result); | 77 | bool UnmarshalIMUData(const std::string& jsonStr, std::vector<uint8_t>& result); |
| 78 | bool UnmarshalIMUArray(cJSON *imuJsonArray, std::vector<uint8_t>& result, int32_t currentType); | 78 | bool UnmarshalIMUArray(cJSON *imuJsonArray, std::vector<uint8_t>& result, int32_t currentType); |
| 79 | + bool UnmarshalCameraIntrin(const std::string& jsonStr, std::vector<uint8_t>& result); | ||
| 79 | int32_t CheckPreconditions(const std::shared_ptr<DataBuffer>& buffer); | 80 | int32_t CheckPreconditions(const std::shared_ptr<DataBuffer>& buffer); |
| 80 | 81 | ||
| 81 | const uint32_t DCAMERA_PRODUCER_MAX_BUFFER_SIZE = 30; | 82 | const uint32_t DCAMERA_PRODUCER_MAX_BUFFER_SIZE = 30; |
| @@ -294,6 +294,56 @@ bool DCameraStreamDataProcessProducer::UnmarshalIMUArray(cJSON *imuJsonArray, | |||
| 294 | return true; | 294 | return true; |
| 295 | } | 295 | } |
| 296 | 296 | ||
| 297 | +bool DCameraStreamDataProcessProducer::UnmarshalCameraIntrin(const std::string& jsonStr, std::vector<uint8_t>& result) | ||
| 298 | +{ | ||
| 299 | + cJSON *rootValue = cJSON_Parse(jsonStr.c_str()); | ||
| 300 | + CHECK_NULL_RETURN((rootValue == nullptr), false); | ||
| 301 | + cJSON *extrinsicJson = cJSON_GetObjectItemCaseSensitive(rootValue, "extrinsic"); | ||
| 302 | + CHECK_AND_FREE_RETURN_RET_LOG((extrinsicJson == nullptr || !cJSON_IsArray(extrinsicJson)), false, rootValue, | ||
| 303 | + "extrinsic parse fail."); | ||
| 304 | + int32_t extrinsicCount = cJSON_GetArraySize(extrinsicJson); | ||
| 305 | + CHECK_AND_FREE_RETURN_RET_LOG((extrinsicCount != CAMERA_EXTRINSIC_NUM), false, rootValue, "extrinsic size error"); | ||
| 306 | + for (int32_t i = 0; i < extrinsicCount; i++) { | ||
| 307 | + cJSON *itemJson = cJSON_GetArrayItem(extrinsicJson, i); | ||
| 308 | + CHECK_AND_FREE_RETURN_RET_LOG(!cJSON_IsNumber(itemJson), false, rootValue, | ||
| 309 | + "extrinsic item parse fail."); | ||
| 310 | + float val = static_cast<float>(itemJson->valuedouble); | ||
| 311 | + uint8_t* valBytes = reinterpret_cast<uint8_t*>(&val); | ||
| 312 | + result.insert(result.end(), valBytes, valBytes + FLOAT_T_BYTE_LEN); | ||
| 313 | + } | ||
| 314 | + | ||
| 315 | + cJSON *intrinJson = cJSON_GetObjectItemCaseSensitive(rootValue, "intrin"); | ||
| 316 | + CHECK_AND_FREE_RETURN_RET_LOG((intrinJson == nullptr || !cJSON_IsArray(intrinJson)), false, rootValue, | ||
| 317 | + "intrin parse fail."); | ||
| 318 | + int32_t intrinCount = cJSON_GetArraySize(intrinJson); | ||
| 319 | + CHECK_AND_FREE_RETURN_RET_LOG((intrinCount != CAMERA_INTRINSIC_NUM), false, rootValue, "intrin size error."); | ||
| 320 | + for (int32_t i = 0; i < intrinCount; i++) { | ||
| 321 | + cJSON *itemJson = cJSON_GetArrayItem(intrinJson, i); | ||
| 322 | + CHECK_AND_FREE_RETURN_RET_LOG(!cJSON_IsNumber(itemJson), false, rootValue, | ||
| 323 | + "intrin item parse fail."); | ||
| 324 | + float val = static_cast<float>(itemJson->valuedouble); | ||
| 325 | + uint8_t* valBytes = reinterpret_cast<uint8_t*>(&val); | ||
| 326 | + result.insert(result.end(), valBytes, valBytes + FLOAT_T_BYTE_LEN); | ||
| 327 | + } | ||
| 328 | + | ||
| 329 | + cJSON *rsTimeJson = cJSON_GetObjectItemCaseSensitive(rootValue, "rollingShutterTime"); | ||
| 330 | + CHECK_AND_FREE_RETURN_RET_LOG((rsTimeJson == nullptr || !cJSON_IsNumber(rsTimeJson)), false, | ||
| 331 | + rootValue, "rollingShutterTime parse fail."); | ||
| 332 | + float rollingShutterTime = static_cast<float>(rsTimeJson->valuedouble); | ||
| 333 | + uint8_t* rollingShutterTimeBytes = reinterpret_cast<uint8_t*>(&rollingShutterTime); | ||
| 334 | + result.insert(result.end(), rollingShutterTimeBytes, rollingShutterTimeBytes + FLOAT_T_BYTE_LEN); | ||
| 335 | + | ||
| 336 | + cJSON *delayCam2IMU = cJSON_GetObjectItemCaseSensitive(rootValue, "xmlGyroTimestampOffset"); | ||
| 337 | + CHECK_AND_FREE_RETURN_RET_LOG((delayCam2IMU == nullptr || !cJSON_IsNumber(delayCam2IMU)), | ||
| 338 | + false, rootValue, "xmlGyroTimestampOffset parse fail."); | ||
| 339 | + float xmlGyroTimestampOffset = static_cast<float>(delayCam2IMU->valuedouble); | ||
| 340 | + uint8_t* xmlGyroTimestampOffsetBytes = reinterpret_cast<uint8_t*>(&xmlGyroTimestampOffset); | ||
| 341 | + result.insert(result.end(), xmlGyroTimestampOffsetBytes, xmlGyroTimestampOffsetBytes + FLOAT_T_BYTE_LEN); | ||
| 342 | + | ||
| 343 | + cJSON_Delete(rootValue); | ||
| 344 | + return true; | ||
| 345 | +} | ||
| 346 | + | ||
| 297 | bool DCameraStreamDataProcessProducer::SetIMUTOBuffer(const DCameraBuffer& sharedMemory, | 347 | bool DCameraStreamDataProcessProducer::SetIMUTOBuffer(const DCameraBuffer& sharedMemory, |
| 298 | const std::shared_ptr<DataBuffer>& buffer) | 348 | const std::shared_ptr<DataBuffer>& buffer) |
| 299 | { | 349 | { |
| @@ -307,6 +357,9 @@ bool DCameraStreamDataProcessProducer::SetIMUTOBuffer(const DCameraBuffer& share | |||
| 307 | auto eisInfo = buffer->eisInfo_; | 357 | auto eisInfo = buffer->eisInfo_; |
| 308 | std::vector<uint8_t> imuData; | 358 | std::vector<uint8_t> imuData; |
| 309 | imuData.reserve(UNIFORM_METADATA_LEN); | 359 | imuData.reserve(UNIFORM_METADATA_LEN); |
| 360 | + if (!UnmarshalCameraIntrin(eisInfo.initParams, imuData)) { | ||
| 361 | + return false; | ||
| 362 | + } | ||
| 310 | 363 | ||
| 311 | int32_t frameID = eisInfo.frameId; | 364 | int32_t frameID = eisInfo.frameId; |
| 312 | uint8_t* frameIDBytes = reinterpret_cast<uint8_t*>(&frameID); | 365 | uint8_t* frameIDBytes = reinterpret_cast<uint8_t*>(&frameID); |
| @@ -73,6 +73,12 @@ const std::string IMU_STR = R"({ | |||
| 73 | } | 73 | } |
| 74 | ] | 74 | ] |
| 75 | })"; | 75 | })"; |
| 76 | +const std::string CALIBRATION_STR = R"({ | ||
| 77 | + "extrinsic": [1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1], | ||
| 78 | + "intrin": [1, 1, 1, 1], | ||
| 79 | + "rollingShutterTime": 1, | ||
| 80 | + "xmlGyroTimestampOffset": 1 | ||
| 81 | + })"; | ||
| 76 | } | 82 | } |
| 77 | void DCameraStreamDataProcessProducerTest::SetUpTestCase(void) | 83 | void DCameraStreamDataProcessProducerTest::SetUpTestCase(void) |
| 78 | { | 84 | { |
| @@ -304,6 +310,15 @@ HWTEST_F(DCameraStreamDataProcessProducerTest, dcamera_stream_data_process_produ | |||
| 304 | buffer->eisInfo_.imuData = IMU_STR; | 310 | buffer->eisInfo_.imuData = IMU_STR; |
| 305 | buffer->frameInfo_.rawTime = 1000000; | 311 | buffer->frameInfo_.rawTime = 1000000; |
| 306 | ret = streamProcess->SetIMUTOBuffer(sharedMemory, buffer); | 312 | ret = streamProcess->SetIMUTOBuffer(sharedMemory, buffer); |
| 313 | + EXPECT_EQ(ret, false); | ||
| 314 | + | ||
| 315 | + auto buffer1 = std::make_shared<DataBuffer>(100); | ||
| 316 | + buffer1->eisInfo_.frameId = 1; | ||
| 317 | + buffer1->eisInfo_.frameTimeStamp = 1; | ||
| 318 | + buffer1->eisInfo_.imuData = IMU_STR; | ||
| 319 | + buffer1->eisInfo_.initParams = CALIBRATION_STR; | ||
| 320 | + buffer1->frameInfo_.rawTime = 1000000; | ||
| 321 | + ret = streamProcess->SetIMUTOBuffer(sharedMemory, buffer1); | ||
| 307 | DCameraSrcImuSensor::GetInstance().SetAREnable(TEST_DEVICE_ID, false); | 322 | DCameraSrcImuSensor::GetInstance().SetAREnable(TEST_DEVICE_ID, false); |
| 308 | EXPECT_EQ(ret, false); | 323 | EXPECT_EQ(ret, false); |
| 309 | } | 324 | } |
| @@ -474,6 +489,25 @@ HWTEST_F(DCameraStreamDataProcessProducerTest, dcamera_stream_data_process_produ | |||
| 474 | EXPECT_EQ(ret, true); | 489 | EXPECT_EQ(ret, true); |
| 475 | } | 490 | } |
| 476 | 491 | ||
| 492 | +/** | ||
| 493 | + * @tc.name: dcamera_stream_data_process_producer_test_0012 | ||
| 494 | + * @tc.desc: Verify UnmarshalCameraIntrin func. | ||
| 495 | + * @tc.type: FUNC | ||
| 496 | + * @tc.require: issue | ||
| 497 | + */ | ||
| 498 | +HWTEST_F(DCameraStreamDataProcessProducerTest, dcamera_stream_data_process_producer_test_0012, TestSize.Level1) | ||
| 499 | +{ | ||
| 500 | + std::shared_ptr<DCameraStreamDataProcessProducer> streamProcess = | ||
| 501 | + std::make_shared<DCameraStreamDataProcessProducer>(TEST_DEVICE_ID, TEST_CAMERA_DH_ID_0, STREAM_ID_1, | ||
| 502 | + DCStreamType::CONTINUOUS_FRAME); | ||
| 503 | + std::vector<uint8_t> result; | ||
| 504 | + const std::string str = ""; | ||
| 505 | + auto ret = streamProcess->UnmarshalCameraIntrin(str, result); | ||
| 506 | + EXPECT_EQ(ret, false); | ||
| 507 | + ret = streamProcess->UnmarshalCameraIntrin(CALIBRATION_STR, result); | ||
| 508 | + EXPECT_EQ(ret, true); | ||
| 509 | +} | ||
| 510 | + | ||
| 477 | /** | 511 | /** |
| 478 | * @tc.name: Start_001 | 512 | * @tc.name: Start_001 |
| 479 | * @tc.desc: Verify DCameraStreamDataProcessProducer Start with CONTINUOUS_FRAME stream type. | 513 | * @tc.desc: Verify DCameraStreamDataProcessProducer Start with CONTINUOUS_FRAME stream type. |
解析的json要经过严格校验