1

How to scale down an image by physical size?

For example, I need a 640*480 image with a size of 200KB has to be scale down to 75KB retains the same 640*480.

tried with cv2.resize and cv2.PyrDown. These two methods mainly focus on resolution. As resolution reduces size reduce too. Scaling down then scaling up using these methods reduces the size as needed but lost the image quality.

Are there any other ways that scaledown image size?

Here is the base problem, MTCNN_face_detection_alignment lagging in IP camera, Convention behind opencv cv2 videocapture frame matrix

Chinni
  • 1,199
  • 1
  • 14
  • 28
Jeyan
  • 729
  • 1
  • 14
  • 27
  • This may help... https://stackoverflow.com/a/52281257/2836621 – Mark Setchell Sep 09 '19 at 10:30
  • Looking at your base problem, the issue actually appears to be that your IP camera generates physically larger images than your built in camera even though the resolution is the same in both cases? Is this correct? – TheBarrometer Sep 09 '19 at 10:31
  • @TheBarrometer Yes. That's correct. IP camera has higher resolution. Scaled down the frame resolution captured from IP camera using cv2.resize to match with builtin camera resolution. However the scaled down Ip camera frame size still not coming down as the size of built in. – Jeyan Sep 09 '19 at 10:38
  • @MarkSetchell that doesn't belong to opencv. That means I have to convert the cv2 frame into JPEG file and process. Then convert back to frame for detection which is my base requirement. So looking for a solution in opencv itself if possible. – Jeyan Sep 09 '19 at 10:44

1 Answers1

0

Please see code below.

# store image shape
(h, w) = img.shape

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

resized = cv2.resize(img, dim, interpolation = cv2.INTER_AREA) 

cv2.imshow('resized image', resized)

Hope this helps.

Dylan Freeman
  • 221
  • 3
  • 12