简体   繁体   English

无法在Mac上使用OpenCV打开图像

[英]Can't open image on mac with OpenCV

I am trying to open an image with OpenCV on mac with Python with this simple program: 我正在尝试使用以下简单程序在带有Python的Mac上使用OpenCV打开图像:

import numpy as np
import cv2
img = cv2.imread("image.jpg", 1)
cv2.imshow("image", img)
cv2.waitKey(0)
cv2.destroyAllWindows()

But every time I run it I get this error: 但是每次运行它时,都会出现此错误:

   cv2.imshow("image", img)
   error: /Users/travis/build/skvark/opencv-
   python/opencv/modules/highgui/src/window.cpp:325: error: (-215) 
   size.width>0 && size.height>0 in function imshow

I have researched this question but it says that the image may be empty, but I'm pretty sure my image isn't empty as I can open it and look at it. 我研究了这个问题,但是它说图像可能是空的,但是我很确定我的图像不是空的,因为我可以打开它并查看它。

I have faced same problem couple of days and I solved my problem by giving full path of image in cv2.imread() 我几天都遇到过同样的问题,我通过在cv2.imread()中给出完整的图像路径来解决了我的问题

here's a sample 这是一个样本

import cv2
import os

img = cv2.imread(os.path.expanduser( "~/Downloads/Pics/A.jpg"))
cv2.namedWindow("Images")
cv2.imshow('Images',img)
cv2.waitKey(1)
cv2.destroyAllWindows()

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM