Commit d07e70a4 authored by Pavel Rojtberg's avatar Pavel Rojtberg

aruco: use Mat().copyTo idiom instead of for loops

parent a7ad78b9
...@@ -920,13 +920,8 @@ static void _getBoardObjectAndImagePoints(const Ptr<Board> &_board, InputArray _ ...@@ -920,13 +920,8 @@ static void _getBoardObjectAndImagePoints(const Ptr<Board> &_board, InputArray _
} }
// create output // create output
_objPoints.create((int)objPnts.size(), 1, CV_32FC3); Mat(objPnts).copyTo(_objPoints);
for(unsigned int i = 0; i < objPnts.size(); i++) Mat(imgPnts).copyTo(_imgPoints);
_objPoints.getMat().ptr< Point3f >(0)[i] = objPnts[i];
_imgPoints.create((int)objPnts.size(), 1, CV_32FC2);
for(unsigned int i = 0; i < imgPnts.size(); i++)
_imgPoints.getMat().ptr< Point2f >(0)[i] = imgPnts[i];
} }
...@@ -937,7 +932,7 @@ static void _getBoardObjectAndImagePoints(const Ptr<Board> &_board, InputArray _ ...@@ -937,7 +932,7 @@ static void _getBoardObjectAndImagePoints(const Ptr<Board> &_board, InputArray _
static void _projectUndetectedMarkers(const Ptr<Board> &_board, InputOutputArrayOfArrays _detectedCorners, static void _projectUndetectedMarkers(const Ptr<Board> &_board, InputOutputArrayOfArrays _detectedCorners,
InputOutputArray _detectedIds, InputArray _cameraMatrix, InputOutputArray _detectedIds, InputArray _cameraMatrix,
InputArray _distCoeffs, InputArray _distCoeffs,
OutputArrayOfArrays _undetectedMarkersProjectedCorners, vector< vector< Point2f > >& _undetectedMarkersProjectedCorners,
OutputArray _undetectedMarkersIds) { OutputArray _undetectedMarkersIds) {
// first estimate board pose with the current avaible markers // first estimate board pose with the current avaible markers
...@@ -972,18 +967,8 @@ static void _projectUndetectedMarkers(const Ptr<Board> &_board, InputOutputArray ...@@ -972,18 +967,8 @@ static void _projectUndetectedMarkers(const Ptr<Board> &_board, InputOutputArray
// parse output // parse output
_undetectedMarkersIds.create((int)undetectedIds.size(), 1, CV_32SC1); Mat(undetectedIds).copyTo(_undetectedMarkersIds);
for(unsigned int i = 0; i < undetectedIds.size(); i++) _undetectedMarkersProjectedCorners = undetectedCorners;
_undetectedMarkersIds.getMat().ptr< int >(0)[i] = undetectedIds[i];
_undetectedMarkersProjectedCorners.create((int)undetectedCorners.size(), 1, CV_32FC2);
for(unsigned int i = 0; i < undetectedCorners.size(); i++) {
_undetectedMarkersProjectedCorners.create(4, 1, CV_32FC2, i, true);
for(int j = 0; j < 4; j++) {
_undetectedMarkersProjectedCorners.getMat(i).ptr< Point2f >()[j] =
undetectedCorners[i][j];
}
}
} }
...@@ -994,7 +979,7 @@ static void _projectUndetectedMarkers(const Ptr<Board> &_board, InputOutputArray ...@@ -994,7 +979,7 @@ static void _projectUndetectedMarkers(const Ptr<Board> &_board, InputOutputArray
*/ */
static void _projectUndetectedMarkers(const Ptr<Board> &_board, InputOutputArrayOfArrays _detectedCorners, static void _projectUndetectedMarkers(const Ptr<Board> &_board, InputOutputArrayOfArrays _detectedCorners,
InputOutputArray _detectedIds, InputOutputArray _detectedIds,
OutputArrayOfArrays _undetectedMarkersProjectedCorners, vector< vector< Point2f > >& _undetectedMarkersProjectedCorners,
OutputArray _undetectedMarkersIds) { OutputArray _undetectedMarkersIds) {
...@@ -1042,20 +1027,14 @@ static void _projectUndetectedMarkers(const Ptr<Board> &_board, InputOutputArray ...@@ -1042,20 +1027,14 @@ static void _projectUndetectedMarkers(const Ptr<Board> &_board, InputOutputArray
// get homography from detected markers // get homography from detected markers
Mat transformation = findHomography(detectedMarkersObj2DAll, imageCornersAll); Mat transformation = findHomography(detectedMarkersObj2DAll, imageCornersAll);
_undetectedMarkersProjectedCorners.create((int)undetectedMarkersIds.size(), 1, CV_32FC2); _undetectedMarkersProjectedCorners.resize(undetectedMarkersIds.size());
// for each undetected marker, apply transformation // for each undetected marker, apply transformation
for(unsigned int i = 0; i < undetectedMarkersObj2D.size(); i++) { for(unsigned int i = 0; i < undetectedMarkersObj2D.size(); i++) {
Mat projectedMarker; perspectiveTransform(undetectedMarkersObj2D[i], _undetectedMarkersProjectedCorners[i], transformation);
perspectiveTransform(undetectedMarkersObj2D[i], projectedMarker, transformation);
_undetectedMarkersProjectedCorners.create(4, 1, CV_32FC2, i, true);
projectedMarker.copyTo(_undetectedMarkersProjectedCorners.getMat(i));
} }
_undetectedMarkersIds.create((int)undetectedMarkersIds.size(), 1, CV_32SC1); Mat(undetectedMarkersIds).copyTo(_undetectedMarkersIds);
for(unsigned int i = 0; i < undetectedMarkersIds.size(); i++)
_undetectedMarkersIds.getMat().ptr< int >(0)[i] = undetectedMarkersIds[i];
} }
...@@ -1216,9 +1195,7 @@ void refineDetectedMarkers(InputArray _image, const Ptr<Board> &_board, ...@@ -1216,9 +1195,7 @@ void refineDetectedMarkers(InputArray _image, const Ptr<Board> &_board,
_detectedIds.clear(); _detectedIds.clear();
// parse output // parse output
_detectedIds.create((int)finalAcceptedIds.size(), 1, CV_32SC1); Mat(finalAcceptedIds).copyTo(_detectedIds);
for(unsigned int i = 0; i < finalAcceptedIds.size(); i++)
_detectedIds.getMat().ptr< int >(0)[i] = finalAcceptedIds[i];
_detectedCorners.create((int)finalAcceptedCorners.size(), 1, CV_32FC2); _detectedCorners.create((int)finalAcceptedCorners.size(), 1, CV_32FC2);
for(unsigned int i = 0; i < finalAcceptedCorners.size(); i++) { for(unsigned int i = 0; i < finalAcceptedCorners.size(); i++) {
...@@ -1248,10 +1225,7 @@ void refineDetectedMarkers(InputArray _image, const Ptr<Board> &_board, ...@@ -1248,10 +1225,7 @@ void refineDetectedMarkers(InputArray _image, const Ptr<Board> &_board,
} }
if(_recoveredIdxs.needed()) { if(_recoveredIdxs.needed()) {
_recoveredIdxs.create((int)recoveredIdxs.size(), 1, CV_32SC1); Mat(recoveredIdxs).copyTo(_recoveredIdxs);
for(unsigned int i = 0; i < recoveredIdxs.size(); i++) {
_recoveredIdxs.getMat().ptr< int >()[i] = recoveredIdxs[i];
}
} }
} }
} }
......
...@@ -230,7 +230,7 @@ void CharucoBoard::_getNearestMarkerCorners() { ...@@ -230,7 +230,7 @@ void CharucoBoard::_getNearestMarkerCorners() {
/** /**
* Remove charuco corners if any of their minMarkers closest markers has not been detected * Remove charuco corners if any of their minMarkers closest markers has not been detected
*/ */
static unsigned int _filterCornersWithoutMinMarkers(const Ptr<CharucoBoard> &_board, static int _filterCornersWithoutMinMarkers(const Ptr<CharucoBoard> &_board,
InputArray _allCharucoCorners, InputArray _allCharucoCorners,
InputArray _allCharucoIds, InputArray _allCharucoIds,
InputArray _allArucoIds, int minMarkers, InputArray _allArucoIds, int minMarkers,
...@@ -265,17 +265,9 @@ static unsigned int _filterCornersWithoutMinMarkers(const Ptr<CharucoBoard> &_bo ...@@ -265,17 +265,9 @@ static unsigned int _filterCornersWithoutMinMarkers(const Ptr<CharucoBoard> &_bo
} }
// parse output // parse output
_filteredCharucoCorners.create((int)filteredCharucoCorners.size(), 1, CV_32FC2); Mat(filteredCharucoCorners).copyTo(_filteredCharucoCorners);
for(unsigned int i = 0; i < filteredCharucoCorners.size(); i++) { Mat(filteredCharucoIds).copyTo(_filteredCharucoIds);
_filteredCharucoCorners.getMat().at< Point2f >(i) = filteredCharucoCorners[i]; return (int)_filteredCharucoIds.total();
}
_filteredCharucoIds.create((int)filteredCharucoIds.size(), 1, CV_32SC1);
for(unsigned int i = 0; i < filteredCharucoIds.size(); i++) {
_filteredCharucoIds.getMat().at< int >(i) = filteredCharucoIds[i];
}
return (unsigned int)filteredCharucoCorners.size();
} }
...@@ -326,7 +318,7 @@ class CharucoSubpixelParallel : public ParallelLoopBody { ...@@ -326,7 +318,7 @@ class CharucoSubpixelParallel : public ParallelLoopBody {
* @brief From all projected chessboard corners, select those inside the image and apply subpixel * @brief From all projected chessboard corners, select those inside the image and apply subpixel
* refinement. Returns number of valid corners. * refinement. Returns number of valid corners.
*/ */
static unsigned int _selectAndRefineChessboardCorners(InputArray _allCorners, InputArray _image, static int _selectAndRefineChessboardCorners(InputArray _allCorners, InputArray _image,
OutputArray _selectedCorners, OutputArray _selectedCorners,
OutputArray _selectedIds, OutputArray _selectedIds,
const vector< Size > &winSizes) { const vector< Size > &winSizes) {
...@@ -380,17 +372,9 @@ static unsigned int _selectAndRefineChessboardCorners(InputArray _allCorners, In ...@@ -380,17 +372,9 @@ static unsigned int _selectAndRefineChessboardCorners(InputArray _allCorners, In
CharucoSubpixelParallel(&grey, &filteredChessboardImgPoints, &filteredWinSizes, params)); CharucoSubpixelParallel(&grey, &filteredChessboardImgPoints, &filteredWinSizes, params));
// parse output // parse output
_selectedCorners.create((int)filteredChessboardImgPoints.size(), 1, CV_32FC2); Mat(filteredChessboardImgPoints).copyTo(_selectedCorners);
for(unsigned int i = 0; i < filteredChessboardImgPoints.size(); i++) { Mat(filteredIds).copyTo(_selectedIds);
_selectedCorners.getMat().at< Point2f >(i) = filteredChessboardImgPoints[i]; return (int)filteredChessboardImgPoints.size();
}
_selectedIds.create((int)filteredIds.size(), 1, CV_32SC1);
for(unsigned int i = 0; i < filteredIds.size(); i++) {
_selectedIds.getMat().at< int >(i) = filteredIds[i];
}
return (unsigned int)filteredChessboardImgPoints.size();
} }
...@@ -863,11 +847,8 @@ void detectCharucoDiamond(InputArray _image, InputArrayOfArrays _markerCorners, ...@@ -863,11 +847,8 @@ void detectCharucoDiamond(InputArray _image, InputArrayOfArrays _markerCorners,
if(diamondIds.size() > 0) { if(diamondIds.size() > 0) {
// parse output // parse output
_diamondIds.create((int)diamondIds.size(), 1, CV_32SC4); Mat(diamondIds).copyTo(_diamondIds);
for(unsigned int i = 0; i < diamondIds.size(); i++)
_diamondIds.getMat().at< Vec4i >(i) = diamondIds[i];
_diamondCorners.create((int)diamondCorners.size(), 1, CV_32FC2); _diamondCorners.create((int)diamondCorners.size(), 1, CV_32FC2);
for(unsigned int i = 0; i < diamondCorners.size(); i++) { for(unsigned int i = 0; i < diamondCorners.size(); i++) {
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment