How to get image of specific size using python?

Naman

I am trying to get pictures from my camera using open cv I am using this code to access camera and save images in a folder.

import cv2
i = 0
#i = int(input(" "))
cap = cv2.VideoCapture(0)
while True:
    ret,frame = cap.read()
    frame = cv2.cvtColor(frame,0)
    cv2.imshow("frame",frame)
    if cv2.waitKey(1) & 0xFF == ord('q'):
        cv2.imwrite(r"C:\Users\naman.sharma\Desktop\Image_dataset\nm_result_{}.png".format(i), frame)
        break
cap.release()
cv2.destroyAllWindows()

This code works well but I am getting an image of size (600,480) which is very big for the project I am doing.

Is there any specific way to capture images with a certain size. I am trying to capture picture of (250,200).

Thanks for help in advance.

wohlstad

Some devices support various capture sizes, but it is unlikely that your device will support a 250x200 frame size.

Instead of changing the capture size, you can resize the captured frame using cv2.resize.
The last parameter interpolation controls the resampling method. The available options are listed here.

Usage example (with bicubic interpolation):

ret,frame = cap.read()
resized_frame = cv2.resize(frame, (250,200), interpolation=cv2.INTER_CUBIC) 

Collected from the Internet

Please contact [email protected] to delete if infringement.

edited at
0

Comments

0 comments
Login to comment

Related

Want to get image size in kilobytes using python

How to get the size of the image?

How to get size of image

How to get image width size during upload using Ajaxupload Codeigniter?

How to get rid of small image artifacts (threshold by size) using ImageMagick?

How to get letters from an image using python

How to locate a specific image to get the src value with Selenium Python

How to create an image of specific size from UIView

how to delete specific image in folder using python opencv

How to extract a specific section of an image using OpenCV in Python?

How to display a specific size image using SRCSET no matter what the device's pixel ratio is?

How to get all image sizes available for a site using add_image_size?

How to get AWS instance total memory size using python?

How do I get the size of a Cassandra table using the Python driver?

Watson Assistant - How to get size of specific entities

How to get total size of specific counted extensions

Using Python- How to resize a cropped image to meet an aspect ratio while not exceeding original image size

Resize image to get a specific max. file size

How to get index of specific group of character in python using regex

How to get a specific record from RDD by using Python

How to get text inside specific tag using tag name with Python

How to get the specific value from the data using python?

how to get specific part in python beautifulsoup without using loop

How to get a specific element from a list using Selenium with Python

How to select and print a specific JSON value using Python GET Request

How to get specific file version from git repository using python

How to get a specific field from a text file using python

Beatifulsoup: how to get image size by url

How to get image size from a canvas?