python 标定相机 检测圆点 对称或非对称

import cv2
import numpy as np

w = 4
h = 11
criteria = (cv2.TERM_CRITERIA_EPS + cv2.TERM_CRITERIA_MAX_ITER, 30, 0.001)

def find_corners(img):
    # gray = cv2.cvtColor(img, cv2.COLOR_BGR2GRAY)
    params = cv2.SimpleBlobDetector_Params()
    params.maxArea = 10000
    params.minArea = 0.01
    params.minDistBetweenBlobs = 0.01
    blobDetector = cv2.SimpleBlobDetector_create(params)
    ret, corners = cv2.findCirclesGrid(img, (w, h), cv2.CALIB_CB_ASYMMETRIC_GRID, blobDetector, None)
    if ret:
        cv2.cornerSubPix(img, corners, (w, h), (1, 1), criteria)
        # cv2.find4QuadCornerSubpix(img, corners, (w, h))
        return corners
    return None


# img = cv2.imread("circles/Snap_001.jpg",1)
img = cv2.imread("circles/calb.jpg",1)
gray_img= cv2.cvtColor(img,cv2.COLOR_BGR2GRAY)
image = cv2.resize(gray_img, (img.shape[1]*2,img.shape[0]*2))

minThreshValue = 120
_, binary = cv2.threshold(gray_img, minThreshValue, 255, cv2.THRESH_BINARY)
cv2.imshow("image", binary)


corners = find_corners(binary)
# 将角点在图像上显示
cv2.drawChessboardCorners(img, (w, h), corners, corners is not None)

cv2.imshow('findCorners', img)
cv2.waitKey()
cv2.destroyAllWindows()

标定板

python 标定相机 检测圆点 对称或非对称_第1张图片

 检测结果

python 标定相机 检测圆点 对称或非对称_第2张图片

import cv2
import numpy as np

w = 8
h = 6
criteria = (cv2.TERM_CRITERIA_EPS + cv2.TERM_CRITERIA_MAX_ITER, 10, 0.001)


def find_corners(img):
    # gray = cv2.cvtColor(img, cv2.COLOR_BGR2GRAY)
    params = cv2.SimpleBlobDetector_Params()
    params.maxArea = 10000
    params.minArea = 1
    params.minDistBetweenBlobs = 1
    blobDetector = cv2.SimpleBlobDetector_create(params)
    # ret, corners = cv2.findCirclesGrid(img, (w, h), cv2.CALIB_CB_ASYMMETRIC_GRID, blobDetector, None)
    ret, corners = cv2.findCirclesGrid(img, (w, h), cv2.CALIB_CB_SYMMETRIC_GRID, blobDetector, None)

    if ret:
        cv2.cornerSubPix(img, corners, (w, h), (1, 1), criteria)
        # cv2.find4QuadCornerSubpix(img, corners, (w, h))
        return corners
    return None

# img = cv2.imread("circles/Snap_3.jpg",1)
# # img = cv2.imread("circles/sm02.jpg",1)
# # img = cv2.imread("circles/calb.jpg", 1)
# gray_img = cv2.cvtColor(img, cv2.COLOR_BGR2GRAY)
# image = cv2.resize(gray_img, (img.shape[1] * 2, img.shape[0] * 2))
#
# minThreshValue = 120
# _, binary = cv2.threshold(gray_img, minThreshValue, 255, cv2.THRESH_BINARY)
# cv2.imshow("image", binary)
#
# corners = find_corners(binary)
# print(corners)
# # 将角点在图像上显示
# cv2.drawChessboardCorners(img, (w, h), corners, corners is not None)
#
# cv2.imshow('findCorners', img)
# cv2.waitKey()
# cv2.destroyAllWindows()


capture = cv2.VideoCapture(0)
while True:
    ret, img = capture.read()
    # frame = cv2.flip(frame,1)   #镜像操作
    cv2.imshow("video", img)
    key = cv2.waitKey(1)
    #print(key)
    if key  == ord('q'):  #判断是哪一个键按下
        break

    gray_img = cv2.cvtColor(img, cv2.COLOR_BGR2GRAY)
    image = cv2.resize(gray_img, (img.shape[1] * 2, img.shape[0] * 2))

    minThreshValue = 120
    _, binary = cv2.threshold(gray_img, minThreshValue, 255, cv2.THRESH_BINARY)
    cv2.imshow("image", binary)

    corners = find_corners(binary)
    print(corners)
    # 将角点在图像上显示
    cv2.drawChessboardCorners(img, (w, h), corners, corners is not None)

    cv2.imshow('findCorners', img)
    cv2.waitKey(1)


cv2.destroyAllWindows()

你可能感兴趣的:(机器视觉与图形图像,opencv,python)