• 制作OpenCV相机标定板棋盘格图像


    一,OpenCV 相机标定中棋盘格图像要点

           1,棋盘格的内部交点个数boardSize:水平方向(board_width, -w=4)和垂直方向(board_height, -h=5)

                个人建议:棋盘格的内部交点个数boardSize的w和h的值不要一样以区分旋转。

           2,棋盘格格子(正方形)的边长squareSize:(squareSize, -s=0.025):

    二,制作棋盘格图像程序

          1,程序语言:Python

          2,程序依赖项:numpy, opencv-python, screeninfo

          3,代码

    1. # pip install screeninfo
    2. #
    3. import numpy as np
    4. import cv2
    5. import screeninfo
    6. def gen_board(board_size, squre_size):
    7. '''
    8. @board_size: board grid num (horz, vert)
    9. @squre_size: board squre length, unit:mm
    10. '''
    11. # ppmm: pixels per mm
    12. ppmm_x = 1920 / 476 # Monitor.width / Monitor.width_mm
    13. ppmm_y = 1080 / 268 # Monitor.height / Monitor.height_mm
    14. # rect_pixels
    15. rect_width = int( ppmm_x * squre_size )
    16. rect_height = int( ppmm_y * squre_size )
    17. img_width = board_size[0] * rect_width
    18. img_height = board_size[1] * rect_height
    19. print("board: grid={0}, img={1}".format((rect_width, rect_height), (img_width, img_height)))
    20. img = np.ones((img_height, img_width, 3), dtype=np.uint8)
    21. pixel = 255
    22. for y in range(0, img_height, rect_height):
    23. colr_grid = [pixel, pixel, pixel]
    24. for x in range(0, img_width, rect_width):
    25. cv2.rectangle(img, (x, y, rect_width, rect_height), colr_grid, -1)
    26. # next col
    27. colr_grid[0] = 255 - colr_grid[0]
    28. colr_grid[1] = 255 - colr_grid[1]
    29. colr_grid[2] = 255 - colr_grid[2]
    30. # next row
    31. pixel = 255 - pixel
    32. cv2.imwrite("board.png", img)
    33. def main():
    34. for m in screeninfo.get_monitors():
    35. print(str(m))
    36. # board size: 9,7
    37. # board squre length=25mm
    38. gen_board((9, 7), 25)
    39. if __name__ == '__main__':
    40. main()

    三,示例

     

  • 相关阅读:
    对角矩阵的压缩存储
    『手撕Vue-CLI』获取下载目录
    LCR 123.图书整理
    python【模块】xml.etree.ElementTree 解析 xml
    AI研究领域有哪些?
    使用python实现短线选股
    FPGA工程师面试——RTL知识
    基于jsp+mysql+Spring+mybatis的SSM学生兼职网站
    C++圆的面积与周长 自定义函数
    2022年上半年系统集成项目管理工程师上午真题及答案解析
  • 原文地址:https://blog.csdn.net/mylaf/article/details/125521948