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

3

I'm trying this

import numpy as np
import cv2

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

#Guardar las dimensiones del primer video
ancho1 = int(video1.get(cv2.cv.CV_CAP_PROP_FRAME_WIDTH))
alto1 = int(video1.get(cv2.cv.CV_CAP_PROP_FRAME_HEIGHT))

#Guardar las dimensiones del segundo video
ancho2 = int(video2.get(cv2.cv.CV_CAP_PROP_FRAME_WIDTH))
alto2 = int(video2.get(cv2.cv.CV_CAP_PROP_FRAME_HEIGHT))

#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 = cv2.cv.CV_FOURCC(*'XVID')

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

while(1):
    #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 = video1.read()
    ret2, frame2 = video2.read()


    #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    
    else:
        break

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

#Si se ha terminado el proceso, limpiar...
video1.release()
video2.release()
out.release()
cv2.destroyAllWindows()

and I present problems here:

ancho1 = int(video1.get(cv2.cv.CV_CAP_PROP_FRAME_WIDTH))
alto1 = int(video1.get(cv2.cv.CV_CAP_PROP_FRAME_HEIGHT))

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
source

1 answer

3

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
source