Ask Your Question
0

What is the reverse of warpPerspective ?

asked 2017-01-05 03:03:11 -0600

BenNG gravatar image

updated 2017-01-05 03:34:42 -0600

Hi all !

At the bottom of this link, a transformation extract the sudoku in "full screen".

I would like to draw some text on the extracted sudoku and re introduce it in the big picture. Do you know how can I re introduce it ?

Here is the code I use:

/**
coordinates is a std::vector<Point2f> with inside:
[topLeft, topRight, bottomLeft, bottomRight]  

original is the original picture (the left one in the link) and sudoku is the right one

*/

float w = (float)input.cols;
float h = (float)input.rows;
float hw = w / 2.0f;
float hh = h / 2.0f;

// to points
dst_p[0] = Point2f(0.0f, 0.0f);
dst_p[1] = Point2f(w, 0.0f);
dst_p[2] = Point2f(w, h);
dst_p[3] = Point2f(0.0f, h);

// create perspective transform matrix
Mat trans_mat33 = getPerspectiveTransform(coordinates, dst_p); //CV_64F->double
Mat inv_trans_mat33 = getPerspectiveTransform(dst_p, coordinates);
// perspective transform operation using transform matrix
warpPerspective(input, sudoku, trans_mat33, input.size(), INTER_LINEAR);

sudoku = writeOnPuzzle(sudoku, "012345000000000000000000000000000000000000000000000000000000000000000000000000000");

invert(trans_mat33, inv_trans_mat33);
warpPerspective(sudoku, original, trans_mat33, input.size(), WARP_INVERSE_MAP);

Thank you !

edit retag flag offensive close merge delete

Comments

Somebody ask the same question here without answer:

BenNG gravatar imageBenNG ( 2017-01-05 03:05:48 -0600 )edit

can you try, if WARP_INVERSE_MAP does the job ?

also, much appreciated, if you'd replace the link with the code, you're actually using !

berak gravatar imageberak ( 2017-01-05 03:26:44 -0600 )edit
1

It does the job yes but the background is black :(

BenNG gravatar imageBenNG ( 2017-01-05 03:35:11 -0600 )edit

1 answer

Sort by ยป oldest newest most voted
0

answered 2017-01-05 04:19:16 -0600

BenNG gravatar image

By using this:

    warpPerspective(sudoku, original, trans_mat33, input.size(), WARP_INVERSE_MAP, BORDER_TRANSPARENT);

I managed to re introduce the sudoku I had modified

Thank you !

edit flag offensive delete link more

Question Tools

1 follower

Stats

Asked: 2017-01-05 03:03:11 -0600

Seen: 6,997 times

Last updated: Jan 05 '17