利用Python-OpenCV及PS制作棋盘格标定板

Python代码

import cv2
import numpy as np

# 定义棋盘格的尺寸
size = 140
# 定义标定板尺寸
boardx = size * 10
boardy = size * 7

canvas = np.zeros((boardy, boardx, 1), np.uint8) # 创建画布
for i in range(0, boardx):
    for j in range(0, boardy):
        if (int(i/size) + int(j/size)) % 2 != 0: # 判定是否为奇数格
            canvas[j, i] = 255
cv2.imwrite("E:/studying/chessboard.png", canvas)

样图
在这里插入图片描述
以上述为例,导出后像素分辨率为1400*980,为得到固定尺寸(cm)的图像,我们再将其导入PhotoShop加工。
菜单栏中选择:图像——图像大小,勾选约束比例及缩放样式,再调节宽度或高度。
在这里插入图片描述
例如设置宽度为20,则实际每个棋盘格的边长大小为2cm。

  • 1
    点赞
  • 23
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
使用PythonOpenCV进行圆形标定板的相机标定,可以按照以下步骤进行: 1. 导入必要的库 ``` import numpy as np import cv2 import glob ``` 2. 定义圆形标定板的参数 ``` # 定义圆形标定板的行数和列数 rows = 7 cols = 10 # 定义每个圆的直径和间距 circle_diameter = 20 # 每个圆的直径 circle_spacing = 10 # 圆之间的间距 ``` 3. 获取标定板图像和角点 ``` # 获取标定板图像的路径 images = glob.glob('path/to/images/*.jpg') # 初始化标定板角点的空列表 obj_points = [] img_points = [] # 设置标定板上的点的坐标 objp = np.zeros((rows * cols, 3), np.float32) objp[:, :2] = np.mgrid[0:rows, 0:cols].T.reshape(-1, 2) objp = objp * (circle_diameter + circle_spacing) # 针对每个标定板图像进行处理 for fname in images: # 读取图像 img = cv2.imread(fname) # 转换为灰度图像 gray = cv2.cvtColor(img, cv2.COLOR_BGR2GRAY) # 查找圆形标定板角点 ret, corners = cv2.findCirclesGrid(gray, (cols, rows), None) # 如果找到了角点,则将其添加到角点列表中 if ret == True: obj_points.append(objp) img_points.append(corners) # 在图像上显示角点 cv2.drawChessboardCorners(img, (cols, rows), corners, ret) # 显示图像 cv2.imshow('img', img) cv2.waitKey(500) # 关闭窗口 cv2.destroyAllWindows() ``` 4. 进行相机标定 ``` # 获取相机的内部参数和外部参数 ret, mtx, dist, rvecs, tvecs = cv2.calibrateCamera(obj_points, img_points, gray.shape[::-1], None, None) # 打印结果 print("Camera matrix:\n", mtx) print("Distortion coefficients:\n", dist) ``` 以上是使用PythonOpenCV进行圆形标定板的相机标定的代码实现,具体实现还需要根据实际情况进行修改和调试。
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值