2013-03-03 1 views
2

왜 다음 코드가 파이썬을 충돌 시키나요? 이미지를 다운로드하고 그것을 numpy 배열로 변환하는 더 쉽고/좋은 방법이 있습니까?numpy 배열로 이미지를 다운로드 할 때 Python 충돌이 발생합니다.

from pylab import * 
from urllib import request 
captcha=imread(request.urlopen('http://pastebin.com/etc/CaptchaSecurityImages.php?width=100&height=35&characters=4&b=123')) 

이렇게하면 스택 추적을 인쇄하는 대신 파이썬 인터프리터가 종료됩니다.

+0

:'나가서 설명하자면 NameError가 : 이름이 'imread가'defined' 없습니다. – Bakuriu

+0

@ 바큐 리 당신은 파일 랩을 가져와야합니다 – Navin

답변

4

몇 가지 문제 :

  1. imreadpng에 이미지 유형 및 기본값을 감지 할 수 없습니다.
  2. matplotlib 's _png.read_png crashes on Python 3 with urllib.request object.
  3. request.urlopen 개체에는 찾기 기능이 없으므로 PIL (PIL은 matplotlib에서 비 PNG 이미지를 읽는 데 사용됨)에서 작동하지 않습니다.

이 코드는 윈 - AMD64-py3.3에 나를 위해 작동 : 그것은 충돌하지 않는

from pylab import * 
from urllib import request 
from io import BytesIO 
url = 'http://pastebin.com/etc/CaptchaSecurityImages.php?width=100&height=35&characters=4&b=123' 
data = BytesIO(request.urlopen(url).read()) 
captcha = imread(data, format='jpg') 
+0

"이름 요청을 가져올 수 없습니다"라는 오류 메시지가 나타납니다. –

관련 문제