【问题标题】:Argument error when compiling .exe from Python using PyInstaller使用 PyInstaller 从 Python 编译 .exe 时出现参数错误
【发布时间】:2020-04-27 21:06:53
【问题描述】:

我正在尝试用 python 编写屏幕录像机程序。我的代码在编译器中正常运行。但是当我将其转换为 .exe 时,它​​会引发此错误:

[ERROR:0] global C:\projects\opencv-python\opencv\modules\videoio\src\cap.cpp (415) cv::VideoWriter::open VIDEOIO(CV_IMAGES): raised OpenCV exception:OpenCV(4.2.0) C:\projects\opencv-python\opencv\modules\videoio\src\cap_images.cpp:253: error: (-5:Bad argument) CAP_IMAGES: can't find starting number (in the name of file): project.avi in function 'cv::icvExtractPattern'

我使用 pyinstaller 转换为 .exe。

这是我的代码:

from tkinter import*
from tkinter import messagebox as msj
from PIL import ImageTk, Image
from PIL import ImageGrab
import os
import time

import cv2
import numpy as np
import glob

recording=False
i = 0
size = 100, 100

mainWindow=Tk()
mainWindow.title("ScreenRecorder")
mainWindow.geometry("200x200")

scriptDirectory = (os.path.dirname(os.path.realpath(__file__)))

def convert(imageCount):
    img_array = []
    for ip in range(1,imageCount):
        x="snap"+str(ip)+".jpg"
        for filename in glob.glob(x):
            img = cv2.imread(filename)
            height, width, layers = img.shape
            size = (width,height)
            img_array.append(img)

    out = cv2.VideoWriter('project.avi',cv2.VideoWriter_fourcc(*'DIVX'), 9, size)

    for iz in range(len(img_array)):
        out.write(img_array[iz])

    out.release()

    for a in range(1,imageCount+1):
        os.remove("snap"+str(a)+".jpg")

def record():
    global i
    print(recording)
    if(recording==True):
        i+=1
        fileName= ("snap"+str(i))
        #time.sleep(0.00005)
        image = ImageGrab.grab()
        name=fileName+".jpg"
        image.save(name,'JPEG')

        imgX = (Image.open("snap"+str(i)+".jpg"))
        imgX= imgX.resize(size, Image.ANTIALIAS)
        imgX=ImageTk.PhotoImage(imgX)

    mainWindow.after(1, record)

def startButton():
    global recording
    print("ehe")
    recording=True
    record()

def stopButton():
    global recording
    recording=False
    record()
    convert(i)


startButton=Button(text="Start",command=startButton)
startButton.pack()
stopButton=Button(text="Stop",command=stopButton)
stopButton.pack()

mainWindow.after(1, record)

mainWindow.mainloop()

【问题讨论】:

    标签: python-3.x opencv tkinter python-imaging-library


    【解决方案1】:

    我只能建议你使用另一种方法,我认为它更简单,尝试使用'auto py to exe'。这是一个可以从网络安装或从pip安装程序安装的模块。 从here 看到。这是我用于我的代码的唯一方法。 其次,要知道如果程序不是用.py格式打开的,就永远不会用.exe打开 希望对你有帮助。

    【讨论】:

    • auto-py-to-exe 也在使用 PyInstaller。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2012-02-19
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2016-06-07
    相关资源
    最近更新 更多