uEye camera with python on Windows

前端 未结 2 1372
终归单人心
终归单人心 2021-01-01 01:08

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 camer

2条回答
  •  遥遥无期
    2021-01-01 02:13

    I was able to get a ueye USB 3.0 camera working in Direct3D mode with the "IDS python libraries" Link to official project.

    Also in use: wxpython 2.8, python 2.7. One key item to remember is to install the DirectX SDK. DXSDK_Jun10.exe worked for me.

    This is working code, but it is not shutting down cleanly (it takes around 20 sec to close). It seems that just stop the capturing will allow it to close normally... an exercise for the reader.

    import wx
    
    def create(parent):
        return Dialog1(parent)
    
    [wxID_DIALOG1, wxID_DIALOG1BCAPTURE, wxID_DIALOG1DIMAGE, 
    ] = [wx.NewId() for _init_ctrls in range(3)]
    
    class Dialog1(wx.Dialog):
        def _init_ctrls(self, prnt):
            # generated method, don't edit
            wx.Dialog.__init__(self, id=wxID_DIALOG1, name='', parent=prnt,
                  pos=wx.Point(739, 274), size=wx.Size(888, 674),
                  style=wx.DEFAULT_DIALOG_STYLE, title='Dialog1')
            self.SetClientSize(wx.Size(872, 636))
    
            self.Dimage = wx.Panel(id=wxID_DIALOG1DIMAGE, name=u'Dimage',
                  parent=self, pos=wx.Point(24, 24), size=wx.Size(640, 480),
                  style=wx.TAB_TRAVERSAL)
            self.Dimage.SetBackgroundColour(wx.Colour(233, 251, 230))
    
            self.BCapture = wx.Button(id=wxID_DIALOG1BCAPTURE, label=u'Capture',
                  name=u'BCapture', parent=self, pos=wx.Point(136, 520),
                  size=wx.Size(144, 71), style=0)
            self.BCapture.Bind(wx.EVT_BUTTON, self.OnBCaptureButton,
                  id=wxID_DIALOG1BCAPTURE)
    
        def __init__(self, parent):
            self._init_ctrls(parent)
    
            # Video
            from pyueye import ueye
            import win32ui
            self.capture = None
            h_cam = ueye.HIDS(0)
            hwnd = ueye.HWND(self.Dimage.GetHandle())
    
            cam = ueye.is_InitCamera(h_cam,hwnd)
            if cam == 0:
                print 'camera was intintialized'
            else:
                print 'camera result',cam
    
            col = ueye.c_int(0)
            mod = ueye.c_int(0)
            ueye.is_GetColorDepth(h_cam, col, mod)
            nRet = ueye.is_SetColorMode (h_cam, mod)
            if nRet != ueye.IS_SUCCESS: print 2,nRet
            print 1,col,mod
    
            SensorInfo = ueye.SENSORINFO()
            nRet = ueye.is_GetSensorInfo(h_cam,SensorInfo)
            if nRet != ueye.IS_SUCCESS: print 55,nRet
            for i in SensorInfo._fields_:
                print i[0],eval('SensorInfo.%s'%i[0])
    
            imgw,imgh = self.Dimage.GetSizeTuple()
            imageSize = ueye.IS_SIZE_2D()
            imageSize.s32Width = imgw
            imageSize.s32Height = imgh
            nRet = ueye.is_AOI(h_cam, ueye.IS_AOI_IMAGE_SET_SIZE, imageSize, ueye.sizeof(imageSize))
            if nRet != ueye.IS_SUCCESS: print 77,nRet
    
            m_nDisplayMode = ueye.IS_SET_DM_DIRECT3D
            nRet = ueye.is_SetDisplayMode(h_cam, m_nDisplayMode)
            if nRet != ueye.IS_SUCCESS: print 88,nRet
    
            #ueye.is_DirectRenderer(h_cam,DR_GET_OVERLAY_KEY_COLOR
            #ueye.is_DirectRenderer(h_cam,DR_GET_MAX_OVERLAY_SIZE
    
            #ueye.is_DirectRenderer(h_cam,DR_GET_USER_SYNC_POSITION_RANGE
            ueye.is_DirectRenderer(h_cam, ueye.DR_SET_VSYNC_OFF, ueye.c_int(0), ueye.c_int(0))
    
            #ueye.is_DirectRenderer(h_cam, ueye.DR_SET_HWND, hwnd,ueye.sizeof(hwnd))
            #ueye.is_DirectRenderer(h_cam,ueye.DR_ENABLE_SCALING,None,None)
    
            nRet = ueye.is_CaptureVideo(h_cam, ueye.IS_WAIT) 
            if nRet != ueye.IS_SUCCESS: print 99,nRet
    
        def OnBCaptureButton(self, event):
            event.Skip()
    
    if __name__ == '__main__':
        app = wx.App(0)
        parent = wx.Frame(None)
        parent.Show()
        dlg = create(parent)
        try:
            result = dlg.ShowModal()
        finally:
            dlg.Destroy()
        del dlg.capture
    

提交回复
热议问题