Closed Sudip-star-a11y closed 1 year 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 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()
Hi, try resizing the width on line 100:
frame = imutils.resize(frame, width = 500)
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.