我是 OpenCV 的新手,但凭借一点运气和大量时间,我能够编写一些代码来检测棋盘中的单个单元,如下所示:
图像帧存储在 Mat 中角点存储在 MatOfPoint2f 中.
显示我如何使用矩阵单独绘制单元格的代码:
private void draw(final Mat frame) {
for (int x = 0; x < BOARD_SIZE - 1; x++)
for (int y = 0; y < BOARD_SIZE - 1; y++) {
final int index = x + y * BOARD_SIZE;
final Point topLeft = cornerPoints.get(index);
final Point bottomLeft = cornerPoints.get(index + BOARD_SIZE);
final Point topRight = cornerPoints.get(index + 1);
final Point bottomRight = cornerPoints.get(index + 1 + BOARD_SIZE);
// left line
Imgproc.line(frame, topLeft, bottomLeft, DEBUG_COLOR);
// right line
Imgproc.line(frame, topRight, bottomRight, DEBUG_COLOR);
// top line
Imgproc.line(frame, topLeft, topRight, DEBUG_COLOR);
// bottom line
Imgproc.line(frame, bottomLeft, bottomRight, DEBUG_COLOR);
}
}
如何使用四个点(单元格的角)来获取每个四边形内部像素的 RGB 值?
最佳答案
从顶点创建蒙版。您可以使用 fillPoly 来实现这一点。 然后迭代像素。如果像素(x,y)在您的掩码中有效,则读取 RGB,否则继续。使用极端顶点限制像素迭代范围。
关于java - 如何在OpenCV中获取由四个点定义的四边形内部的像素?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/35262858/