pixelink相机的python驱动程序
pixelink的Python项目详细描述
pixelink相机的python驱动程序。
兼容性
在以下环境下测试和开发,
- pixelink相机型号:pixelink gige pl-b781g
- PixeLink软件开发工具包4.2-8.7.1版(约2014年,包括2017年版)
- Windows 7 Pro(32位和64位)
- Linux Ubuntu16.04(64位)(libpxlapi.so.4.2.1.11)
- Python2.7(32位和64位)和Python3.6(64位)
安装
使用python的pip工具安装此包:
pip install pixelink
有几个依赖项,
- decorator (required)
- numpy (optional)
- pillow (optional - used to save the images)
对于window s的用户,使用以下二进制存储库安装numpy,
下载完numpy+mkl控制盘文件后,执行以下操作 命令(假设numpy-1.13.2+mkl-cp36-cp36m-win-amd64.whl):
pip install numpy‑1.13.2+mkl‑cp36‑cp36m‑win_amd64.whl
Linux操作系统
对于基于linux debian的o/s,您需要安装以下依赖项:
sudo apt-get install libsdl2-2.0-0 sudo apt-get install libavcodec-ffmpeg56
您需要导出以下设置(使用您的位置 pixelink库目录:
export LD_LIBRARY_PATH=~/Downloads/pixelink/lib
示例
安装了Numpy的帧抓取,
>>>frompixelinkimportPixeLINK>>>cam=PixeLINK()>>>cam.shutter=0.002>>>cam.grab()array([[17,18,17,...,18,16,17],[16,17,17,...,18,17,17],[17,17,16,...,17,17,17],...,[20,20,21,...,20,20,20],[21,18,20,...,21,20,21],[22,21,20,...,20,21,20]],dtype=uint8)>>>raw_data=cam.grab()>>>raw_data.mean()21.016006038647344>>>cam.shutter=0.003>>>raw_data=cam.grab()>>>raw_data.mean()29.30297418478261>>>cam.close()>>>>>>fromPILimportImage>>>im=Image.fromarray(raw_data)>>>im.save('test1.png')
在未安装Numpy的情况下抓取帧,
>>>frompixelinkimportPixeLINK>>>fromPILimportImage>>>cam=PixeLINK()>>>cam.shutter=0.004>>>data=cam.grab()>>>data<ctypes.c_char_Array_6624000objectat0x00000000039EF448>>>>cam.size(2208,3000)>>>cam.pixel_size1>>>im=Image.frombuffer('L',cam.size,data)__main__:1:RuntimeWarning:thefrombufferdefaultsmaychangeinafuturerelease;forportability,changethecalltoread:frombuffer(mode,size,data,'raw',mode,0,1)>>>im.save('test2.png')>>>cam.close()
在线程中连续捕获帧,
importthreadingimporttimefrompixelinkimportPixeLINK,PxLerrordefgrab_frames(cam):frame_num=0time_start=time.time()print('Continuous frame grabbing started...')whilecam.is_open():frame_num+=1try:data=cam.grab()# TODO: do something with the data...exceptPxLerrorasexc:print('ERROR: grab_frames:',str(exc))continuet_total=time.time()-time_startifframe_num%10==0:frame_rate=float(frame_num)/t_totalprint('#%04d FPS: %0.3f frames/sec'%(frame_num,frame_rate))defmain():cam=PixeLINK()cam.shutter=0.002# exposure time in secondsth=threading.Thread(target=grab_frames,args=[cam])th.start()try:whileTrue:time.sleep(1.0)exceptKeyboardInterrupt:print('Caught CTRL+C')finally:print('Closing camera...')cam.close()print('Waiting for thread...')th.join()print('Done.')if__name__=='__main__':main()