saimj7 / People-Counting-in-Real-Time

People Counting in Real-Time with an IP camera.
MIT License
528 stars 263 forks source link

Reducing the frame Size of the camera feed. #45

Closed Sudip-star-a11y closed 1 year ago

Sudip-star-a11y commented 2 years ago

Hi Saimj7,

Superb Work!!. Really appreciable.

One help I require on how to reduce the camera frame size? Like I am getting the live feed from the camera but in my actual deployment I don't want the entire feed to be involved in people counting. I would like to trim out the four edges of the live feed square.

Will really appreciate your help.

Thanks.

dryuvrajk commented 2 years ago

There is no specific function for cropping using OpenCV, NumPy array slicing is what does the job. Every image that is read in, gets stored in a 2D array (for each color channel). Simply specify the height and width (in pixels) of the area to be cropped. And it's done!

Below is the Python code:

Import packages

import cv2 import numpy as np

img = cv2.imread('test.jpg') print(img.shape) # Print image shape cv2.imshow("original", img) # Cropping an image

cropped_image = img[80:280, 150:330] # Display cropped image

cv2.imshow("cropped", cropped_image) # Save the cropped image

cv2.imwrite("Cropped Image.jpg", cropped_image)

cv2.waitKey(0) cv2.destroyAllWindows()

saimj7 commented 1 year ago

Hi, try resizing the width on line 100:

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