0

I have been trying to warp an image my using opencv 3.1.0, Shape Tranformation class. Specifically, Thin Plate Sline Algorithm

(I actually tried a block of code from Shape Transformers and Interfaces OpenCV3.0 )

But the problem is that I keep gettting runtime time error with the console saying

D:\Project\TPS_Transformation\x64\Debug\TPS_Transformation.exe (process 13776) exited with code -1073741819

I figured out the code that caused the error is tps->estimateTransformation(source, target, matches); which is the part that executes the transformation algorithm for the first time.

I searched the runtime error saying that it could be the dll problem, but I have no problem running opencv in general. I get the error when I run the Shape Transformation algorithm, specifically estimateTranformation function.

#include <iostream>

#include <opencv2\opencv.hpp>
#include <opencv2\imgproc.hpp>
#include "opencv2\shape\shape_transformer.hpp"

using namespace std;
using namespace cv;

int main()
{

    Mat img1 = imread("D:\\Project\\library\\opencv_3.1.0\\sources\\samples\\data\\graf1.png");


    std::vector<cv::Point2f> sourcePoints, targetPoints;
    sourcePoints.push_back(cv::Point2f(0, 0));
    sourcePoints.push_back(cv::Point2f(399, 0));
    sourcePoints.push_back(cv::Point2f(0, 399));
    sourcePoints.push_back(cv::Point2f(399, 399));

    targetPoints.push_back(cv::Point2f(100, 0));
    targetPoints.push_back(cv::Point2f(399, 0));
    targetPoints.push_back(cv::Point2f(0, 399));
    targetPoints.push_back(cv::Point2f(399, 399));

    Mat source(sourcePoints, CV_32FC1);
    Mat target(targetPoints, CV_32FC1);
    Mat respic, resmat;

    std::vector<cv::DMatch> matches;
        for (unsigned int i = 0; i < sourcePoints.size(); i++)
            matches.push_back(cv::DMatch(i, i, 0));

    Ptr<ThinPlateSplineShapeTransformer> tps = createThinPlateSplineShapeTransformer(0);
    tps->estimateTransformation(source, target, matches);
    std::vector<cv::Point2f> transPoints;
    tps->applyTransformation(source, target);

    cout << "sourcePoints = " << endl << " " << sourcePoints << endl << endl;
    cout << "targetPoints = " << endl << " " << targetPoints << endl << endl;
    //cout << "transPos = " << endl << " " << transPoints << endl << endl;
    cout << img1.size() << endl;

    imshow("img1", img1); // Just to see if I have a good picture

    tps->warpImage(img1, respic);

    imshow("Tranformed", respic); //Always completley grey ?
    waitKey(0);

    return 0;
}

I just want to be able to run the algorithm so that I can check if it is the algorithm that I want.

Please help.

Thank you.

opencv-version 3.1.0

IDE: Visual Studio 2015

OS : Windows 10

1 Answers1

1

Try adding

transpose(source, source);
transpose(target, target);

before estimateTransformation().

See https://answers.opencv.org/question/69384/shape-transformers-and-interfaces/.

Zeyu Wang
  • 21
  • 2