cv:assertion failed with perspectivetransform

I am facing this error while applying homography, (-215:Assertion failed) scn + 1 == m.cols in function 'cv::perspectiveTransform' As pointed out I thought there was problem with length of des1 and des2 being less than 2, idk if that was the case. But I am facing the above error and it has left me scratching my head

Code

#!/usr/bin/env python

import cv2
import numpy as np
from utils import mouse_handler
from utils import get_four_points
import sys


cap = cv2.VideoCapture('2.mp4')
MIN_MATCH_COUNT = 5
#img1 = cv2.imread('b.png', cv2.IMREAD_UNCHANGED)
img1 = cv2.imread('b.png', 0) # Query picture
img2 = cv2.imread('d.png', 0) # training picture
sift = cv2.xfeatures2d.SIFT_create()

# Use SIFT to find key points and descriptors
kp1, des1 = sift.detectAndCompute(img1, None)


# Loop until the end of the video
while (cap.isOpened()):
    ret, frame = cap.read()
    # Display image.
    kp2, des2 = sift.detectAndCompute(frame, None)
    FLANN_INDEX_KDTREE = 0
    index_params = dict(algorithm=FLANN_INDEX_KDTREE, trees=5)
    search_params = dict(checks=50)

    flann = cv2.FlannBasedMatcher(index_params, search_params)
    if (des1 is not None and len(des1) > 2 and des2 is not None and len(des2) > 2):
        matches = flann.knnMatch(des1, des2, k=2)
    #matches = flann.knnMatch(des1, des2, k=2)

that piece of your code seems missing

related: