eskaur / zivid-turntable

Turntable project from Zivid PlayTime 2020
BSD 3-Clause "New" or "Revised" License
1 stars 1 forks source link

'zivid.calibration' has no attribute 'custom_feature_points' #13

Closed nishantsnair closed 2 years ago

nishantsnair commented 3 years ago

Running your code in 'process_data.py' with some pcd's I have collected with arucos I get an error when the code tries to determine the transform from feature_a to feature_b with in line 80: detection_result_a = zivid.calibration.custom_feature_points(features_a) line 81: detection_result_b = zivid.calibration.custom_feature_points(features_b) in calibration.py

the error is AttributeError: module 'zivid.calibration' has no attribute 'custom_feature_points'. This makes sense since in zivid.calibration there is a detect_feature_points method but no custom_feature_points. Can you please help

eskaur commented 3 years ago

Yeah sorry, this is not an official Zivid code-sample unfortunately, so there is no guarantee that it will work. So far the function "custom_feature_points()" only exists in an internal version of the SDK. It has not been released (yet).

nishantsnair commented 3 years ago

Is it possible to just get that function? I think I have everything else already.

Maybe that is too much to ask. Even a description of that method might be useful. I can work on my own implementation.

eskaur commented 3 years ago

I could give you the Python function, but it would not work because the back-end does not exist in any version of the SDK.

Anyway, there is a way forward for you, but it would require some implementation on your part. I assume you intended to do the following two-step procedure:

  1. Call detection_result_a = zivid.calibration.custom_feature_points(features_a) etc
  2. Send the DetectionResult list into calibrate_multi_camera(detection_results) to get transformation matrices.

Since I can't make the first point work for you, you'd have to replace both yourself. What you can do is find (or implement) an algorithm for calculating the so-called "rigid transform" between two sets of feature points. That should give you essentially the same functionality. If you google that you should be able to find something.

nishantsnair commented 2 years ago

Hi, as you recommended a little over a year ago I found a rigid 3D transform here: https://github.com/nghiaho12/rigid_transform_3D/blob/master/test_rigid_transform_3D.py the function def _get_transform() in /zivid_turntable/calibration.py was rewritten to:

def _get_transform( marker_set_a: Dict[int, ArucoMarker], marker_set_b: Dict[int, ArucoMarker] ) -> np.ndarray:

features_a, features_b = _get_common_feature_points(
    marker_set_a, marker_set_b)

rot, tran = rigid_transform_3D(
    features_a.transpose(), features_b.transpose())

affine = np.zeros((4, 4))

affine[:3, :3] = rot[:,:3]

affine[:3, 3] = tran[:, 0]

affine[3, 3] = 1

return affine

The result though is very wrong image can you help me spot any differences between what I am doing and what the internal sdk methods are. Also are these now available to the public?

eskaur commented 2 years ago

Hi @nishantsnair ! I don't have time to look into details at the moment, but I have a quick idea for you to check: It could be that this rigid transform function you found is defined in the opposite direction. Can you try one of these things?:

nishantsnair commented 2 years ago
  • Swap the order of features_a.transpose(), features_b.transpose(). or
  • Invert your affine transform before returning it.

That was easy :) it works now! a night of sleepless debugging and this was it!