tryolabs / norfair

Lightweight Python library for adding real-time multi-object tracking to any detector.
https://tryolabs.github.io/norfair/
BSD 3-Clause "New" or "Revised" License
2.34k stars 237 forks source link

error: (-28:Unknown error code -28) The input arrays should have at least 4 corresponding point sets to calculate Homography in function 'findHomography' #299

Closed utility-aagrawal closed 5 months ago

utility-aagrawal commented 5 months ago

Hi,

Would you know why I am getting this error? I see in the code here that you check for minimum 4 pairs of points before findHomography but still getting the error:

https://github.com/tryolabs/norfair/blob/009a1b171ab14336d79d7b7b02dfa5f45066c79e/norfair/camera_motion.py#L220

File "/home/aagrawal/face_detection/real_videos/open_source_face_detection.py", line 232, in main coord_transformation = motion_estimator.update(frame) #, mask) File "/home/aagrawal/face_detection/face_venv/lib/python3.10/site-packages/norfair/camera_motion.py", line 396, in update update_prvs, coord_transformations = self.transformations_getter( File "/home/aagrawal/face_detection/face_venv/lib/python3.10/site-packages/norfair/camera_motion.py", line 216, in call homography_matrix, points_used = cv2.findHomography( cv2.error: OpenCV(4.9.0) /io/opencv/modules/calib3d/src/fundam.cpp:385: error: (-28:Unknown error code -28) The input arrays should have at least 4 corresponding point sets to calculate Homography in function 'findHomography'

aguscas commented 5 months ago

The reason might be because that bug was fixed not long ago, but the fix is still not part of the latest release. Maybe try installing Norfair from the master branch:

pip install git+https://github.com/tryolabs/norfair.git@master#egg=norfair

Tell me if this fixes the issue.

utility-aagrawal commented 5 months ago

Thanks a lot, @aguscas !

Installing from master seemed to work. I do get the following warning though:

image

Does this mean that transformation will be skipped for the frame in case of this issue but everything else will work fine?

aguscas commented 5 months ago

Everything should work fine. That means that the coord_transformation will not be updated in that frame (the MotionEstimator will return the latest transformation it could estimate). As long as that doesn't happen often it shouldn't be a problem with the coord_transformation, since typically a single frame shouldn't affect that much at the coordinate_transformation.

utility-aagrawal commented 5 months ago

Makes sense! Closing this issue. Again, thanks so much for your help!

aguscas commented 5 months ago

If you want to avoid having that warning (so that you always estimate the transformation), you can also try setting the max_points argument of the MotionEstimator to a higher value (so that it tries sampling more points), or the min_distance argument to a smaller value (so that we allow to sample points that are closer to each other).

utility-aagrawal commented 5 months ago

For now, it's not an issue for me but I'll experiment with those two parameters. Thanks a lot!