绘制全屏棋盘图案?

Drawing full screen chessboard pattern?

我在 OpenCV 工作(相机校准,然后创建 3d 模型),直到现在我总是在纸上打印棋盘格图案,然后拍摄校准所需的照片。我试图找到一种方法来在全屏上绘制带有预定义正方形大小的图案(这样我就可以在校准过程中设置正方形大小),但我只找到了 Python 海龟模块,它似乎只用于在屏幕的一部分上绘制,它总是在最后一个方块上绘制一个箭头。我需要绘制与屏幕边界有一些小偏移的图案,并在这些偏移内绘制一个具有统一正方形的棋盘。另外,我看到有些人在 GIMP 中绘制图案,但不是在全屏上。

OpenCV有drawChessboardCorners的功能,但是它需要从之前导入的图像中建立角点,需要校准,所以我认为它没有意义。

如果有人知道如何解决这个问题,无论是使用某种程序还是某种编程语言的模块(Python 如果可能),我将不胜感激。

在您最喜欢的图形编辑器中准备您的棋盘图案,将文件保存到您要用于显示它以进行校准的计算机上,然后在需要时显示它。我想你可能是 over-thinking 问题...

I only found turtle module which seems to be only for drawing on part of screen and it always draws arrow on last square.

让我们通过在屏幕大小的 window 中绘制一个网格来避免这两个问题,最后一个方块上没有箭头:

from turtle import Screen, Turtle

BLOCK_SIZE = 72  # pixels
CURSOR_SIZE = 20  # pixels

BORDER = 1  # blocks

screen = Screen()
screen.setup(1.0, 1.0)  # display size window
width, height = screen.window_width(), screen.window_height()
screen.setworldcoordinates(0, 0, width, height)

block = Turtle('square', visible=False)  # hide the cursor completely
block.pencolor('black')
block.shapesize(BLOCK_SIZE / CURSOR_SIZE)
block.penup()

x_count = width // BLOCK_SIZE - BORDER * 2
x_width = x_count * BLOCK_SIZE
x_start = (width - x_width) // 2
x_limit = x_width + (BORDER + 1) * BLOCK_SIZE

y_count = height // BLOCK_SIZE - BORDER * 2
y_height = y_count * BLOCK_SIZE
y_start = (height - y_height) // 2
y_limit = y_height + (BORDER + 1) * BLOCK_SIZE

screen.tracer(False)

for parity_y, y in enumerate(range(y_start, y_limit, BLOCK_SIZE)):
    block.sety(y)

    for parity_x, x in enumerate(range(x_start, x_limit, BLOCK_SIZE)):
        block.fillcolor(['white', 'black'][(parity_y % 2) == (parity_x % 2)])
        block.setx(x)
        block.stamp()

screen.tracer(True)
screen.mainloop()

(如果您想覆盖更多屏幕,请将扩展坞隐藏在 OS X 中。)

不幸的是,这是以 像素 为单位绘制的,这是任意的。使用显示器的像素间距值查看我关于 drawing in a standardized measure 的回答。

这里是生成棋盘图案的简单代码。但是,棋盘的直径是以像素为单位的。

import numpy as np

h = 6
w = 8
size = 100
checkerboard = 255.0 * np.kron([[1, 0] * (w//2), [0, 1] * (w//2)] * (h//2), np.ones((size, size)))