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

Code to convert polar to cartesian radar #32

Open
Madhusakth opened this issue Jul 22, 2022 · 2 comments
Open

Code to convert polar to cartesian radar #32

Madhusakth opened this issue Jul 22, 2022 · 2 comments

Comments

@Madhusakth
Copy link

Hi,

Would it be possible to share the code you used for converting the radar data from polar to cartesian?

Thanks!

@Ianpengg
Copy link

Ianpengg commented Dec 1, 2022

Hi~
You can take this code from Oxford radar-robotcar-dataset for reference
I've already modified a little bit to fit the polar data provided by Radiate.

def from_polar_to_cart(raw_example_data, cart_resolution: float, cart_pixel_width: int, interpolate_crossover=True):

    radar_resolution = np.array([0.0432], np.float32)
    azimuths = np.arange(400) * (math.pi/180)*0.9
    raw_example_data = raw_example_data.T
    fft_data = raw_example_data[:, :].astype(np.float32)[:, :, np.newaxis] / 255.
    if (cart_pixel_width % 2) == 0:
        cart_min_range = (cart_pixel_width / 2 - 0.5) * cart_resolution
    else:
        cart_min_range = cart_pixel_width // 2 * cart_resolution
    coords = np.linspace(-cart_min_range, cart_min_range, cart_pixel_width, dtype=np.float32)
    Y, X = np.meshgrid(coords, -coords)
    sample_range = np.sqrt(Y * Y + X * X)
    sample_angle = np.arctan2(Y, X)
    sample_angle += (sample_angle < 0).astype(np.float32) * 2. * np.pi

    # Interpolate Radar Data Coordinates
    azimuth_step = azimuths[1] - azimuths[0]

    sample_u = (sample_range - radar_resolution / 2) / radar_resolution
    sample_v = (sample_angle - azimuths[0]) / azimuth_step

    # We clip the sample points to the minimum sensor reading range so that we
    # do not have undefined results in the centre of the image. In practice
    # this region is simply undefined.
    sample_u[sample_u < 0] = 0

    if interpolate_crossover:
        fft_data = np.concatenate((fft_data[-1:], fft_data, fft_data[:1]), 0)
        sample_v = sample_v + 1

    polar_to_cart_warp = np.stack((sample_u, sample_v), -1)
    cart_img = np.expand_dims(cv2.remap(fft_data, polar_to_cart_warp, None, cv2.INTER_LINEAR), -1)
    
    return cart_img

@yangsc4063
Copy link

However, after using the above method, I found that there was still a difference between the images provided by the dataset and the images I transformed. You can zoom in and compare carefully, or use the following line of code

# compare the interpolated BEV image with the Cartesian radar image
assert np.allclose(bev_img, cart_img, atol=1e-1)

test_interpol_transformer
test_raw_cart_img
I am also very curious about code that convert polar to cartesian. Looking forward to your reply!

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

3 participants