FixedCamera crashes with an inappropriate point array shape #316
Open
Description
Hello!
I am getting started with the library and I want to make a quick demo of how the motion estimator works. I run the following code as is shown in the examples from the docs and it is crashing. I provide my code and the traceback
Script:
from norfair import Video, FixedCamera
from norfair.camera_motion import MotionEstimator
motion_estimator = MotionEstimator()
video = Video(input_path="video.mp4")
fixed_camera = FixedCamera()
for frame in video:
coord_transformations = motion_estimator.update(frame)
bigger_frame = fixed_camera.adjust_frame(frame, coord_transformations)
video.write(bigger_frame)
Traceback:
Traceback (most recent call last):
File "workdir/visualization_baseline.py", line 14, in <module>
bigger_frame = fixed_camera.adjust_frame(frame, coord_transformations)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "env_path/lib/python3.11/site-packages/norfair/drawing/fixed_camera.py", line 103, in adjust_frame
coord_transformation.rel_to_abs(top_left[::-1]).round().astype(int)[::-1]
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "env_path/lib/python3.11/site-packages/norfair/camera_motion.py", line 158, in rel_to_abs
points_with_ones = np.hstack((points, ones))
^^^^^^^^^^^^^^^^^^^^^^^^^
File "env_path/lib/python3.11/site-packages/numpy/core/shape_base.py", line 357, in hstack
return _nx.concatenate(arrs, 0, dtype=dtype, casting=casting)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
ValueError: all the input arrays must have same number of dimensions, but the array at index 0 has 1 dimension(s) and the array at index 1 has 2 dimension(s)
It can be seen that the top_left
is an array of shape (2, )
, but hstack
needs an array of shape (num_points, 2)
, so the error arises.
Has anyone encountered this behaviour?
Environment:
- OS: Ubuntu 22.04
- Python version: 3.11.5
- Norfair version: 2.2.0