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

Index out of bounds exception #1

Open
MiguelFRomeroR opened this issue May 17, 2018 · 3 comments
Open

Index out of bounds exception #1

MiguelFRomeroR opened this issue May 17, 2018 · 3 comments

Comments

@MiguelFRomeroR
Copy link

Hi, thanks for sharing the code. Your solution has been really helpful for me!

However, I found a small issue. You can replicate it by changing line 20:
self.FOV = [0.45, 0.45]
to
self.FOV = [0.3, 0.3]

and line 113:
center_point = np.array([0.5, .5])
to
center_point = np.array([0.5, .9])

It triggers the exception at line 76, in _bilinear_interpolation.

IndexError: index 8389700 is out of bounds for size 8388608

To solve it, I added the following, after line 64:

x2 = np.minimum(x2, self.frame_width-1)
y2 = np.minimum(y2, self.frame_height-1)

I think the error occurs because for the interpolation, you take pixel i and pixel i+1, and in some specific cases, pixel i is already the last pixel (either in width or height).

Hope it helps.

@gogozhu
Copy link

gogozhu commented Dec 27, 2018

Hi, thanks for your solution. I also encountered this problem.

However, when I tried your solution, I found another issue.

As we know, the first pixel and the last pixel on the latitude of an equirectangular image are continuous, which means the pixel i+1 should be 0 rather than width when the pixel i is the last pixel. Therefor, I think the correct solution should be the following.

First, you can change line 62
x2 = np.add(x0, np.ones(uf.shape).astype(int)) # coords of pixel to top right
to
_x2 = np.add(x0, np.ones(uf.shape).astype(int)) # coords of pixel to top right

Then add the following after line 64:

x2 = np.mod(_x2, self.frame_width)  
y2 = np.minimum(y2, self.frame_height-1)

Finally, in order to correct the bilinear interpolation, the x2 in line 80 and 81 should be changed to _x2.

wa = np.multiply(_x2 - uf, y2 - vf)
wb = np.multiply(_x2 - uf, vf - y0)

Hope it helps.

remorsecs added a commit to remorsecs/equirectangular-toolbox that referenced this issue Sep 5, 2019
@kwea123
Copy link

kwea123 commented May 31, 2020

If you install opencv-python, there is a more concise way, add the following lines after
spericalCoord = self._calcSphericaltoGnomonic(convertedScreenCoord)

sphericalCoord = sphericalCoord.reshape(self.height, self.width, 2).astype(np.float32) % 1
out = cv2.remap(frame, 
                        sphericalCoord[..., 0]*self.frame_width, 
                        sphericalCoord[..., 1]*self.frame_height, 
                        interpolation=cv2.INTER_LINEAR,
                        borderMode=cv2.BORDER_WRAP)
return out

then you don't need the handcrafted _bilinear_interpolation anymore. It produces the same result.

@KevinHwangKR
Copy link

Hey, could you tell me how you were able to run this program please?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants