S Andrew
S Andrew

Reputation: 7198

How to increase size of an image while saving it in opencv python

I have python script which detect person and face in a frame. First it detects person, then save its image by increasing some image. Then it detects the face in that person image and also save the face image.

As the original saved image of both person and face is very small because I am reducing the size of the frame initially

frame = imutils.resize(frame, width=500)

so that I get good fps and low noise. This is why while saving the image, I have to increase its width and height. Below is the code I am using and its results:

scale_percent = 220  # percent of original size
width = int(image.shape[1] * scale_percent / 100)
height = int(image.shape[0] * scale_percent / 100)
dim = (width, height)

dim = (width, height)
resized_img = cv2.resize(image, dim, interpolation = cv2.INTER_AREA)

Test image I am using is :

enter image description here

Saved image of face after resize:

enter image description here

and saved image of person after resize:

enter image description here

although the person image looks to be fine but face image is very low in quality. Is there any way possible so that we can increase the size (width and height) of the image but still keep it in a good quality. Please help. Thanks

Upvotes: 0

Views: 1309

Answers (1)

em_bis_me
em_bis_me

Reputation: 388

Try with INTER_CUBIC or INTER_LACZOS4

resized_img = cv2.resize(image, dim, interpolation = cv2.INTER_CUBIC)

I have worked mostly on images and from my experience: INTER_NEAREST~INTER_AREA < INTER_CUBIC~INTER_LACZOS4~INTER_LINEAR

But still, there will be some amount of pixelation when you do any of these operations, coz you are manipulating the original image data.

Upvotes: 3

Related Questions