Get and store distortion matrix
This commit is contained in:
parent
06300f9f4a
commit
5210c35627
|
@ -10,6 +10,8 @@ using namespace godot;
|
|||
|
||||
void UltraleapImage::_bind_methods() {
|
||||
ClassDB::bind_method(D_METHOD("get_data"), &UltraleapImage::get_data);
|
||||
ClassDB::bind_method(D_METHOD("get_distortion_matrix"), &UltraleapImage::get_distortion_matrix);
|
||||
ClassDB::bind_method(D_METHOD("get_matrix_version"), &UltraleapImage::get_matrix_version);
|
||||
}
|
||||
|
||||
void UltraleapImage::fill_images_data(Ref<UltraleapImage> left, Ref<UltraleapImage> right, const LEAP_IMAGE* images) {
|
||||
|
@ -21,14 +23,17 @@ void UltraleapImage::fill_images_data(Ref<UltraleapImage> left, Ref<UltraleapIma
|
|||
return;
|
||||
}
|
||||
|
||||
// We'll shove data 8 bytes by 8 bytes to go fast
|
||||
PackedInt64Array temp_left = PackedInt64Array();
|
||||
PackedInt64Array temp_right = PackedInt64Array();
|
||||
|
||||
uint32_t tot_pixels = height * width;
|
||||
|
||||
uint64_t* data_left = (uint64_t*)((uint8_t*)images->data + images->offset);
|
||||
uint64_t* data_right = (uint64_t*)((uint8_t*)(images + 1)->data + (images + 1)->offset);
|
||||
|
||||
// Fill the data 8 bytes at a time
|
||||
for (uint32_t i = 0; i < tot_pixels / 8; i++) {
|
||||
uint64_t* data_left = (uint64_t*)((uint8_t*)images->data + images->offset);
|
||||
uint64_t* data_right = (uint64_t*)((uint8_t*)(images + 1)->data + (images + 1)->offset);
|
||||
uint64_t pixel_left = data_left[i];
|
||||
uint64_t pixel_right = data_right[i];
|
||||
temp_left.push_back(pixel_left);
|
||||
|
@ -37,4 +42,32 @@ void UltraleapImage::fill_images_data(Ref<UltraleapImage> left, Ref<UltraleapIma
|
|||
|
||||
left->data = temp_left.to_byte_array();
|
||||
right->data = temp_right.to_byte_array();
|
||||
|
||||
// Check and store left image distortion matrix
|
||||
if (left->matrix_version != images->matrix_version) {
|
||||
left->matrix_version = images->matrix_version;
|
||||
left->distortion_matrix.clear();
|
||||
|
||||
for (uint32_t i = 0; i < 64; i++) {
|
||||
for (uint32_t j = 0; j < 64; j++) {
|
||||
float x = images->distortion_matrix->matrix[i][j].x;
|
||||
float y = images->distortion_matrix->matrix[i][j].y;
|
||||
left->distortion_matrix.push_back(Vector2(x, y));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Check and store left image distortion matrix
|
||||
if (right->matrix_version != (images + 1)->matrix_version) {
|
||||
right->matrix_version = (images + 1)->matrix_version;
|
||||
right->distortion_matrix.clear();
|
||||
|
||||
for (uint32_t i = 0; i < 64; i++) {
|
||||
for (uint32_t j = 0; j < 64; j++) {
|
||||
float x = images->distortion_matrix->matrix[i][j].x;
|
||||
float y = images->distortion_matrix->matrix[i][j].y;
|
||||
right->distortion_matrix.push_back(Vector2(x, y));
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
|
@ -18,13 +18,18 @@ class UltraleapImage : public Resource {
|
|||
|
||||
public:
|
||||
PackedByteArray data = PackedByteArray();
|
||||
PackedVector2Array distortion_matrix = PackedVector2Array();
|
||||
|
||||
// Getters / Setters
|
||||
|
||||
PackedByteArray get_data() { return data; }
|
||||
PackedVector2Array get_distortion_matrix() { return distortion_matrix; }
|
||||
uint64_t get_matrix_version() { return matrix_version; }
|
||||
|
||||
static void fill_images_data(Ref<UltraleapImage> left, Ref<UltraleapImage> right, const LEAP_IMAGE* images);
|
||||
|
||||
uint64_t matrix_version = 999;
|
||||
|
||||
protected:
|
||||
static void _bind_methods();
|
||||
};
|
||||
|
|
|
@ -151,7 +151,7 @@ void UltraleapHandTracking::serviceMessageLoop() {
|
|||
while (_isRunning) {
|
||||
result = LeapPollConnection(connectionHandle, 100, &msg);
|
||||
|
||||
if (result != eLeapRS_Success) {
|
||||
if (result != eLeapRS_Success && result != eLeapRS_Timeout) {
|
||||
UtilityFunctions::print(UltraleapTypes::ultraleap_result_to_string(result));
|
||||
continue;
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue