Aruco opencv使用过程中的问题记录及解决方案
编译环境:
windows10
vs2103+win32 debug
opencv3.1.0+opencv_contrib-3.1.0
1. aruco board 生成显示标记板的对象指针问题
问题描述:
aruco::GridBoard::create()这个返回值的类型是GridBoard,导致draw()前指针引用无法正常使用
在网上可以找到的两种示例写法,一种是使用auto声明变量、一种是直接生成指针类型对象,这应该是往期版本的contrib里,aruco 生成标记板的函数的返回值就是board的指针类型,这一点在看https://www.cnblogs.com/qsm2020/p/14139183.html源码分析的时候也可以得到印证。
//auto写法
auto dictionary = aruco::getPredefinedDictionary(DICT_6X6_250);
auto board = aruco::GridBoard::create(5, 7, 0.04, 0.01, dictionary);
Mat boardImg;
board->draw(Size(600, 800), boardImg, 10, 1);
imshow("boardImg", boardImg);
//声明生成指针写法
cv::Ptr<cv::aruco::GridBoard> board = cv::aruco::GridBoard::create(5, 7, 0.04, 0.01, dictionary);
cv::Mat boardImage;
board->draw( cv::Size(600, 500), boardImage, 10, 1 );
但是我使用的3.1.0这个版本,它的函数已经更新,现在的返回值已经是gridboard类型了,具体源码的函数定义如下,所以以上两种写法都不可行;
/**
* @brief Create a GridBoard object
*
* @param markersX number of markers in X direction
* @param markersY number of markers in Y direction
* @param markerLength marker side length (normally in meters)
* @param markerSeparation separation between two markers (same unit than markerLenght)
* @param dictionary dictionary of markers indicating the type of markers.
* The first markersX*markersY markers in the dictionary are used.
* @return the output GridBoard object
*
* This functions creates a GridBoard object given the number of markers in each direction and
* the marker size and marker separation.
*/
static GridBoard create(int markersX, int markersY, float markerLength, float markerSeparation,
Dictionary dictionary);
解决方案:
-
成员函数可以直接使用! cv::aruco::GridBoard board = cv::aruco::GridBoard::create(5, 7, 0.04, 0.01, dictionary);
cv::Mat boardImage;
board.draw( cv::Size(600, 500), boardImage, 10, 1 );
-
使用opencv的指针类型为其创建指针索引(可以,但没必要) cv::aruco::GridBoard board = cv::aruco::GridBoard::create(5, 7, 0.04, 0.01, dictionary);
cv::Ptr<cv::aruco::GridBoard> pboard = cv::makePtr<cv::aruco::GridBoard>(board);
cv::Mat boardImage;
pboard->draw( cv::Size(600, 500), boardImage, 10, 1 );
|