我正在尝试使用 openCV.NET 来读取扫描的表格。问题在于,有时相关感兴趣区域的位置和对齐方式可能会因打印表单的打印机和用户扫描表单的方式而异。
所以我想我可以使用 ArUco 标记作为参考点,因为已经构建了可以识别它们的库 (ArUco.NET)。我希望找出 ArUco 代码旋转了多少,然后将表单向后旋转该数量以确保文本是直的。然后我可以使用 ArUco 代码的中心作为参考点,在表单上的特定区域使用 OCR。
我正在使用以下代码来获取 OpenGL modelViewMatrix。但是,无论 ArUco 代码旋转哪个角度,它似乎总是相同的数字。我刚刚开始使用所有这些库,但我认为 modelViewMatrix 会根据标记的旋转给我不同的值。为什么总是一样?
Mat cameraMatrix = new Mat(3, 3, Depth.F32, 1);
Mat distortion = new Mat(1, 4, Depth.F32, 1);
using (Mat image2 = OpenCV.Net.CV.LoadImageM("./image.tif", LoadImageFlags.Grayscale))
{
using (var detector = new MarkerDetector())
{
detector.ThresholdMethod = ThresholdMethod.AdaptiveThreshold;
detector.Param1 = 7.0;
detector.Param2 = 7.0;
detector.MinSize = 0.01f;
detector.MaxSize = 0.5f;
detector.CornerRefinement = CornerRefinementMethod.Lines;
var markerSize = 10;
IList<Marker> detectedMarkers = detector.Detect(image2, cameraMatrix, distortion);
foreach (Marker marker in detectedMarkers)
{
Console.WriteLine("Detected a marker top left at: " + marker[0].X + @" " + marker[0].Y);
//Upper 3x3 matrix of modelview matrix (0,4,8,1,5,9,2,6,10) is called rotation matrix.
double[] modelViewMatrix = marker.GetGLModelViewMatrix();
}
}
}