ezwelty / glimpse

glimpse: Glacier Image Particle Sequencer
13 stars 1 forks source link

IndexError: Box extends beyond grid bounds #30

Closed frigusgulo closed 3 years ago

frigusgulo commented 3 years ago

Trace:

`Traceback (most recent call last):
  File "trackhelheim.py", line 95, in <module>
    tracks = tracker.track(motion_models=motion_models, parallel=True)
  File "/home/dunbar/anaconda3/envs/glimpse/lib/python3.8/site-packages/glimpse/track/tracker.py", line 364, in track
    results = pool.map(
  File "/home/dunbar/anaconda3/envs/glimpse/lib/python3.8/site-packages/sharedmem/sharedmem.py", line 770, in map
    raise pg.get_exception()
sharedmem.sharedmem.WorkerException: Box extends beyond grid bounds
Traceback (most recent call last):
  File "/home/dunbar/anaconda3/envs/glimpse/lib/python3.8/site-packages/sharedmem/sharedmem.py", line 295, in _workerMain
    self.main(self, *self.args)
  File "/home/dunbar/anaconda3/envs/glimpse/lib/python3.8/site-packages/sharedmem/sharedmem.py", line 631, in _main
    r = realfunc(work)
  File "/home/dunbar/anaconda3/envs/glimpse/lib/python3.8/site-packages/sharedmem/sharedmem.py", line 711, in realfunc
    if star: return func(*i)
  File "/home/dunbar/anaconda3/envs/glimpse/lib/python3.8/site-packages/glimpse/track/tracker.py", line 348, in process
    raise e
  File "/home/dunbar/anaconda3/envs/glimpse/lib/python3.8/site-packages/glimpse/track/tracker.py", line 322, in process
    self.initialize_template(
  File "/home/dunbar/anaconda3/envs/glimpse/lib/python3.8/site-packages/glimpse/track/tracker.py", line 526, in initialize_template
    box = self.observers[obs].tile_box(uv, size=tile_size, img=img)
  File "/home/dunbar/anaconda3/envs/glimpse/lib/python3.8/site-packages/glimpse/track/observer.py", line 130, in tile_box
    return grid.snap_box(uv, size, centers=False, edges=True).astype(int)
  File "/home/dunbar/anaconda3/envs/glimpse/lib/python3.8/site-packages/glimpse/raster.py", line 417, in snap_box
    raise IndexError("Box extends beyond grid bounds")
IndexError: Box extends beyond grid bounds
`

Code:

`path = glob.glob(join(DEM_DIR,"*.tif"))[0] print("DEM PATH: {}".format(path)) dem = glimpse.Raster.open(path=path)

    dem.crop(zlim=(0, np.inf))
    dem.fill_crevasses(mask=~np.isnan(dem.array), fill=True)

    # ---- Prepare viewshed ----
    for obs in observers:
        dem.fill_circle(obs.images[0].cam.xyz, radius=50)
    viewshed = dem.copy()
    viewshed.array = np.ones(dem.shape, dtype=bool)
    for obs in observers:
        viewshed.array &= dem.viewshed(obs.images[0].cam.xyz)

    print("\n *****Viewshed Done**** \n")
    # ---- Run Tracker ----
    xy = []
    xy0 = np.array([ 533528.0,7361411.0])[np.newaxis,:]
    #xy.append(xy0)

    xy = [xy0] #qu+ np.vstack([xy for xy in itertools.product(range(-200, 200, 25), range(-200, 200, 25))])

    # Helheim vels around 0.8 m/day

    time_unit = datetime.timedelta(days=1)
    motion_models = [glimpse.CartesianMotion(
        xyi, time_unit=time_unit, 
        dem=dem, 
        dem_sigma=2.5, 
        n=5000, 
        xy_sigma=(0.5,0.5),
        vxyz_sigma=(.4, .3, 0.02),
        axyz=(0,0,0), 
        axyz_sigma=(.25, .25, .05)) for xyi in xy]

    tracker = glimpse.Tracker(observers=observers, viewshed=viewshed)
    print("\n****Tracking Now*****\n")
    tracks = tracker.track(motion_models=motion_models, parallel=True)`

From what I have seen of the code, it looks as though this call should be under the Try/except branch (https://github.com/ezwelty/glimpse/blob/master/src/glimpse/track/tracker.py#L300). My best guess is that the projected camera coordinates called at (https://github.com/ezwelty/glimpse/blob/master/src/glimpse/track/observer.py#L130) are not in the camera image?

ezwelty commented 3 years ago

That error is being raised when trying to initialize a tracking template that extends beyond the image bounds. Either move the starting point away from the image edge, or make the template smaller.

As for the error being raised, I quote the docstring:

"""
Track particles through time.

If more than one motion models are passed (`motion_models`),
errors and warnings are caught silently,
and any images from Observers with :attr:`cache``=True` are cached.

So the current behavior is to catch errors only if you are running more than one motion model. In your example, you passed in one motion model.

frigusgulo commented 3 years ago

xy0 = np.array([ 533528.0,7361411.0,180])[np.newaxis,:] infront = testcam.infront(xy0) xy = xy0[:,0:2]+ np.vstack([xy for xy in itertools.product(range(-200, 200, 25), range(-200, 200, 25))]) elevs = 180*np.ones((xy.shape[0],1)) xy = np.concatenate((xy,elevs),1) uv = testcam.xyz_to_uv(xy) observers[1].images[0].plot() matplotlib.pyplot.scatter(uv[:, 0], uv[:, 1]) plt.show()

Hey Ethan, I think your call on the warped distortion coefficients was correct. Do you think I should go back and re-calibrate? I am fairly dissapointed with open-cv's modules and would be very open to something else if you had reccomendations. We are just about done with a solid approach to the LiDAR stuff as well so at least that is coming along.


From: Ethan Welty notifications@github.com Sent: Thursday, January 28, 2021 9:57 AM To: ezwelty/glimpse glimpse@noreply.github.com Cc: Frankie Dunbar franklyn.dunbar@umontana.edu; Author author@noreply.github.com Subject: Re: [ezwelty/glimpse] IndexError: Box extends beyond grid bounds (#30)

That error is being raised when trying to initialize a tracking template that extends beyond the image bounds. Either move the starting point away from the image edge, or make the template smaller.

As for the error being raised, I quote the docstring:

""" Track particles through time.

If more than one motion models are passed (motion_models), errors and warnings are caught silently, and any images from Observers with :attr:cache``=True are cached.

So the current behavior is to catch errors only if you are running more than one motion model. In your example, you passed in one motion model.

— You are receiving this because you authored the thread. Reply to this email directly, view it on GitHubhttps://github.com/ezwelty/glimpse/issues/30#issuecomment-769224601, or unsubscribehttps://github.com/notifications/unsubscribe-auth/AKOECUENRFF2T6S3U5EJQZTS4GJO7ANCNFSM4WT6DJYA.

ezwelty commented 3 years ago

I doubt there is anything wrong with the performance of the OpenCV camera calibration module, although I wouldn't be surprised if they are a little tricky to use.

As I said back in December, I am not surprised in the least that the calibration is not correct.

These calibration images (in /calibrations/*.jpeg) are likely worse than no calibration at all. The target is small in the image frame, does not appear near image edges, and is visibly warped.

Don't expect a better calibration without better calibration images. As for calibration software, I used to use and enjoy the Camera Calibration Toolbox for MATLAB when I used MATLAB. PhotoModeler's camera calibration is very good (that is what I used in my dissertation for lab calibrations), but the software is not free. Agisoft's Lens (which I believe is free, even if Metashape / Photoscan is not) is decent, especially if you have access to a large, flat computer monitor to display the calibration pattern on – but does not allow manual review and adjustment of the checkerboard corner detection, unlike the other software I mentioned.

frigusgulo commented 3 years ago

As for calibration images, my understanding is that you need up-close images of the chessboard at various angles? Would a set of images like the one attached at different perspectives suffice?


From: Ethan Welty notifications@github.com Sent: Wednesday, February 3, 2021 11:15 AM To: ezwelty/glimpse glimpse@noreply.github.com Cc: Frankie Dunbar franklyn.dunbar@umontana.edu; Author author@noreply.github.com Subject: Re: [ezwelty/glimpse] IndexError: Box extends beyond grid bounds (#30)

I doubt there is anything wrong with the performance of the OpenCV camera calibration module, although I wouldn't be surprised if they are a little tricky to use.

As I said back in December, I am not surprised in the least that the calibration is not correct.

These calibration images (in /calibrations/*.jpeg) are likely worse than no calibration at all. The target is small in the image frame, does not appear near image edges, and is visibly warped.

Don't expect a better calibration without better calibration images. As for calibration software, I used to use and enjoy the Camera Calibration Toolbox for MATLABhttp://www.vision.caltech.edu/bouguetj/calib_doc/ when I used MATLAB. PhotoModeler's camera calibration is very good (that is what I used in my dissertation for lab calibrations), but the software is not free. Agisoft's Lens (which I believe is free, even if Metashape / Photoscan is not) is decent, especially if you have access to a large, flat computer monitor to display the calibration pattern on – but does not allow manual review and adjustment of the checkerboard corner detection, unlike the other software I mentioned.

— You are receiving this because you authored the thread. Reply to this email directly, view it on GitHubhttps://github.com/ezwelty/glimpse/issues/30#issuecomment-772713620, or unsubscribehttps://github.com/notifications/unsubscribe-auth/AKOECUGLR7RUZLKUXMAOPTLS5GHDVANCNFSM4WT6DJYA.