Ask Your Question
2

Wasteful code?

asked 2017-04-06 04:27:21 -0600

yakuto4 gravatar image

updated 2017-04-06 04:37:53 -0600

berak gravatar image
hi
I Check this code from: 

 opencv32\opencv_contrib\modules\sfm\src\simple_pipeline.cpp

and i found faster code.
->

    libmv_reconstruction_.reconstruction.AllPoints()[i].X[j]

 should be: 

    libmv:: vector<EuclideanPoint> Points = libmv_reconstruction_.reconstruction.AllPoints();

and  change to Points [i].X[j]

-------------------------------------

    getPoints(OutputArray points3d) {
        const size_t n_points =
          libmv_reconstruction_.reconstruction.AllPoints().size();

        points3d.create(n_points, 1, CV_64F);

        Vec3d point3d;
        for ( size_t i = 0; i < n_points; ++i )
        {
          for ( int j = 0; j < 3; ++j )
            point3d[j] =  libmv_reconstruction_.reconstruction.AllPoints()[i].X[j];
          Mat(point3d).copyTo(points3d.getMatRef(i));
        }

      }

-------------------------------------
getPoints(OutputArray points3d) {
    libmv:: vector<EuclideanPoint> points = libmv_reconstruction_.reconstruction.AllPoints();
    const size_t n_points = points.size();
    points3d.create(n_points, 1, CV_64F);

    Vec3d point3d;
    for ( size_t i = 0; i < n_points; ++i )
    {
      for ( int j = 0; j < 3; ++j )
        point3d[j] = points[i].X[j];
      Mat(point3d).copyTo(points3d.getMatRef(i));
    }
  }

thanks

edit retag flag offensive close merge delete

Comments

Have you test this code? I have got an exceptionat line points3d.create(n_points, 1, CV_64F);

LBerger gravatar imageLBerger ( 2017-05-09 15:00:16 -0600 )edit

I test this code on Visual Studio 2015 communication c++

thanks

yakuto4 gravatar imageyakuto4 ( 2017-05-10 00:36:05 -0600 )edit

1 answer

Sort by ยป oldest newest most voted
2

answered 2017-04-06 05:14:42 -0600

berak gravatar image

yea, AllPoints() will do a deep copy each time it is called, so wasteful.

(though getPoints() will be only called once per reconstruction attempt, so probably not that important (think 80/20))

still, maybe make an issue / pr here ?

edit flag offensive delete link more

Question Tools

1 follower

Stats

Asked: 2017-04-06 04:27:21 -0600

Seen: 254 times

Last updated: Apr 06 '17