イメージをローカルディレクトリに保存し、そのディレクトリからイメージを読み込むプログラムがあります。Python:Urllib2とOpenCV
しかし、私は画像を保存したくありません。私は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)
これは私に、このエラーを与える:
argument 1 must be string without null bytes, not str
私は何ができますか?あなたはPILを使用することができますしたい場合は
ありがとう、非常に便利です!ワンポイント:「CStringIOから」エラーが発生しました。これは "from cStringIO ..."(小文字の 'c')でなければなりません。 –
私の悪い。それを指摘してくれてありがとう。私はそれを変更しました。 – Froyo