Ask Your Question
1

opencv Mat points to acess Mat image in one line

asked 2017-02-06 04:28:42 -0600

Abs gravatar image

updated 2017-02-06 04:56:16 -0600

I have an Mat image and a Mat of points containing few coordinates. I want to extract and make another Mat variable from the Mat image pixels at the points stored in the Mat of points without using for loop. Currently I am using for loop but want to make it faster.

`for(int kk=0;kk < cAM.cd[ii].ind_in.rows; kk++)
   {
        I.at < float > (kk,0)=Iw.at < float > (cAM.cd[ii].ind_in.at < Point > (kk,0).y, cAM.cd[ii].ind_in.at < Point > (kk,0).x);
   }`

Here I have coordinates in "cAM.cd[ii].ind_in" and Iw a Mat type image. I want a linear Mat I with all pixel values in Iw at those coordinates.

edit retag flag offensive close merge delete

1 answer

Sort by ยป oldest newest most voted
1

answered 2017-02-06 06:52:56 -0600

LBerger gravatar image

You can use remap. I copy x diagonal in dst :

    Mat x = (Mat_<uchar>(3, 3) << 1, 2, 3, 4, 5, 6, 7, 8, 9);
    Mat map(1, 3, CV_32FC2);
        for (int j = 0; j<map.cols; j++)
                map.at<Point2f>(0, j) = Point2f(j, j);
       Mat dst;
    remap(x, dst, map, Mat(), INTER_NEAREST);
    cout << x << endl;
    cout << dst << endl;

results are

x=[  1,   2,   3;
   4,   5,   6;
   7,   8,   9]
dst=[  1,   5,   9]
edit flag offensive delete link more

Comments

Thanks a lot @LBerger. It solved my problem.

Abs gravatar imageAbs ( 2017-02-06 23:40:26 -0600 )edit

Question Tools

1 follower

Stats

Asked: 2017-02-06 04:24:45 -0600

Seen: 576 times

Last updated: Feb 06 '17