because it works when importing cv2 and cv does not work when I import it


I'm trying this

import numpy as np
import cv2

#Cargar los dos videos
video1 = cv2.VideoCapture('')
video2 = cv2.VideoCapture('')

#Guardar las dimensiones del primer video
ancho1 = int(video1.get(
alto1 = int(video1.get(

#Guardar las dimensiones del segundo video
ancho2 = int(video2.get(
alto2 = int(video2.get(

#El ancho del video final sera el minimo de las dos longitudes horizontales
ancho = int(min(ancho1, ancho2))

#Usar un codec compatible con .avi
fourcc =*'XVID')

#Crear el objeto VideoWriter
out = cv2.VideoWriter('output.avi',fourcc, 30, (ancho,alto1+alto2))

    #En este frame guardaremos la union de los dos videos:
    frame = np.zeros((alto1+alto2,ancho,3), np.uint8)

    #Leer un frame de cada video
    ret1, frame1 =
    ret2, frame2 =

    #Mirar que ambos frames sean validos (uno de los videos podria ser mas corto que el otro)
    if ret1 and ret2:
        frame[0:alto2,0:ancho] = frame2 #Colocar el frame del primer video en la mitad superior
        frame[alto2:(alto2+alto1),0:ancho] = frame1 #Colocar el frame del segundo video en la mitad inferior
        out.write(frame) #Escribir el nuevo frame
        cv2.imshow('frame',frame) #Mostrarlo en una ventana

    #Si frame1 o frame2 es nulo, salir del programa    

    #Se puede interrumpir el proceso pulsando 'q'
    if cv2.waitKey(1) & 0xFF == ord('q'):

#Si se ha terminado el proceso, limpiar...

and I present problems here:

ancho1 = int(video1.get(
alto1 = int(video1.get(

Because it says that it does not recognize cv then I decided to import part in shell cv and it does not work but I import cv2 and there if

asked by ger 10.07.2017 в 01:24

1 answer


If you use OpenCV 3 onwards the use of the cv submodule has been deprecated, instead use simply:

ancho1 = int(video1.get(cv2.CAP_PROP_FRAME_WIDTH ))
alto1 = int(video1.get(cv2.CAP_PROP_FRAME_HEIGHT))

We can find a small example in the official documentation about the use of the methods set and get in video captures next to both variables in OpenCV 3 in the following link:

Getting Started with Videos

answered by 10.07.2017 / 02:14