'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 1:[1]
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!
Solution 2:[2]
You confuse cv2.imwrite and cv2.imread in first use.
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|---|
| Solution 1 | Mac Yang |
| Solution 2 | teplandr |
