-1
下面是py2exe安裝腳本:無法通過python獨立可執行文件在另一臺計算機上通過PyQt4 gui中的OpenCV加載視頻。給沒有錯誤無助
from setuptools import setup
import py2exe
from glob import glob
import numpy
import sys
import cv2
SETUP_DICT = {
'windows': [{
'script': 'C:\\Users\\Codemen1\\Documents\\Python Scripts\\video.py',
}],
'zipfile': 'lib/library.zip',
'data_files': (
('', glob(r'C:\Windows\SYSTEM32\msvcp100.dll')),
('', glob(r'C:\Windows\SYSTEM32\msvcr100.dll')),
),
'options': {
'py2exe': {
'bundle_files': 3,
#'bundle_files': 1,
#'packages': 'cv2',
'includes': ['sip', 'PyQt4.QtCore','numpy','sys','cv2'],
},
}
}
setup(**SETUP_DICT)
這setup.py腳本完全適用於圖像的其它&功能,如果我讓他們執行。
這裏是我的PyQt代碼我在哪裏顯示視頻
class Ui_MainWindow(object):
def setupUi(self, MainWindow):
MainWindow.setObjectName(_fromUtf8("Control panel"))
MainWindow.setWindowTitle(_translate("Control panel", "Control panel", None))
#MainWindow.resize(1407, 722)
MainWindow.setFixedSize(800, 722)
self.centralwidget = QtGui.QWidget(MainWindow)
self.centralwidget.setObjectName(_fromUtf8("centralwidget"))
self.verticalLayoutWidget = QtGui.QWidget(self.centralwidget)
self.verticalLayoutWidget.setGeometry(QtCore.QRect(10, 20, 160, 661))
self.verticalLayoutWidget.setObjectName(_fromUtf8("verticalLayoutWidget"))
self.verticalLayout = QtGui.QVBoxLayout(self.verticalLayoutWidget)
self.verticalLayout.setMargin(0)
self.verticalLayout.setObjectName(_fromUtf8("verticalLayout"))
self.videoFrame = QtGui.QLabel(self.centralwidget)
self.videoFrame.setGeometry(QtCore.QRect(100, 40, 591, 611))
self.videoFrame.setText(_fromUtf8(""))
self.videoFrame.setObjectName(_fromUtf8("videoFrame"))
MainWindow.setCentralWidget(self.centralwidget)
self.videoFrame = QtGui.QLabel(self.centralwidget)
self.videoFrame.setGeometry(QtCore.QRect(190, 40, 591, 611))
self.videoFrame.setText(_fromUtf8(""))
self.videoFrame.setObjectName(_fromUtf8("videoFrame"))
MainWindow.setCentralWidget(self.centralwidget)
class Video():
def __init__(self,capture):
self.capture = capture
self.currentFrame=np.array([])
def captureNextFrame1(self):
"""
capture frame and reverse RBG BGR and return opencv image
"""
ret, readFrame=self.capture.read()
if(ret==True):
self.currentFrame=cv2.cvtColor(readFrame,cv2.COLOR_BGR2RGB)
def convertFrame(self):
""" converts frame to format suitable for QtGui """
try:
height,width=self.currentFrame.shape[:2]
bytesPerLine = 3 * width
img=QtGui.QImage(self.currentFrame.data,width,height,bytesPerLine,QtGui.QImage.Format_RGB888)
img=QtGui.QPixmap.fromImage(img)
self.previousFrame = self.currentFrame
return img
except:
return None
class Gui(QtGui.QMainWindow):
def __init__(self,parent=None):
QtGui.QWidget.__init__(self,parent)
self.ui = Ui_MainWindow()
self.ui.setupUi(self)
self.video1 = Video(cv2.VideoCapture("C:\\Users\Public\\OpenCVproject\\IMG_1491.mov"))
self._timer = QtCore.QTimer(self)
self._timer.timeout.connect(self.play)
self._timer.start(27)
self.update()
def play(self):
try:
self.video1.captureNextFrame1()
self.ui.videoFrame.setPixmap(self.video1.convertFrame())
self.ui.videoFrame.setScaledContents(True)
except TypeError:
print "No frame"
def main():
app = QtGui.QApplication(sys.argv)
ex = Gui()
ex.show()
sys.exit(app.exec_())
if __name__ == '__main__':
main()
沒有錯,到目前爲止的代碼。完美的作品。但是,如果我讓這個獨立的exe文件的視頻不在其他計算機上呈現。完美展現在我的身上。
你可以在你想要做的事情上添加更多細節嗎?提供代碼和一些背景信息...這非常含糊 – Shahram