0

I am trying to capture image with each function call

import imageio as iio
camera = iio.get_reader("<video0>")
screenshot = camera.get_data(0)
plt.imsave(filename, screenshot)
camera.close()

I am able to save the image but the image size is varying sometime it is of the size of 960540 and sometime 1280720.

I went through the documentation of imageio but did not find any attribute to set its shape. I want a fix shape of image all the time.

I have tried OpenCV, it has its own limitation w.r.t my requirements.

So please suggest something in this package only.

Could anyone please help.

Kumar
  • 125
  • 1
  • 9
  • Are we talking shape or size here? Compression is going to make frame sizes change depending on their content anywhere regardless of the library you use, but if you are asking about the shape and for some reason it is changing from frame to frame you can try resize each frame to achieve consistency. – Mr K. Jul 30 '21 at 07:26
  • I am talking for the dimensions (height and width) here. It comes as 1280 * 720 pixels sometime and sometime 960 * 540 pixels. I am not changing here anything. in the code part but still it changes. – Kumar Aug 01 '21 at 03:19
  • Please state which camera make/model you are using and also try acquiring a few frames and printing the shape after each, that is `print(screenshot.shape)` – Mark Setchell Aug 03 '21 at 08:50
  • Also, what are the first few bytes of screenshot in hex please? – Mark Setchell Aug 03 '21 at 14:29

1 Answers1

1

Your comment made clear you want to keep the resolution consistent for the duration of the whole video. As imageio does not provide a resize operation I suggest you to use skimage to handle that part.

import imageio as iio
import matplotlib.pyplot as plt
from skimage.transform import resize

camera = iio.get_reader("<video0>")

filename = "experiment_"

# randomly set to 30 frames for this example
for i in range(0, 30):
    screenshot = camera.get_data(i)
    # skimage resize function here
    screenshot = resize(screenshot, (1280, 720))
    final_filename = str(i) + ".jpg"
    plt.imsave(filename+final_filename, screenshot)
camera.close()
Mr K.
  • 1,064
  • 3
  • 19
  • 22