我有一个程序,它将图像保存在本地目录中,然后从该目录读取图像。
但我不想保存这个图像。我希望直接从url读取。
这是我的代码:
如果我将其更改为:
这将给我报以下错误:
但我不想保存这个图像。我希望直接从url读取。
这是我的代码:
import cv2.cv as cv
import urllib2
url = "http://cache2.allpostersimages.com/p/LRG/18/1847/M5G8D00Z/posters/curious-cat.jpg"
filename = "my_test_image" + url[-4:]
print filename
opener = urllib2.build_opener()
page = opener.open(url)
img= page.read()
abc = open(filename, "wb")
abc.write(img)
abc.close()
img = cv.LoadImage(filename)
cv.ShowImage("Optical Flow", img)
cv.WaitKey(30)
如果我将其更改为:
img = cv.LoadImage(img)
这将给我报以下错误:
我该怎么办?第一个参数必须为不含空字节的字符串,而不是str