Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

FixedCamera crashes with an inappropriate point array shape #316

Open
Dentikka opened this issue Apr 23, 2024 · 0 comments
Open

FixedCamera crashes with an inappropriate point array shape #316

Dentikka opened this issue Apr 23, 2024 · 0 comments
Labels
bug Something isn't working

Comments

@Dentikka
Copy link

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
@Dentikka Dentikka added the bug Something isn't working label Apr 23, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

1 participant