skip to Main Content
def imgCrop(img, src):

    x = 0
    y = 514
    w = 1502
    h = 1170
    cv2.imwrite("test.png",img)
    crop_img = img[y:y+h, x:x+w]
    cv2.imwrite("img.png", crop_img)
imgCrop(img, src)

This is my code, I tried to crop an image then save it, runs well locally.
But when I try to do it on EC2 linux centOs, it just shows

!_img.empty() in function ‘imwrite’

"test.png" is good, but when it reached crop_img, it’s empty.
I’ve tried "pip install opencv-contrib-python" it still don’t work, and saw all related post, still have no clue on this.

Please help! Thank you!

2

Answers


  1. Chosen as BEST ANSWER

    Sorry for not providing full information, was trying to make my question brief. After several attempts, I found out that it's due to the size of chrome windows are different from linux and my macOS, And thus the [x,y,w,h] variable have to be adjusted to the chrome window size on different machine. Thank you for all the information!


  2. You confuse cv2.imwrite and cv2.imread in first use.

    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search