aruco::detectMarkers 没有找到标记的真实边缘
aruco::detectMarkers is not finding true edges of markers
我正在使用 ArUco 标记来校正透视图并计算图像的大小。在此图像中,我知道标记外边缘之间的确切距离,并使用它来计算黑色矩形的大小。
我的问题是 aruco::detectMarkers
并不总能识别标记的真实边缘(如细节图所示)。当我根据标记的角校正透视时,它会导致失真,影响图像中对象的大小计算。
有没有办法提高aruco::detectMarkers
的边缘检测精度?
这是一张 scaled-down 整个板子的照片:
这里是 lower-left 标记的详细信息,显示了边缘检测的不准确性:
这里是 upper-right 标记的详细信息,显示了相同标记 ID 的准确边缘检测:
在这个缩小的图像中很难看清,但是 upper-left 标记是准确的,而 lower-right 标记是不准确的。
我调用 detectMarkers
的函数:
bool findMarkers(const Mat image, Point2d outerMarkerCoordinates[], Point2d innerMarkerCoordinates[], Size2d *boardSize) {
Ptr<aruco::Dictionary> theDictionary = aruco::getPredefinedDictionary(aruco::DICT_4X4_1000);
vector<vector<Point2f> > markers;
vector<int> ids;
aruco::detectMarkers(image, theDictionary, markers, ids);
aruco::drawDetectedMarkers(image, markers, ids);
return true; //There's actually more code here that makes sure there are four markers.
}
检查 optional detectorParameters
argument 到 detectMarkers
显示了一个名为 doCornerRefinement
的参数。它的描述是"do subpixel refinement or not"。由于我看到的错误大于一个像素,我认为这不适用于我的情况。我还是试了一下,用 cornerRefinementWinSize
值进行了试验,发现它确实解决了我的问题。现在我认为 ArUco 意义上的 "pixel" 是标记内的一个正方形的大小,而不是图像像素。
对 detectMarkers
的修改调用:
bool findMarkers(const Mat image, Point2d outerMarkerCoordinates[], Point2d innerMarkerCoordinates[], Size2d *boardSize) {
Ptr<aruco::Dictionary> theDictionary = aruco::getPredefinedDictionary(aruco::DICT_4X4_1000);
vector<vector<Point2f> > markers;
vector<int> ids;
Ptr<aruco::DetectorParameters> detectorParameters = new aruco::DetectorParameters;
detectorParameters->doCornerRefinement = true;
detectorParameters->cornerRefinementWinSize = 11;
aruco::detectMarkers(image, theDictionary, markers, ids, detectorParameters);
aruco::drawDetectedMarkers(image, markers, ids);
return true; //There's actually more code here that makes sure there are four markers.
}
成功!
我正在使用 ArUco 标记来校正透视图并计算图像的大小。在此图像中,我知道标记外边缘之间的确切距离,并使用它来计算黑色矩形的大小。
我的问题是 aruco::detectMarkers
并不总能识别标记的真实边缘(如细节图所示)。当我根据标记的角校正透视时,它会导致失真,影响图像中对象的大小计算。
有没有办法提高aruco::detectMarkers
的边缘检测精度?
这是一张 scaled-down 整个板子的照片:
这里是 lower-left 标记的详细信息,显示了边缘检测的不准确性:
这里是 upper-right 标记的详细信息,显示了相同标记 ID 的准确边缘检测:
在这个缩小的图像中很难看清,但是 upper-left 标记是准确的,而 lower-right 标记是不准确的。
我调用 detectMarkers
的函数:
bool findMarkers(const Mat image, Point2d outerMarkerCoordinates[], Point2d innerMarkerCoordinates[], Size2d *boardSize) {
Ptr<aruco::Dictionary> theDictionary = aruco::getPredefinedDictionary(aruco::DICT_4X4_1000);
vector<vector<Point2f> > markers;
vector<int> ids;
aruco::detectMarkers(image, theDictionary, markers, ids);
aruco::drawDetectedMarkers(image, markers, ids);
return true; //There's actually more code here that makes sure there are four markers.
}
检查 optional detectorParameters
argument 到 detectMarkers
显示了一个名为 doCornerRefinement
的参数。它的描述是"do subpixel refinement or not"。由于我看到的错误大于一个像素,我认为这不适用于我的情况。我还是试了一下,用 cornerRefinementWinSize
值进行了试验,发现它确实解决了我的问题。现在我认为 ArUco 意义上的 "pixel" 是标记内的一个正方形的大小,而不是图像像素。
对 detectMarkers
的修改调用:
bool findMarkers(const Mat image, Point2d outerMarkerCoordinates[], Point2d innerMarkerCoordinates[], Size2d *boardSize) {
Ptr<aruco::Dictionary> theDictionary = aruco::getPredefinedDictionary(aruco::DICT_4X4_1000);
vector<vector<Point2f> > markers;
vector<int> ids;
Ptr<aruco::DetectorParameters> detectorParameters = new aruco::DetectorParameters;
detectorParameters->doCornerRefinement = true;
detectorParameters->cornerRefinementWinSize = 11;
aruco::detectMarkers(image, theDictionary, markers, ids, detectorParameters);
aruco::drawDetectedMarkers(image, markers, ids);
return true; //There's actually more code here that makes sure there are four markers.
}
成功!