Opencv VideoCapture在Windows XP上崩溃

时间:2017-09-12 09:57:17

标签: python windows opencv video windows-xp

我通过oracle VirtualBox将Windows xp(sp3,32位)作为VM运行。

我正在尝试使用opencv2播放视频文件但是无论何时我调用cap = VideoCapture(url)它都会崩溃(windows xp' s发送并且不会发送报告弹出来)。

opencv2版本是3.1.0 python版本是3.4 windows xp sp3 32位。

任何人都知道吗?

代码写在下面。

from PIL import Image, ImageTk
import tkinter as tk
import argparse
import datetime
import cv2
import os

class Application:
    def __init__(self, output_path = "./"):
        """ Initialize application which uses OpenCV + Tkinter. It displays
            a video stream in a Tkinter window and stores current snapshot on disk """
        self.vs = cv2.VideoCapture('images/5a121d1ede80980cf28c8eb50674f661.mp4') # capture video frames, 0 is your default video camera
        self.output_path = output_path  # store output path
        self.current_image = None  # current image from the camera

        self.root = tk.Tk()  # initialize root window
        self.root.title("PyImageSearch PhotoBooth")  # set window title

        # self.destructor function gets fired when the window is closed
        self.root.attributes("-fullscreen", True)

        # getting size to resize! 30 - space for button
        self.size = (self.root.winfo_screenwidth(), self.root.winfo_screenheight() - 30)

        self.panel = tk.Label(self.root)  # initialize image panel
        self.panel.pack(fill='both', expand=True)

        # create a button, that when pressed, will take the current frame and save it to file

        # start a self.video_loop that constantly pools the video sensor
        # for the most recently read frame
        # init frames
        self.frames = self.resize_video()
        self.video_loop()

    def resize_video(self):
        temp = list()
        try:
            temp_count_const = cv2.CAP_PROP_FRAME_COUNT
        except AttributeError:
            temp_count_const = cv2.cv.CV_CAP_PROP_FRAME_COUNT

        frames_count = self.vs.get(temp_count_const)

        while self.vs.isOpened():
            ok, frame = self.vs.read()  # read frame from video stream
            if ok:  # frame captured without any errors
                cv2image = cv2.cvtColor(frame, cv2.COLOR_BGR2RGBA)  # convert colors from BGR to RGBA
                cv2image = cv2.resize(cv2image, self.size, interpolation=cv2.INTER_NEAREST)
                cv2image = Image.fromarray(cv2image)  # convert image for PIL
                temp.append(cv2image)
                # simple progress print w/o sys import
                print('%d/%d\t%d%%' % (len(temp), frames_count, ((len(temp)/frames_count)*100)))
            else:
                return temp

    def video_loop(self):
        """ Get frame from the video stream and show it in Tkinter """
        if len(self.frames) != 0:
            self.current_image = self.frames.pop(0)
            self.panel.imgtk = ImageTk.PhotoImage(self.current_image)
            self.panel.config(image=self.panel.imgtk)
            self.root.after(1, self.video_loop)  # call the same function after 30 milliseconds

# construct the argument parse and parse the arguments
ap = argparse.ArgumentParser()
ap.add_argument("-o", "--output", default="./",
                help="path to output directory to store snapshots (default: current folder")
args = vars(ap.parse_args())

# start the app
print("[INFO] starting...")
pba = Application(args["output"])
print("no , I was first")
pba.root.mainloop()

以下是导致崩溃的代码,只需2行代码即可崩溃

import cv2
cap = cv2.VideoCapture('images/5a121d1ede80980cf28c8eb50674f661.mp4')

0 个答案:

没有答案