2017-12-01 12 views
1

Wand을 사용하여 pdf 파일을 이미지로 변환 중입니다. 그런 다음 ndimage를 사용하여 추가 이미지 처리를 수행합니다.막대 이미지 객체를 numpy 배열로 변환하는 방법 (OpenCV없이)?

나는 완드 이미지를 ndarray로 직접 변환하고 싶습니다 ... 나는 대답을 보았습니다 here,하지만 OpenCV를 사용합니다. OpenCV를 사용하지 않고 이것이 가능합니까? 이런 당신은 버퍼를 사용할 수 있습니다

답변

0

scipy.misc.imread()가 다시 열릴 내가 임시 파일을 저장하는 순간, 들어

:

import cStringIO 
import skimage.io 
from wand.image import Image 
import numpy 

#create the image, then place it in a buffer 
with Image(width = 500, height = 100) as image: 
    image.format  = 'bmp' 
    image.alpha_channel = False 
    img_buffer=numpy.asarray(bytearray(image.make_blob()), dtype=numpy.uint8) 

#load the buffer into an array 
img_stringIO = cStringIO.StringIO(img_buffer) 
img = skimage.io.imread(img_stringIO) 

img.shape