0

I am running windows xp(sp3, 32 bit) as a VM through oracle VirtualBox.

I am trying to play a video file using opencv2 but whenever i call cap = VideoCapture(url) it just crashes(that windows xp's send and dont send report pop up comes).

opencv2 version is 3.1.0 python version is 3.4 windows xp sp3 32 bit.

Anyone knows anything?

code is written below.

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()

Below is the code which causes the crash, just 2 lines of code that is all it takes to crash

import cv2
cap = cv2.VideoCapture('images/5a121d1ede80980cf28c8eb50674f661.mp4')
Prashanth Kumar B
  • 566
  • 10
  • 25
  • Check your file path, it's likely wrong. Do you have any error handling around that line? post some code – GPPK Sep 12 '17 at 10:31
  • Thanks for replying, but try except does not do anything, cause, as soon as it reaches that statement, a windows error message pops up and everything gets stuck, is there anyway apart from there i can get you some reports – Prashanth Kumar B Sep 12 '17 at 10:39
  • Post your code, you will get more help. https://stackoverflow.com/help/mcve – GPPK Sep 12 '17 at 10:42
  • @GPPK I have added the code, basically it just fails at this spot, self.vs = cv2.VideoCapture('images/5a121d1ede80980cf28c8eb50674f661.mp4') – Prashanth Kumar B Sep 12 '17 at 10:45
  • I think your fliepath could be wrong - https://stackoverflow.com/questions/24564889/opencv-python-not-opening-images-with-imread – GPPK Sep 12 '17 at 11:45
  • No, I tried that solution it is not working...!!! – Prashanth Kumar B Sep 12 '17 at 12:17
  • can you reduce the code to just capture and display? or capture and print image size or something? – Micka Sep 12 '17 at 13:47
  • the thing is, I will get an error message as soon as i call this, self.vs = cv2.VideoCapture('images/5a121d1ede80980cf28c8eb50674f661.mp4') I have edited the question and added the minimum code which causes the error – Prashanth Kumar B Sep 12 '17 at 14:03
  • do you get any error code? – Micka Sep 12 '17 at 16:03
  • No, I did not get any error code, the process gets crashed, I suspect it is because of some graphics issue on the vm, not sure, so i am going to install windows xp on a physical machine and try the same code on that lets see what happens, I will update this post once i do that...! However please let me know if you guys have any ideas that i can try to resolve this. – Prashanth Kumar B Sep 13 '17 at 05:04
  • HI All, The error message remains the same it is not playing the video, :( even on a physical machine with everything installed, correctly :(, any news from you guys – Prashanth Kumar B Sep 14 '17 at 08:21

0 Answers0