Ask Your Question
3

Shape Transformers and Interfaces

asked 2015-08-25 09:23:19 -0600

Ives gravatar image

Hi, I was trying to make use of the new Shape Transformers and Interfaces. Unfortunately it doesn't work as expected. To ensure not making any fancy warps and getting strange results cause of that reason I initialized a transformation where nothing at all should happen. But output for transformation for a testpoint is always [0,0] and the warped image is always completley gray. Any suggestions what could be wrong are welcome.

int main(void)
{
    Mat img1 = imread("C:\\opencv\\sources\\samples\\data\\graf1.png", IMREAD_GRAYSCALE);
    std::vector<cv::Point2f> points1, testpoints;
    vector<DMatch> good_matches;
    Mat respic, resmat;

    points1.push_back(Point(0, 0)); //Corners 800x600 pic
    points1.push_back(Point(799, 0));
    points1.push_back(Point(799, 599));
    points1.push_back(Point(0, 599));

    Mat pointmatrix1(points1);

    good_matches.push_back(DMatch(0, 0, 0));
    good_matches.push_back(DMatch(1, 1, 0));
    good_matches.push_back(DMatch(2, 2, 0));
    good_matches.push_back(DMatch(3, 3, 0));

    testpoints.push_back(Point(250, 250));
    Mat testpointsmat(testpoints);

    // Apply TPS
    Ptr<ThinPlateSplineShapeTransformer> mytps = createThinPlateSplineShapeTransformer(0);
    mytps->estimateTransformation(pointmatrix1, pointmatrix1, good_matches); // Using same pointmatrix nothing should change in res
    mytps->applyTransformation(testpointsmat, resmat);

    cout << "pointmatrix1 = " << endl << " " << pointmatrix1 << endl << endl;
    cout << "testpointsmat = " << endl << " " << testpointsmat << endl << endl;
    cout << "resmat = " << endl << " " << resmat << endl << endl; //Always [0,0] ?

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

    mytps->warpImage(img1, respic);

    imwrite("Tranformed.png", respic);
    imshow("Tranformed", respic); //Always completley grey ?

    waitKey(0);

    return 0;
}
edit retag flag offensive close merge delete

1 answer

Sort by ยป oldest newest most voted
5

answered 2015-08-25 10:36:06 -0600

LBerger gravatar image

updated 2015-08-25 11:33:43 -0600

Don't ask me why but if you add this two lines it works om my computer

   // Apply TPS
    transpose(pointmatrix1, pointmatrix1); // ADD
    transpose(testpoints, testpoints); // ADD
    Ptr<ThinPlateSplineShapeTransformer> mytps = createThinPlateSplineShapeTransformer(0);
    mytps->estimateTransformation(pointmatrix1, pointmatrix1, good_matches); // Using same pointmatrix nothing should change in res
    mytps->applyTransformation(testpointsmat, resmat);

Now There is something strange in source code here why cols and not rows

Following remarks of @juanmanpr That's can be done too

   // Apply TPS
    Ptr<ThinPlateSplineShapeTransformer> mytps = createThinPlateSplineShapeTransformer(0);
    mytps->estimateTransformation(points1, points1, good_matches); // Using same pointmatrix nothing should change in res
    mytps->applyTransformation(testpointsmat, resmat);

that's better thanks @juanmanpr

edit flag offensive delete link more

Comments

1

Apparently it is the format is used by the ShapeContextDescriptor. I agree it is strange, this constraint should be added to the documentation, or a PR should be added so the TPSTransformer accepts both types of data. It should work when the input data is a vector of points though.

juanmanpr gravatar imagejuanmanpr ( 2015-08-25 11:20:10 -0600 )edit

Question Tools

1 follower

Stats

Asked: 2015-08-25 09:23:19 -0600

Seen: 2,461 times

Last updated: Aug 25 '15