GIVEN:
A matrix (N, 3) build from a point cloud, i.e. a vector<Point3d>
std::vector<cv::Point3d> pcVector = ... // from somewhere
cv::Mat pcMat = cv::Mat(pcVector).reshape(1);
Thus having pcMat
to be something like:
[ 0.1, 1.3, 4.5 ]
[ 3.1, 1.4, 7.6 ]
...
[ 1.1, 3.4, 4.1 ]
GOAL:
An efficient method to get a column of ones added to the matrix. That is to receive a matrix like the following from the above.
[ 0.1, 1.3, 4.5, 1.0 ]
[ 3.1, 1.4, 7.6, 1.0 ]
...
[ 1.1, 3.4, 4.1, 1.0 ]
CURRENTLY:
cv::Mat result(N, 4);
cv::Mat ones = cv::Mat_<double>::ones(N, 1);
cv::hconcat(pcMat, ones, result);
QUESTION:
This seems to be inefficient since a temporary matrix full of ones needs to be created. Are there any tricks to get this done faster?