Attention! This forum will be made read-only by Dec-20. Please migrate to https://forum.opencv.org. Most of existing active users should've received invitation by e-mail.
Ask Your Question
1

How to convert a CV_32SC1 to int

asked 2014-03-29 22:38:35 -0500

Higerra gravatar image

updated 2014-03-30 01:52:56 -0500

berak gravatar image

I'm now using opencv for super-resolution. In one step I have to get the affine matrix and apply the transform to another matrix (which is not a Mat). I have some problems when trying to get the data from affine matrix (a 2*3 Mat). My code:

    Mat affine = Mat(2,3,CV_32SC1);
    affine = getAffineTransform(corners_cur, corners_ref);
    cout<<affine<<endl;
    for(int y=0;y<2;y++)
    {
        for(int x=0;x<3;x++)
            cout<<affine.at<int>(y,x)<<' ';
        cout<<endl;
    }

I output the 'affine' matrix twice, using different methods. The results is as below:

[1.004656149032001, -0.02000349563412032, 2.860194169683911; 0.01286062523971824, 0.9765526069572313, 1.203057387073405]

1400706429 1072698130 -566786328 -428060329 1066030763 1085705763

The first one seems to be reasonable, but the second one is totally a mess. I suppose the problem occurs when forcing CV_32SC1 to int but I don't know how to convert the data type properly.

edit retag flag offensive close merge delete

1 answer

Sort by ยป oldest newest most voted
3

answered 2014-03-30 02:09:11 -0500

berak gravatar image

getAffineTransform returns a (float or double) Mat.

so your initial assignment gets overwritten / ignored. (a integer Mat does not make much sense anyway for a transformation)

and yes, trying to acccess a float Mat with at<int> will make a mess of it.

again, your assumption that it was int is wrong in the 1st place.

edit flag offensive delete link more
Login/Signup to Answer

Question Tools

Stats

Asked: 2014-03-29 22:38:35 -0500

Seen: 685 times

Last updated: Mar 29 '14