# cv:assertion failed with perspectivetransform

**URL:** <https://forum.opencv.org/t/cv-assertion-failed-with-perspectivetransform/5356>\
**Category:** Python\
**Created:** [September 26, 2021, 2:09pm UTC](https://forum.opencv.org/t/cv-assertion-failed-with-perspectivetransform/5356 "2021-09-26T14:09:54Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![zexapod](https://sea2.discourse-cdn.com/flex020/user_avatar/forum.opencv.org/zexapod/32/3272_2.png) [@zexapod](https://forum.opencv.org/u/zexapod)\
**Post date:** [September 26, 2021, 2:09pm UTC](https://forum.opencv.org/t/cv-assertion-failed-with-perspectivetransform/5356/1 "2021-09-26T14:09:54Z")

</div>

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

```auto
#!/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)

```

---

<div class="post-metadata">

**Author:** ![berak](https://avatars.discourse-cdn.com/v4/letter/b/85f322/32.png) [@berak](https://forum.opencv.org/u/berak)\
**Post date:** [September 26, 2021, 2:17pm UTC](https://forum.opencv.org/t/cv-assertion-failed-with-perspectivetransform/5356/2 "2021-09-26T14:17:05Z")

</div>

> [@zexapod](#):
>
> I am facing this error while applying homography,

that piece of your code seems missing

---

<div class="post-metadata">

**Author:** ![crackwitz](https://sea2.discourse-cdn.com/flex020/user_avatar/forum.opencv.org/crackwitz/32/14_2.png) [@crackwitz](https://forum.opencv.org/u/crackwitz)\
**Post date:** [September 26, 2021, 3:15pm UTC](https://forum.opencv.org/t/cv-assertion-failed-with-perspectivetransform/5356/3 "2021-09-26T15:15:53Z")

</div>

related:

> <https://stackoverflow.com/questions/69328130/cvassertion-failed-with-perspectivetransform>
