【问题标题】:How to grab frames from a frame grabber card?如何从图像采集卡中抓取帧?
【发布时间】:2013-12-09 05:34:46
【问题描述】:

我正在尝试编写一个自定义软件(在 python 中)来从图像采集卡中抓取帧 (Hauppauge WinTV-HVR-1900),但我无法让它工作。捆绑的 WinTV 软件运行良好,我可以从 USB 网络摄像头抓取帧,所以我知道硬件工作正常。不过我设法捕捉到了一些东西,因为我的屏幕是全黑的,但会更改为正确的尺寸和分辨率,所以我的预感是它是某种解码问题。

谁能帮助我提供一个指示或提供从此类硬件中提取帧的代码示例,好吗?我应该编写一个完整的自定义驱动程序吗?或者也许使用VLC python bindings(因为VLC确实成功读取了视频流)?

编辑:

基本上,我的问题归结为:我的图像采集卡与网络摄像头有何不同,因为集成的硬件编码器产生 MPEG-2 流? 不应该像我的网络摄像头那样表现?

我尝试的逻辑文件(在 windows 7 上使用 pyQt4 和 python 2.7 的 QT 框架):

#-*- coding: utf-8 -*-
import sys
from VideoCapture import Device
#import Gui files and classes 
import FloGui
import deviceDialog
# PyQT4 imports
from PyQt4 import QtGui, QtCore

class devicedialog(QtGui.QDialog, deviceDialog.Ui_streamDialog):
    #the logic of the streaming device choice dialog
    def __init__(self,parent=None):
        super(devicedialog,self).__init__(parent)
        self.setupUi(self)
        self.retranslateUi(self)
        self.index = None
        i=0
        self.camlist=list()
        while True:
            try:
                cam = Device(i,0)
                name = cam.getDisplayName()
                dev = [name,i]
                self.camlist.append(dev)
                i+=1
                del cam
            except:
                break
        for j in xrange(len(self.camlist)):
            item = QtGui.QListWidgetItem(self.camlist[j][0])
            self.deviceListBox.addItem(item)
        self.exec_()

    def accept(self):
        selected = self.deviceListBox.currentItem().text()
        for k in xrange(len(self.camlist)):
            if self.camlist[k][0]==selected:
                self.index = k
        QtGui.QDialog.accept(self)

class Flolog(QtGui.QMainWindow,FloGui.Ui_MainWindow):
    """
    Flolog is inherited from both QtGui.QDialog and FloGui.Ui_MainWindow
    """
    def __init__(self, parent=None):
        """
            Initialization of the class. Call the __init__ for the super classes
        """
        super(Flolog,self).__init__(parent)
        self.setupUi(self)
        self.retranslateUi(self)
        self.connectActions()

    def streamchoice(self):
        streamdialog = devicedialog()
        self.VideoWidget.stop()
        self.VideoWidget.path = streamdialog.index
        self.VideoWidget.load()
        self.playButton.setEnabled(True)

    def menuloadfile(self):
        filename = QtGui.QFileDialog.getOpenFileName(self, 'Open File', '.')
        self.VideoWidget.stop()
        self.VideoWidget.path = str(filename)
        self.VideoWidget.load()
        self.playButton.setEnabled(True)


    def playbutton(self):
        self.VideoWidget.play()
        self.playButton.setEnabled(False)

    def main(self):
        self.show()

    def quit_(self):
        sys.exit(0)

    def connectActions(self):
        """
        Connect the user interface controls to the logic
        """
        self.actionFile.triggered.connect(self.menuloadfile)
        self.actionStream.triggered.connect(self.streamchoice)
        self.actionQuit.triggered.connect(self.quit_)
        self.playButton.clicked.connect(self.playbutton)
        self.stopButton.clicked.connect(self.VideoWidget.stop)




if __name__=='__main__':
    app = QtGui.QApplication(sys.argv)
    Flologob = Flolog()
    Flologob.main()
    sys.exit(app.exec_())

【问题讨论】:

  • 你解决过这个问题吗?
  • 我在 Ubuntu 上通过 v4l2 驱动程序切换设备解决了这个问题。我知道windows上有一个等价物,但我不知道名字。

标签: python opencv webcam video-capture


【解决方案1】:

我实际上终于解决了这个问题。问题源于这样一个事实,即应首先手动或在代码中指定图形驱动程序应使用哪个视频设备。我通过 v4l2 图形驱动程序切换设备在 Linux Ubuntu 上解决了这个问题。我知道在 Windows 上可以执行相同的操作。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2015-02-08
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2016-09-20
    • 2010-10-31
    相关资源
    最近更新 更多