ue相机与Windows上的python
我需要让一台uEye相机在
Windows上使用python进行拍照并在直播中进行操作.
由于uEye相机是广泛使用的工业相机,我认为有一个标准的解决方案;但是,我找不到任何东西. 该解决方案需要在Windows XP或Windows 7上的python 2.7下运行. 我很感激任何在Windows上成功使用ueye相机的人在这个问题上分享他的知识,或者至少指出我正确的方向.我也觉得确实需要找到一个通用的解决方案,因为我肯定不是唯一有这个要求的人. 到目前为止我尝试过的 (a)pyueye 有一个python driver available在Linux下工作 – 根据文档 – “应该在Windows上工作”. 我试过了,但安装失败了: ueyeueye.pyx: cannot find cimported module 'stdlib' ueyeueye.pyx: cannot find cimported module 'python_cobject' Compiling ueyeueye.pyx because it changed. Compiling ueyeueyeh.pyx because it changed. [1/2] Cythonizing ueyeueye.pyx 我不知道cimported模块是什么,以及这是否应该工作.因此,了解是否有人在Windows系统上成功安装此驱动程序可能会很好. (b)openCV OpenCV似乎是图像捕获和处理的某种标准.似乎有些人用它来访问uEye相机,而似乎也有一些共识认为uEye相机不适用于openCV.我还没有找到任何据称有效的示例代码. 无论如何我试过这个(使用openCV版本2.4.13),我可以访问相机并从中检索图片.分辨率最初为480 x 640,但我可以将其更改为768 x 1024的传感器分辨率. cam = cv2.VideoCapture(0) width = cam.get(cv2.cv.CV_CAP_PROP_FRAME_WIDTH) height = cam.get(cv2.cv.CV_CAP_PROP_FRAME_HEIGHT) exposure = cam.get(cv2.cv.CV_CAP_PROP_EXPOSURE) print width,height,exposure # prints 640 480 -4.0 hr = cam.set(cv2.cv.CV_CAP_PROP_FRAME_HEIGHT,768) wr = cam.set(cv2.cv.CV_CAP_PROP_FRAME_WIDTH,1024) print "Setting resolution ",hr,wr # prints True True cam.set(cv2.cv.CV_CAP_PROP_EXPOSURE,0) # or any other value,same for gain width = cam.get(cv2.cv.CV_CAP_PROP_FRAME_WIDTH) height = cam.get(cv2.cv.CV_CAP_PROP_FRAME_HEIGHT) exposure = cam.get(cv2.cv.CV_CAP_PROP_EXPOSURE) print width,exposure # 1024.0 768.0 -4.0 ret,buff = cam.read() cam.release() 很可能是相机处于某种自动模式,可以自动调整曝光时间和增益等参数.但如果是这种情况,我该如何设置此自动模式. (c)simpleCV simpleCV似乎是openCV的替代品.我也试过了,它给出了只获取480 x 640像素图像的问题,我找不到任何方式来设置它不同,既不是设置曝光时间的方法. from SimpleCV import Camera cam = Camera(0) img = cam.getImage() # img is a 480 x 640 pixel image (d)用C编写自己的驱动程序 一种选择可能是编写C代码以通过其SDK访问摄像机.完整的documentation of the SDK可用
我最近有一个类似的项目,发现了一些对我有用的解决方案.我也使用python 2.7(32位)和Windows 7.我敢肯定还有其他多种方法来控制相机,但我找到的两种方法是(1)使用c API与c API,或(2)使用pythonnet(即clr)和dotNet库.每种方法都需要从单独的dll文件中导入和调用函数.我最终更喜欢ctypes方法,因为它更容易编译成可执行文件,但这两种方法同样适用于控制相机.
1.使用python ctypes的uEye API: 可以使用ctypes在python中调用uEye API dll中的函数.使用ctypes有点麻烦,因为在python和c之间传递变量需要不断地转换数据类型,但它有效. import ctypes import numpy as np uEyeDll = ctypes.cdll.LoadLibrary("ueye_api.dll") #include full path or copy dll into same folder as .py script #connect camera cam = ctypes.c_uint32(0) hWnd = ctypes.c_voidp() msg=uEyeDll.is_InitCamera(ctypes.byref(cam),hWnd) ErrChk=uEyeDll.is_EnableAutoExit (cam,ctypes.c_uint(1)) if ~ErrChk: print (' Camera Connected') IS_CM_SENSOR_RAW8 =ctypes.c_int(11) nRet = uEyeDll.is_SetColorMode(cam,IS_CM_SENSOR_RAW8) IS_SET_TRIGGER_SOFTWARE = ctypes.c_uint(0x1000) nRet = uEyeDll.is_SetExternalTrigger(cam,IS_SET_TRIGGER_SOFTWARE) #allocate memory width_py = 1600 height_py = 1200 pixels_py =8 width = ctypes.c_int(width_py) #convert python values into c++ integers height = ctypes.c_int(height_py) bitspixel=ctypes.c_int(pixels_py) pcImgMem = ctypes.c_char_p() #create placeholder for image memory pid=ctypes.c_int() ErrChk=uEyeDll.is_AllocImageMem(cam,width,bitspixel,ctypes.byref(pcImgMem),ctypes.byref(pid)) if ~ErrChk: print (' Success') else: print (' Memory allocation failed,no camera with value' +str(cam.value)) # Get image data uEyeDll.is_SetImageMem(cam,pcImgMem,pid) ImageData = np.ones((height_py,width_py),dtype=np.uint8) #put these lines inside a while loop to return continous images to the array "ImageData" uEyeDll.is_FreezeVideo (cam,ctypes.c_int(0x0000)) #IS_DONT_WAIT = 0x0000,or IS_GET_LIVE = 0x8000 uEyeDll.is_CopyImageMem (cam,pid,ImageData.ctypes.data) 2.使用pythonnet& uEye .NET界面 从.NET dll调用函数的语法比使用ctypes更简单,但由于某些原因,安装pythonnet(clr)包对我来说很难.以下是使用.NET函数获取摄像机图像的示例: import numpy as np import clr import sys import System from System import Array,Double,IntPtr,Random print System.Environment.Version from CLR.System.Reflection import Assembly from System.Collections.Generic import Dictionary from System.Runtime.InteropServices import Marshal true =bool(1) false=bool(0) #import .NET dll using clr (pythonnet) sys.path.append(r"C:Program FilesIDSuEyeDevelopDotNet") # path of dll clr.AddReference ('uEyeDotNet') # the dll import uEye # initialize camera cam = uEye.Camera() CAM_ID=1; msg=cam.Init(CAM_ID) print 'InitMessage ='+ str(msg) # Change Camera settings gain =1 #% gain exposure = 0.2 #ms ColorMode=cam.PixelFormat.Set(uEye.Defines.ColorMode.SensorRaw8) errChk=cam.Trigger.Set(uEye.Defines.TriggerMode.Software) errChk=cam.Gain.Hardware.GetSupported(1,1,1) errChk,gainFactor=cam.Gain.Hardware.ConvertScaledToFactor.Master(gain,1) errChk=cam.Gain.Hardware.Factor.SetMaster(gainFactor) errChk2,gain=cam.Gain.Hardware.Factor.GetMaster(gain) errChk2,gainout=cam.Gain.Hardware.Scaled.GetMaster(1) cam.Timing.Exposure.Set(1) errChk,exposure_out=cam.Timing.Exposure.Get(exposure) #allocate image memory ErrChk,memout=cam.Memory.Allocate(1600,1200,8,true,1) [ErrChk,Width,Height,Bits,Pitch] = cam.Memory.Inquire(memout,1); # image aquisition for n in range(1000): ErrChk=cam.Acquisition.Freeze(true) outarray = System.Array[System.Byte](()) [ErrChk,tmp] = cam.Memory.CopyToArray(memout,outarray) #'Copy .Net Array using Marshal.Copy imageData = np.empty(len(tmp),dtype=np.uint8) Marshal.Copy(tmp,IntPtr.__overloads__[int](imageData.__array_interface__['data'][0]),len(tmp)) (编辑:李大同) 【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容! |
- get-event-store – Windows Azure上的事件存储无法从外部访
- 如何在Rich Edit控件(Win32 / C)中更改下划线颜色
- Qt 事件系统浅析 (用 Windows API 描述,分析了QCoreApplic
- wpf – Windows 8上的命令绑定问题(发布预览版)
- 如何备份我的建议以禁用Windows防火墙服务?
- Windows Caffe中MNIST数据格式转换实现
- windows安装RabbitMQ注意事项
- win10上安装nginx
- windows-installer – 无提示Windows Installer安装程序,无
- 如何从停止错误0xc00002e2恢复Hyper-V来宾域控制器
- Windows – Active Directory站点 – 设计和连接
- windows-xp – 为什么Windows(文件)资源管理器尝
- .net-3.5 – Windows工作流动态,用户创建的工作流
- windows-server-2008 – 多台服务器的远程桌面
- windows – remote:fatal:解包后留下未解决的增
- xaml – 绑定ListPicker.SelectedIndex问题
- 如何在NSIS中调用PowerShell
- windows-server-2008 – 如何拒绝Windows中共享/
- windows-server-2012 – WSUS无法下载任何东西,不
- windows – 在TaskManager中不显示虚拟机内存使用