How to Crop an image in opencv using Python

 How to Crop an image in opencv using Python





Code :
import cv2
import numpy as np
img = cv2.imread("lambo.png")
imcrop = img[0:100,200:500]
cv2.imshow("image",img)
cv2.imshow("crop",imcrop)
cv2.waitKey(0)

Code Explanation:
  • First we are going to import cv2 and numpy
  • Then we will read our image and store into a variable called img
  • Now we have have to define a starting and ending point of rectangle as example 0:100 means 0 from x and 100 from y is the starting point and 200 from x and 500 from y is the ending point we are going to store this in variable called imcrop
  • Then we simply show our image by using cv2.imshow

Post a Comment

0 Comments