image - raspberry python imgproc module saving -
hi using python library called imgproc
create can take images webcam onto raspberry-pi. don't know how save .jpg
file. have researched everywhere can't find reply anywhere.the link library here. have tried don't have pi-cam proper method. hers current code:
import socket import time imgproc import * cam = camera(320, 240) host = "example.com" port = 8888 s = socket.socket(socket.af_inet, socket.sock_stream) ri = socket.gethostbyname(host) s.connect((ri , port)) x = true while x: img = cam.grabimage()
it possible using, e.g., pil or similar library. however, if want fast, there problems.
the challenge comes imgproc
api, not seem allow quick access image info itself. method using __getitem__
method of image
object, illustration img[x,y]
. looks much numpy
arrays, unfortunately not have else in common.
imgproc
lean wrapper built on c library. quite instructive have @ imgproc.py
, shows available bindings.
most have build image pixel-by-pixel, not fast. example:
img_array = numpy.array([ [ img[x,y] x in range(img.width) ] y in range(img.height) ] , dtype='uint8')
once have image array, can convert pil image , save image:
pil_img = image.fromarray(img_array) pil_img.save('my_image.jpg')
in order this, need both numpy
, image
modules (pil). method not fast. alternative create empty numpy
array , populate it:
img_array = numpy.empty((img.height, img.width, 3), dtype='uint8') y in range(img.height): x in range(img.height): img_array[y,x] = img[x,y]
only testing reveal 1 less slow.
in principle, not hideously hard augment library adding bit more powerful wrapper functions around library create homecoming binary buffer contents in improve format, doing requires knowledge both in c , in python.
python image raspberry-pi python-imaging-library
No comments:
Post a Comment