我需要一个 uEye 摄像头 在 Windows 上使用 python 来拍照和在直播中操作。
由于 uEye 相机是广泛使用的工业相机,我本以为对此有一个标准的解决方案;但是,我找不到任何东西。
该解决方案需要在 Windows XP 或 Windows 7 上的 python 2.7 下运行。
如果有人在 Windows 上的 python 中成功使用过 uEye 相机,请分享他在这个问题上的知识,或者至少为我指明正确的方向,我将不胜感激。我还觉得确实需要找到一个通用的解决方案,因为可以肯定的是,我不是唯一有此要求的人。
到目前为止我已经尝试过
有一个python driver available它在 Linux 下工作,并且 - 根据文档 - “应该在 Windows 上工作”。
我试过了,但安装失败:
python setup.py 安装
给我
ueye\ueye.pyx: cannot find cimported module 'stdlib'
ueye\ueye.pyx: cannot find cimported module 'python_cobject'
Compiling ueye\ueye.pyx because it changed.
Compiling ueye\ueyeh.pyx because it changed.
[1/2] Cythonizing ueye\ueye.pyx
我不知道什么是 cimported 模块,也不知道这是否应该有效。因此,最好了解是否有人已在 Windows 系统上成功安装此驱动程序。
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, height, exposure # 1024.0 768.0 -4.0
ret, buff = cam.read()
cam.release()
很可能相机处于某种自动模式,可以自动调整曝光时间和增益等参数。但如果是这种情况,我该如何关闭此自动模式。
simpleCV 似乎是 openCV 的替代品。我也试过了,它给出了只获取 480 x 640 像素图像的问题,我找不到任何不同的方法来设置它,也没有设置曝光时间的方法。
from SimpleCV import Camera
cam = Camera(0)
img = cam.getImage() # img is a 480 x 640 pixel image
一种选择可能是编写 C 代码以通过其 SDK 访问相机。一个完整的documentation of the SDK可用 似乎有人成功地做到了( here 或 here ) 但我什至不知道从哪里开始以及如何将实时图像导入 python。
最佳答案
我最近有一个类似的项目,并找到了几个适合我的解决方案。我还使用 python 2.7(32 位)和 Windows 7。我确定还有多种其他方法可以控制相机,但我发现的两种方法是 (1) 将 ctypes 与 c++ API 结合使用,或 (2)将 pythonnet(即 clr)与 dotNet 库一起使用。每种方法都需要从单独的 dll 文件中导入和调用函数。我最终更喜欢 ctypes 方法,因为它更容易编译成可执行文件,但两种方法都同样适用于控制相机。
<强>1。使用 python ctypes 的 uEye API:
uEye API dll中的函数可以使用ctypes在python中调用。使用 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, height, 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, pcImgMem, pid, ImageData.ctypes.data)
<强>2。使用 pythonnet 和 uEye .NET 接口(interface)
从 .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 Files\IDS\uEye\Develop\DotNet") # 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,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,1,1,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, 0,IntPtr.__overloads__[int](imageData.__array_interface__['data'][0]), len(tmp))
强>强>关于python - 在 Windows 上使用 python 的 uEye 相机,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/40563139/
我正在学习如何使用Nokogiri,根据这段代码我遇到了一些问题:require'rubygems'require'mechanize'post_agent=WWW::Mechanize.newpost_page=post_agent.get('http://www.vbulletin.org/forum/showthread.php?t=230708')puts"\nabsolutepathwithtbodygivesnil"putspost_page.parser.xpath('/html/body/div/div/div/div/div/table/tbody/tr/td/div
我有一个Ruby程序,它使用rubyzip压缩XML文件的目录树。gem。我的问题是文件开始变得很重,我想提高压缩级别,因为压缩时间不是问题。我在rubyzipdocumentation中找不到一种为创建的ZIP文件指定压缩级别的方法。有人知道如何更改此设置吗?是否有另一个允许指定压缩级别的Ruby库? 最佳答案 这是我通过查看rubyzip内部创建的代码。level=Zlib::BEST_COMPRESSIONZip::ZipOutputStream.open(zip_file)do|zip|Dir.glob("**/*")d
类classAprivatedeffooputs:fooendpublicdefbarputs:barendprivatedefzimputs:zimendprotecteddefdibputs:dibendendA的实例a=A.new测试a.foorescueputs:faila.barrescueputs:faila.zimrescueputs:faila.dibrescueputs:faila.gazrescueputs:fail测试输出failbarfailfailfail.发送测试[:foo,:bar,:zim,:dib,:gaz].each{|m|a.send(m)resc
很好奇,就使用rubyonrails自动化单元测试而言,你们正在做什么?您是否创建了一个脚本来在cron中运行rake作业并将结果邮寄给您?git中的预提交Hook?只是手动调用?我完全理解测试,但想知道在错误发生之前捕获错误的最佳实践是什么。让我们理所当然地认为测试本身是完美无缺的,并且可以正常工作。下一步是什么以确保他们在正确的时间将可能有害的结果传达给您? 最佳答案 不确定您到底想听什么,但是有几个级别的自动代码库控制:在处理某项功能时,您可以使用类似autotest的内容获得关于哪些有效,哪些无效的即时反馈。要确保您的提
假设我做了一个模块如下:m=Module.newdoclassCendend三个问题:除了对m的引用之外,还有什么方法可以访问C和m中的其他内容?我可以在创建匿名模块后为其命名吗(就像我输入“module...”一样)?如何在使用完匿名模块后将其删除,使其定义的常量不再存在? 最佳答案 三个答案:是的,使用ObjectSpace.此代码使c引用你的类(class)C不引用m:c=nilObjectSpace.each_object{|obj|c=objif(Class===objandobj.name=~/::C$/)}当然这取决于
我正在尝试使用ruby和Savon来使用网络服务。测试服务为http://www.webservicex.net/WS/WSDetails.aspx?WSID=9&CATID=2require'rubygems'require'savon'client=Savon::Client.new"http://www.webservicex.net/stockquote.asmx?WSDL"client.get_quotedo|soap|soap.body={:symbol=>"AAPL"}end返回SOAP异常。检查soap信封,在我看来soap请求没有正确的命名空间。任何人都可以建议我
我需要在客户计算机上运行Ruby应用程序。通常需要几天才能完成(复制大备份文件)。问题是如果启用sleep,它会中断应用程序。否则,计算机将持续运行数周,直到我下次访问为止。有什么方法可以防止执行期间休眠并让Windows在执行后休眠吗?欢迎任何疯狂的想法;-) 最佳答案 Here建议使用SetThreadExecutionStateWinAPI函数,使应用程序能够通知系统它正在使用中,从而防止系统在应用程序运行时进入休眠状态或关闭显示。像这样的东西:require'Win32API'ES_AWAYMODE_REQUIRED=0x0
关闭。这个问题是opinion-based.它目前不接受答案。想要改进这个问题?更新问题,以便editingthispost可以用事实和引用来回答它.关闭4年前。Improvethisquestion我想在固定时间创建一系列低音和高音调的哔哔声。例如:在150毫秒时发出高音调的蜂鸣声在151毫秒时发出低音调的蜂鸣声200毫秒时发出低音调的蜂鸣声250毫秒的高音调蜂鸣声有没有办法在Ruby或Python中做到这一点?我真的不在乎输出编码是什么(.wav、.mp3、.ogg等等),但我确实想创建一个输出文件。
我在我的项目目录中完成了compasscreate.和compassinitrails。几个问题:我已将我的.sass文件放在public/stylesheets中。这是放置它们的正确位置吗?当我运行compasswatch时,它不会自动编译这些.sass文件。我必须手动指定文件:compasswatchpublic/stylesheets/myfile.sass等。如何让它自动运行?文件ie.css、print.css和screen.css已放在stylesheets/compiled。如何在编译后不让它们重新出现的情况下删除它们?我自己编译的.sass文件编译成compiled/t
我想将html转换为纯文本。不过,我不想只删除标签,我想智能地保留尽可能多的格式。为插入换行符标签,检测段落并格式化它们等。输入非常简单,通常是格式良好的html(不是整个文档,只是一堆内容,通常没有anchor或图像)。我可以将几个正则表达式放在一起,让我达到80%,但我认为可能有一些现有的解决方案更智能。 最佳答案 首先,不要尝试为此使用正则表达式。很有可能你会想出一个脆弱/脆弱的解决方案,它会随着HTML的变化而崩溃,或者很难管理和维护。您可以使用Nokogiri快速解析HTML并提取文本:require'nokogiri'h