How to crop an image in OpenCV using Python

后端 未结 9 2101
面向向阳花
面向向阳花 2020-11-22 08:45

How can I crop images, like I\'ve done before in PIL, using OpenCV.

Working example on PIL

im = Image.open(\'0.png\').convert(\'L\')
im = im.crop((1         


        
9条回答
  •  名媛妹妹
    2020-11-22 09:22

    It's very simple. Use numpy slicing.

    import cv2
    img = cv2.imread("lenna.png")
    crop_img = img[y:y+h, x:x+w]
    cv2.imshow("cropped", crop_img)
    cv2.waitKey(0)
    

提交回复
热议问题