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

How to save compressed images #80

Open
collinabidi opened this issue Oct 10, 2019 · 5 comments
Open

How to save compressed images #80

collinabidi opened this issue Oct 10, 2019 · 5 comments

Comments

@collinabidi
Copy link

I'm attempting to record both RGB and Depth images at the same time using two cameras. However, when I run the modified baseline_race.py script, saving the images uncompressed seems to be too much for my computer to handle.

When I try to save the compressed images, I get the error:

ValueError: cannot reshape array of size 122900 into shape (240, 320, 3)

I'm wondering how to get the dimensions of the compressed image so I can properly save it.

Additionally, help with efficiently saving both RGB and Depth images from two cameras would be greatly appreciated.

@madratman
Copy link
Contributor

Hey @collinabidi
How about using cv2.imwrite?
baseline_racer.py is already reshaping it for you in the image_callback function:

    import time

    def image_callback(self):
        # get uncompressed fpv cam image
        request = [airsim.ImageRequest("fpv_cam", airsim.ImageType.Scene, False, False)]
        response = self.airsim_client_images.simGetImages(request)
        img_rgb_1d = np.fromstring(response[0].image_data_uint8, dtype=np.uint8) 
        img_rgb = img_rgb_1d.reshape(response[0].height, response[0].width, 3)
        # for saving, you can do :
        cv2.imwrite(time.strftime("%Y%m%d-%H%M%S") + ".png", img_rgb)

@madratman
Copy link
Contributor

Can you share your python snippet as well?
122900 seems wrong.

@collinabidi
Copy link
Author

collinabidi commented Oct 10, 2019

request = [airsim.ImageRequest('depth_cam', 3, False, True)]
response = self.airsim_client_images.simGetImages(request)
img_1d = np.fromstring(response[1].image_data_uint8, dtype=np.uint8)
img_depth = img_1d.reshape(response[1].height, response[1].width, 3)
cv2.imwrite(self.output_dir + '/depth_ims/' + str(self.drone_name) + '_' + str("{0:.3f}".format(round(time.time(),3))) + '.png', img_depth)

The only modification I've made is changing the compress parameter to True

@yannbouteiller
Copy link

Depht images? I thought we were only allowed to get rgb images from the front camera?

@madratman
Copy link
Contributor

I think he might be generating a dataset, afai can tell.

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