【问题标题】:how to read image from wand.image.Image without saving it to drive如何从 wand.image.Image 读取图像而不将其保存到驱动器
【发布时间】:2019-01-30 02:35:59
【问题描述】:

我应该在此代码中进行哪些更改,这样我就不必在步骤 [A] 中将图像保存到磁盘,然后在步骤 [B] 中再次从磁盘读取它。如代码所示。任何人都可以通过更改代码或一些提示来帮助我吗?

import io
import os
import six
from google.cloud import vision 
from google.cloud import translate
from google.cloud.vision import types
import json
from wand.image import Image

client = vision.ImageAnnotatorClient()

sample_pdf = Image(filename='CMB72_CMB0720160.pdf[0]', resolution=500)
blank = Image(filename='Untitled.png')
all_ = sample_pdf.clone()
polling_ = sample_pdf.clone()
voters = sample_pdf.clone()
all_.crop(3000,2800,3800,3860)       
polling_.crop(870,4330,2900,4500)
voters.crop(1300,4980,2000,5250)
blank.composite(all_,left=0,top=0)
blank.composite(voters,left=0,top=1100)
blank.composite(polling_,left=0,top=1420)
blank.save('CMB72_CMB0720122.jpg')---------------[A]


file_name = 'CMB72_CMB0720122.jpg'-------------|
with io.open(file_name,'rb') as image_file:----|>[B]
     content = image_file.read()---------------|

image = types.Image(content= content)

image_context = vision.types.ImageContext(
        language_hints=['hi'])       

response = client.document_text_detection(image=image)
texts = response.text_annotations
file = open('jin.txt','w+',encoding='utf-8')
file.write(texts[0].description)
file.close()

【问题讨论】:

    标签: image image-processing computer-vision imagemagick python-imaging-library


    【解决方案1】:

    使用wand.image.Image.make_blob 方法。

    content = blank.make_blob('JPEG')
    

    【讨论】:

      猜你喜欢
      • 2013-06-05
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2018-05-14
      • 1970-01-01
      • 1970-01-01
      • 2010-11-09
      相关资源
      最近更新 更多