在标记识别中调整aruco检测参数

时间:2019-09-08 19:41:40

标签: opencv aruco

我有两张非常相似的照片 这是正确识别为5x5_250词典的标记209

marker 209 recognized by Aruco

虽然这另一个非常相似,却无法识别, 它是同一5x5_250词典的标记207:

marker 207 NOT recognized by Aruco

,另外在这张其他照片中也识别出了标记207:

marker 207 recognized

我尝试更改检测器参数

params->adaptiveThreshWinSizeMin = 4;
params->adaptiveThreshWinSizeMax = 26;
params->adaptiveThreshWinSizeStep = 2;
params->minMarkerPerimeterRate = 0.01;
params->maxMarkerPerimeterRate = 4;
params->polygonalApproxAccuracyRate = 0.1;
params->perspectiveRemovePixelPerCell = 10;

但是似乎没有什么变化,所以我回到默认值, 所以我的问题是:

  1. 标记周围是否需要白色边框?
  2. 为什么在第二张照片中无法识别标记207? 谢谢

1 个答案:

答案 0 :(得分:1)

由于ArUco标记检测的第一步是角点检测,因此ArUco标记周围的白色边框是必需的。 供参考,请参见page 4 of the documentation of the ArUco library

不幸的是,切断标记周围的所谓“安静区域”是一个普遍的问题。将来,可能会帮助打印带有其他角的标记,例如:

ArUco marker with corners

要生成角,请运行此代码段并将其拖放到需要的位置。然后右键单击并“将图像另存为...”。

var canvas = document.getElementById("myCanvas");
var context = canvas.getContext("2d");
var theImage = null;

function redraw(){
    if (!theImage){
        context.font = "30px Arial";
        context.fillStyle = "black";
        context.fillText("Drag & Drop image here.", 10, 40);
        return;
    }
    
    var width = theImage.width;
    var height = theImage.height;
    
    var nTiles = 8;
    var padding = 3;
    var cornerLength = 4;
    var dx = width / nTiles;
    var dy = height / nTiles;
    
    canvas.width = 2 * padding * dx + width;
    canvas.height = 2 * padding * dy + height;
    
    // clear background
    context.fillStyle = "#ffffff";
    context.fillRect(0, 0, canvas.width, canvas.height);
    
    // draw corners
    context.fillStyle = "#000000";
    context.fillRect(0, 0, dx, dy * cornerLength);
    context.fillRect(0, 0, cornerLength * dx, dy);
    context.fillRect(canvas.width - dx, canvas.height - dy * cornerLength, dx, dy * cornerLength);
    context.fillRect(canvas.width - cornerLength * dx, canvas.height - dy, cornerLength * dx, dy);
    context.fillRect(canvas.width - dx, 0, dx, dy * cornerLength);
    context.fillRect(canvas.width - cornerLength * dx, 0, dx * cornerLength, dy);
    context.fillRect(0, canvas.height - dy * cornerLength, dx, dy * cornerLength);
    context.fillRect(0, canvas.height - dy, cornerLength * dx, dy);
    
    // draw image
    context.drawImage(theImage, padding * dx, padding * dy);
}

redraw();

function handleFile(file){
    var reader = new FileReader();
    reader.onload = function(){
        var image = new Image();
        image.src = this.result;
        image.onload = function(){
            theImage = image;
            redraw();
        }
    }
    reader.readAsDataURL(file);
}

canvas.addEventListener("dragover", function(e){
    e.preventDefault()
    e.stopPropagation()
})

canvas.addEventListener("drop", function(e){
    var files = e.dataTransfer.files;
    for (var i = 0; i < files.length; i++){
        handleFile(files[i]);
    }
    e.preventDefault()
    e.stopPropagation()
})
<canvas id="myCanvas" width="512" height="512"></canvas>