Home>

An error occurs in the code for projective transformation of the following video.
Why is that? ?

By the way, usually there are many examples where projective transformation is just a still image, but is it possible for a movie? ?

import cv2
import numpy as np
from matplotlib import pyplot as plt

cap = cv2.VideoCapture ('move1.mp4')
while (cap.isOpened ()):
    ret, frame = cap.read ()

# Set corresponding points before and after conversion
    p_original = np.float32 ([[247,388], [805,408], [17, 833], [1063, 860]])
    p_trans = np.float32 ([[0,0], [500,0], [0,690], [500,690]])
# Transformation matrix and projective transformation
    M = cv2.getPerspectiveTransform (p_original, p_trans)
    i_trans = cv2.warpPerspective (frame, M, (500, 690))


    show = cv2.cvtColor (i_trans, cv2.COLOR_BGR2RGB)
    cv2.imshow ('syaei', show)


    if cv2.waitKey (1)&0xFF == ord ('q'):
        break

cap.release ()
cv2.destroyAllWindows ()

This is an error statement

File "syaei.py", line 20, in<module>
    i_trans = cv2.warpPerspective (frame, M, (500, 690))
cv2.error: OpenCV (4.1.1) /Users/travis/build/skvark/opencv-python/opencv/modules/imgproc/src/imgwarp.cpp:2886: error: (-215: Assertion failed) _src.total ( )>0 in function 'warpPerspective'