libgphoto2绑定了一个力求惯用的接口
gphoto2-cffi的Python项目详细描述
python与libgphoto2的绑定,接口力求 习惯用语。与python的其他绑定不同,gphoto2 cffi隐藏了大部分 低层抽象并在仍然 提供对图书馆大部分功能的访问。
importgphoto2cffiasgp# List all attached cameras that are supportedcams=gp.list_cameras()# Get a camera instance by specifying a USB bus and device numbermy_cam=gp.Camera(bus=4,device=1)# Get an instance for the first supported cameramy_cam=gp.Camera()# ormy_cam=next(gp.list_cameras())# Capture an image to the camera's RAM and get its dataimgdata=my_cam.capture()# Grab a preview from the camerapreviewdata=my_cam.get_preview()# Get a list of files on the camerafiles=tuple(my_cam.list_all_files())# Iterate over a file's contentwithopen("image.jpg","wb")asfp:forchunkinmy_cam.files[0].iter_data():fp.write(chunk)# Get a configuration valueimage_quality=my_cam.config['capturesettings']['imagequality'].value# Set a configuration valuemy_cam.config['capturesettings']['imagequality'].set("JPEG Fine")
支持Python2.7和3.4或更新版本(cpython和pypyy)。
要求
- libgphoto2,带有开发标题
- 一个有效的c编译器
- CFFI
安装
来源:
$ pip install git+https://github.com/jbaiter/gphoto2-cffi.git
类似项目
- piggyphoto:使用cTypes
- python-gphoto2:使用swig