neozhaoliang / surround-view-system-introduction

A full Python implementation for real car surround view system
MIT License
871 stars 307 forks source link

TypeError: only integer scalar arrays can be converted to a scalar index in run_get_projection_maps.py #21

Closed Jimwaga closed 3 years ago

Jimwaga commented 3 years ago

Hi,

I keep on encountering this error whenever i try to run run_get_projection_maps.py and run_live_demo.py

Also, can you provide a requirements file if possible?

Setup Info:

Python 3.8.3 running on Windows 10

Steps to reproduce:

  1. cloned repo
  2. created and enabled virtual environment
  3. installed dependencies. I attached my requirements.txt
  4. Run above script python run_get_projection_maps.py -camera front -scale 0.7 0.8 -shift -150 -100
$ "./Surround Vision/.venv/Scripts/python.exe" "./Surround Vision/run_get_projection_maps.py" -camera front -scale 0.7 0.8 -shift -150 -100

Traceback (most recent call last):
  File "./Surround Vision/run_get_projection_maps.py", line 73, in <module>
    main()
  File "./Surround Vision/run_get_projection_maps.py", line 62, in main
    camera = FisheyeCameraModel(camera_file, camera_name)
  File ".\Surround Vision\surround_view\fisheye_camera.py", line 28, in __init__
    self.load_camera_params()
  File ".\Surround Vision\surround_view\fisheye_camera.py", line 49, in load_camera_params
    self.update_undistort_maps()
  File ".\Surround Vision\surround_view\fisheye_camera.py", line 59, in update_undistort_maps
    self.undistort_maps = cv2.fisheye.initUndistortRectifyMap(
TypeError: only integer scalar arrays can be converted to a scalar index
Jimwaga commented 3 years ago

I found the solution

Change Proposal

self.resolution = fs.getNode("resolution").mat()

to

self.resolution = fs.getNode("resolution").mat().flatten()

Need to flatten since output is always 2 dimension

Troubleshooting done:

  1. It seems that the code self.resolution = fs.getNode("resolution").mat() in fisheye_camera.py returns resolution as individual arrays for width and height
  2. If you print (width, height) at line 57, you'll get (array([960], dtype=int32), array([640], dtype=int32))
  3. In opencv documentation,
size Undistorted image size.
neozhaoliang commented 3 years ago

Thanks for pointing out this bug. Fixed. I coded it on Ubuntu 16.04/18.04 and used python3.5/python3.6, didn't encounter this problem. Maybe something changed in Python3.8.