Search code examples
pythonlinuxopencvamazon-ec2centos

OpenCV image crop didn't work in linux, but works on local


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!


Solution

  • 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!