Debug assertion failed when using perspectiveTransform

asked 2018-07-31 10:32:23 -0500

updated 2018-07-31 13:43:42 -0500

I'm trying to use perspectiveTransform for correcting a point in the video stream from camera. To do so I wrote this code. It is running when tranformation matrix transform is already calculated using getPerspectiveTransform function.

if (isPointsSet) {
    vector <Point2f> transformedPoints, srcPoints;
    srcPoints.clear();
    // getting all objects in frame
    for (int i = 0; i < frame->ObjectCount(); i++)
    {
            cObject *obj = frame->Object(i);
            srcPoints.push_back((Point2f)(obj->X(), obj->Y()));
    }
    // applying transformation matrix
    perspectiveTransform(srcPoints, transformedPoints, transform);
    for (auto i : transformedPoints) {
            std::cout << '\n' << i.x << ' ' << i.y;
    }               
}

It runs fine for a first time, but after in the next run it causes Debug assertion failed!error. Where is the problem might be?

This is how I'm creating a transformation matrix:

Mat transform
/* some code here */
transform = getPerspectiveTransform(cameraAnchorPoints, anchorPoints);

cameraAnchorPoints and anchorPoints are vectors of four Point2f

edit retag flag offensive close merge delete