python运行程序后不显示图像是什么原因,OpenCV-Python不显示图像

I am currently following a tutorial on how to use OpenCV with python but something isn't working. When i run this code that should display an image i get this error: error: C:\builds\master_PackSlaveAddon-win32-vc12-static\opencv\modules\highgui\src\window.cpp:271: error: (-215) size.width>0 && size.height>0 in function cv::imshow

Here is the code

import numpy as np

import cv2

img = cv2.imread('C:\Users\Ive\Downloads\7.jpg',0)

cv2.imshow("image",img)

cv2.waitKey(0)

cv2.destroyAllWindows()

Someone already asked this question on here but the answer didn't work for me. The answer was to remove the unnecessary quotes. But i don't have them.

解决方案

You need to escape backslashes, or your string will be ill-formed.

This will work:

img = cv2.imread('C:\\Users\\Ive\\Downloads\\7.jpg',0)

You can find here additional information.

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值