久久久久久久av_日韩在线中文_看一级毛片视频_日本精品二区_成人深夜福利视频_武道仙尊动漫在线观看

在 Windows 上使用 python 的 uEye 相機

uEye camera with python on Windows(在 Windows 上使用 python 的 uEye 相機)
本文介紹了在 Windows 上使用 python 的 uEye 相機的處理方法,對大家解決問題具有一定的參考價值,需要的朋友們下面隨著小編來一起學習吧!

問題描述

我需要一個 uEye 相機 在 Windows 上使用 python 來拍照和操作直播.
由于 uEye 相機是廣泛使用的工業相機,我認為有一個標準的解決方案;但是,我找不到任何東西.解決方案需要在 Windows XP 或 Windows 7 上的 python 2.7 下運行.

I need to get a uEye camera working with python on Windows in order to take pictures and operate on the live stream.
Since uEye cameras are widely spread industrial cameras I would have thought that there is a standard solution to this; however, I could not find any. The solution needs to run under python 2.7 on Windows XP or Windows 7.

如果有人在 Windows 上的 python 中成功使用了 uEye 相機,我將不勝感激,分享他在這個問題上的知識,或者至少為我指明正確的方向.我也覺得確實有必要找到一個通用的解決方案,因為我肯定不是唯一一個有這個要求的人.

I would appreciate anyone who has successfully used a uEye camera in python on Windows to share his knowledge on this issue or at least point me in the right direction. I also feel that there is really a need to find a generic soltion, since for sure I'm not the only one with this requirement.

到目前為止我已經嘗試過什么

What I've tried so far

有一個 python 驅動程序可用,它可以在 Linux 下運行,并且 - 根據文檔 - 應該在 Windows 上工作".

There is a python driver available which works under Linux and - according to the documentation - "should work on windows".

我試過了,但安裝失敗:
python setup.py 安裝給我

I've tried that but installation failed:
python setup.py install gives me

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 系統上成功安裝了這個驅動程序.

I have no idea what cimported modules are and whether this should work at all. So it might be good to know if anyone has successfully installed this driver on a Windows system.

OpenCV 似乎是圖像捕獲和處理的某種標準.似乎有些人用它來訪問 uEye 相機,而似乎也有一些共識認為 uEye 相機不適用于 openCV.我沒有找到任何據報道有效的示例代碼.

OpenCV seems to be some kind of standard for image capturing and processing. It seems some people have used it to access a uEye camera, while there also seems to be some consensus that uEye cameras do not work with openCV. I haven't found any reportedly working example code.

無論如何我都試過了(使用 openCV 2.4.13 版),我可以訪問相機并從中檢索圖片.最初的分辨率是 480 x 640,但我可以將其更改為 768 x 1024 的傳感器分辨率.但是,我無法正確設置曝光時間和增益,如我使用的以下代碼所示.

Anyways I tried this (using openCV version 2.4.13) and I can access the camera and retrieve a picture from it. The resolution initially is 480 x 640, but I am able to change it to the sensor resoltion of 768 x 1024. However, I am not able to set the exposure time and the gain correctly, as can be seen in the following code I used.

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()

很可能相機處于某種自動模式,自動調整曝光時間增益等參數.但是如果是這種情況,我該如何設置這個自動模式.

It may well be that the camera is in some kind of auto-mode that automatically adjusts the parameters like exposure time and gain. But if this is the case, how would I set this auto-mode off.

simpleCV 似乎是 openCV 的替代品.我也試過了,它給出了只獲取 480 x 640 像素圖像的問題,我找不到任何不同的設置方法,也找不到設置曝光時間的方法.

simpleCV seems to be an alternative to openCV. I also tried that and it gives the problem of only fetching a 480 x 640 pixel image and I couldn't find any way to set it differently, neither a way to set the exposure time.

from SimpleCV import Camera
cam = Camera(0)
img = cam.getImage() # img is a 480 x 640 pixel image

(d) 用 C 編寫自己的驅動程序

一種選擇可能是編寫 C 代碼以通過其 SDK 訪問相機.提供完整的SDK 文檔看來,有人已經成功地做到了(這里,或這里)但我什至不知道從哪里開始以及如何將實時圖像導入 python.

(d) Writing own driver in C

One option might be to write a C code to access the camera via its SDK. A full documentation of the SDK is available and it seems, someone has successfully done it (here, or here) but I wouldn't even know where to start and how to get the live image into python.

推薦答案

我最近有一個類似的項目,并找到了一些對我有用的解決方案.我還使用了python 2.7(32位)和windows 7.我確信還有多種其他方法可以控制相機,但我發現的兩種方法是(1)使用ctypes和c++ API,或者(2)將 pythonnet(即 clr)與 dotNet 庫一起使用.每種方法都需要從單獨的 dll 文件中導入和調用函數.我最終更喜歡 ctypes 方法,因為它更容易編譯成可執行文件,但兩種方法在控制相機方面同樣適用.

I had a similar project recently and found a couple of solutions that worked for me. I was also using python 2.7 (32-bit) and windows 7. I'm sure there are multiple other ways to control the camera but the two methods I found were (1) either using ctypes with the c++ API, or (2) using pythonnet (i.e. clr) with the dotNet libraries. Each method requires importing and calling functions from a separate dll file. I ultimately preferred the ctypes approach because it was easier to compile into an executable, but both methods worked equally well for controlling the camera.

1.使用 python ctypes 的 uEye API:

uEye API dll 中的函數可以在 python 中使用 ctypes 調用.使用 ctypes 有點麻煩,因為在 python 和 c 之間傳遞變量需要不斷地轉換數據類型,但是它可以工作.

The functions in the uEye API dll can be called in python using ctypes. Using ctypes is slightly cumbersome because passing variables between python and c requires constantly converting data types, but it works.

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 界面

從 .NET dll 調用函數的語法比使用 ctypes 更簡單,但由于某種原因,安裝 pythonnet (clr) 包對我來說很困難.下面是一個使用 .NET 函數獲取相機圖像的示例:

The syntax to call functions from the .NET dll is more straightforward than with ctypes, but installing the pythonnet (clr) package was difficult for me for some reason. Here's an example of acquiring a camera image with the .NET functions:

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,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))

這篇關于在 Windows 上使用 python 的 uEye 相機的文章就介紹到這了,希望我們推薦的答案對大家有所幫助,也希望大家多多支持html5模板網!

【網站聲明】本站部分內容來源于互聯網,旨在幫助大家更快的解決問題,如果有圖片或者內容侵犯了您的權益,請聯系我們刪除處理,感謝您的支持!

相關文檔推薦

How should I verify a log message when testing Python code under nose?(在鼻子下測試 Python 代碼時,我應該如何驗證日志消息?)
Patch __call__ of a function(修補函數的 __call__)
How to call self in a mock method of an object in Python?(如何在 Python 中對象的模擬方法中調用 self?)
Mocking only a single method on an object(僅模擬對象上的單個方法)
Mocking a subprocess call in Python(在 Python 中模擬子進程調用)
Checking call order across multiple mocks(檢查多個模擬的調用順序)
主站蜘蛛池模板: 日韩一区二区三区在线 | 久久久久久久久久久国产 | 午夜免费福利 | 亚洲一区在线免费观看 | 在线一区二区视频 | 欧美日韩国产激情 | 日韩欧美中文字幕在线观看 | 深夜福利网站 | 亚洲性生活片 | 午夜网| 国产一区二区av | 日本丰满肉感bbwbbwbbw | 国产又粗又猛视频免费 | 欧美xx孕妇 | 精品久久久久久久久久久久久久久久 | www.亚洲成人 | 欧美精品在线免费观看 | 日韩一级黄色片 | 日韩视频二区 | 日韩在线播放视频 | 波多野结衣亚洲一区 | 欧美专区在线 | 久操视频在线 | 特级黄色大片 | 欧美在线免费 | 久久在线视频 | 久久精品美女 | 精品视频免费 | 久久久久久久免费视频 | 欧美视频一区 | 毛片www | 哦┅┅快┅┅用力啊┅aps | 17c在线| 成人午夜av | 久热精品视频 | 久久99精品久久久久久琪琪 | 国产三级成人 | 免费毛片在线 | 精品一区视频 | 国产免费黄色片 | a级片免费 |