Código de Python - Interfaz para extraer los fotogramas de un vídeo.

Imágen de perfil
Val: 712
Bronce
Ha aumentado 1 puesto en Python (en relación al último mes)
Gráfica de Python

Interfaz para extraer los fotogramas de un vídeo.gráfica de visualizaciones


Python

Publicado el 11 de Febrero del 2021 por Antonio (76 códigos)
2.658 visualizaciones desde el 11 de Febrero del 2021
Programa para extraer los fotogramas de un vídeo.
La interfaz consta de 4 botones:
SELECT VIDEO: Para seleccionar el vídeo del que se va a extraer los fotogramas.
EXTRACT FRAMES: Para iniciar el proceso de extracción en la ubicación que se elija.
STOP: Para interrumpir el proceso de extracción.
CHANGE TO GRAY MODE: Para extraer fotogramas en escala de grises.

vtf

PARA CUALQUIER DUDA U OBSERVACIÓN, USEN LA SECCIÓN DE COMENTARIOS.

Requerimientos

Lenguaje: Python
Librerías y recursos: Pmw, opencv, threading, os, tkinter

1.2

Publicado el 11 de Febrero del 2021gráfica de visualizaciones de la versión: 1.2
2.659 visualizaciones desde el 11 de Febrero del 2021
estrellaestrellaestrellaestrellaestrella
estrellaestrellaestrellaestrella
estrellaestrellaestrella
estrellaestrella
estrella

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
#!/usr/bin/env python
# -*- coding: utf-8 -*-
from tkinter import filedialog
from tkinter import Label, Button
import Pmw
import cv2
import threading
import os
 
class App:
    def __init__(self):
 
        self.ventana = Pmw.initialise(fontScheme = 'pmw1')
        self.label = Label(self.ventana,text="NO FILE SELECTED",bg='gray45',fg='white')
        self.label.pack(side='top')
        self.file = ""
        self.extract = True
        self.color = True
        self.executing = False
        self.ventana.title('VIDEO TO FRAMES')
        self.ventana.configure(bg='gray45')
        self.display = Pmw.ScrolledText(self.ventana,hscrollmode='none',
                      vscrollmode='dynamic', hull_relief='sunken',
                      hull_background='gray20', hull_borderwidth=10,
                      text_background='dark green', text_width=70,#109,
                      text_foreground='lawn green', text_height=22,#39,
                      text_padx=10, text_pady=10, text_relief='groove',
                      text_font=('Fixedsys', 10))
 
        self.display.pack(padx=0,pady=0)
 
        botones = Pmw.ButtonBox(self.ventana,hull_background="gray20")
        botones.pack(fill='both',expand=1,padx=1,pady=1)
        self.btnMode = Button(self.ventana,text="CHANGE TO GRAY MODE",width=73,bg='gray30',fg='white',command=self.mode)
        self.btnMode.pack(side='bottom')
 
        botones.add('SELECT VIDEO',width=23,bg='gray80',command=self.openFile)
        botones.add('EXTRACT FRAMES',width=23,bg='gray80',command=self.initExtract)
        botones.add('STOP',width=23,bg='gray80',command=self.stop_pro)
        self.display.appendtext("WELCOME.")
        botones.alignbuttons()
 
        self.ventana.mainloop()
 
    def openFile(self):
        if self.executing == False:
            self.file = filedialog.askopenfilename(initialdir="/",title="SELECT FILE",
                                                   filetypes=(("mp4 files","*.mp4"),("all files","*.*")))
 
            if self.file != "":
                self.display.clear()
                self.archiv = self.file.split("/")[-1]
                self.name,ex = os.path.splitext(self.archiv)
                self.label.configure(text=self.archiv)
                self.display.appendtext('ROOT: {}\n'.format(self.file))
 
    def extractFrames(self):
        self.display.clear()##########
        self.cam = cv2.VideoCapture(self.file)
        count = 1#0
        while(True):
            ret,frame = self.cam.read()
            if self.extract == False:
                self.display.appendtext("\nSTOPPED: {} frames generated.\n".format(count-1))
                break
            if ret:
                name = self.name+" "+str(count)+'.jpg'
 
                self.display.appendtext('Generated frame: {}\n'.format(name))
                if self.color == False:
                    gray_frame = cv2.cvtColor(frame,cv2.COLOR_BGR2GRAY)#
                    cv2.imwrite(name,gray_frame)
                else:
                    cv2.imwrite(name,frame)
                count += 1
            else:
                self.display.appendtext("\n\nPROCESS FINISHED: {} frames generated.\n".format(count-1))
                self.executing = False
                break
 
        self.cam.release()
        cv2.destroyAllWindows()
 
    def stop_pro(self):
        self.extract = False
        self.executing = False
 
    def mode(self):
        if self.color == True:
            self.color = False
            self.btnMode.configure(bg='light green',fg='red',text='CHANGE TO COLOR MODE')
            self.display.appendtext('\nGRAY MODE\n')
        else:
            self.color = True
            self.btnMode.configure(bg='gray30',fg='white',text='CHANGE TO GRAY MODE')
            self.display.appendtext('\nCOLOR MODE\n')
 
    def initExtract(self):
        if self.file != "" and self.executing == False:
            self.extract = True
            direct = filedialog.askdirectory()
            if direct != "":
                self.executing = True
                os.chdir(direct)
                t = threading.Thread(target=self.extractFrames)
                t.start()
 
if __name__=="__main__":
    App()



Comentarios sobre la versión: 1.2 (0)


No hay comentarios
 

Comentar la versión: 1.2

Nombre
Correo (no se visualiza en la web)
Valoración
Comentarios...
CerrarCerrar
CerrarCerrar
Cerrar

Tienes que ser un usuario registrado para poder insertar imágenes, archivos y/o videos.

Puedes registrarte o validarte desde aquí.

Codigo
Negrita
Subrayado
Tachado
Cursiva
Insertar enlace
Imagen externa
Emoticon
Tabular
Centrar
Titulo
Linea
Disminuir
Aumentar
Vista preliminar
sonreir
dientes
lengua
guiño
enfadado
confundido
llorar
avergonzado
sorprendido
triste
sol
estrella
jarra
camara
taza de cafe
email
beso
bombilla
amor
mal
bien
Es necesario revisar y aceptar las políticas de privacidad

http://lwp-l.com/s6878