【问题标题】:Camera calibration with cv2.findCirclesGrid grid not detected未检测到 cv2.findCirclesGrid 网格的相机校准
【发布时间】:2022-01-23 12:41:15
【问题描述】:

我正在尝试校准我们的一台相机,但 cv2.findCirclesGrid 函数出现问题。

图像分辨率非常低且模糊,并且无法更改(由于我们使用的传感器类型)。我附上了一些示例图片。

Sample1Sample2Sample3

cv2.simpleBlobDetector 可以很好地找到圆圈,并且由于 findCriclesGrid() 函数基于我很惊讶它不起作用,尤其是使用相同的检测器参数。我附上了相同的示例图片,但带有检测到的圆圈。

Sample1_CirclesDetectedSample2_CirclesDetectedSample3_CirclesDetected

我在 simpleBlobDetector 中注意到的一件事是,无论我使用什么参数,关键点的响应都保持为 0.0。我想知道 findCirclesGrid() 是否根据他们的响应对关键点进行排序或验证?

这里是用于 simpleBlobDetector() 的代码:

import math
import cv2
import numpy as np
import logging

image = 'PathToImage'

log = logging.getLogger(__name__)

im = cv2.imread(image, cv2.IMREAD_GRAYSCALE)

params = cv2.SimpleBlobDetector_Params()
params.minThreshold = 1
params.maxThreshold = 255

params.filterByArea = True
params.minArea = 50
params.maxArea = 300

params.filterByInertia = True
params.minInertiaRatio = 0.5

params.filterByCircularity = True
params.minCircularity = .8

params.minDistBetweenBlobs = 7


detector = cv2.SimpleBlobDetector_create(params)

# Keypoint class: pt->coordinates, size->diameter, angle->angle of the blob, response->response showing the confidence of the proposition, octave, class_id
keypoints = detector.detect(im)

# Generate image
im_with_keypoints = cv2.drawKeypoints(im, keypoints, np.array([]), (0, 0, 255),
                                      cv2.DRAW_MATCHES_FLAGS_DRAW_RICH_KEYPOINTS)
imgResized = cv2.resize(im_with_keypoints, (665, 500))

# find circle centers and size
circle_number = 12
point_centres = []
point_locations = []

"""gathers an array of the centrepoints of circles detected"""
for keyPoint in keypoints:
    x = keyPoint.pt[0]
    y = keyPoint.pt[1]
    s = keyPoint.size
    log.info(f'{keyPoint.response=}')

    pt = [x, y, np.sqrt(s / math.pi)]
    pts = [[x, y]]
    point_centres.append(pt)
    point_locations.append(pts)

这是我用于 findCirclesGrid() 的代码:

import cv2
import numpy as np
import glob
from find_circles import circle_centres
import logging

def main():
    log = logging.getLogger(__name__)
    logging.basicConfig(level = logging.INFO)

    CHECKERBOARD = (3, 4)
    SquareSize = 72

    # Creating vector to store vectors of 3D points for each checkerboard image
    objpoints = []
    # Creating vector to store vectors of 2D points for each checkerboard image
    imgpoints = []


    objp = np.zeros((1, CHECKERBOARD[0] * CHECKERBOARD[1], 3), np.float32)
    objp[0, :, :2] = np.mgrid[0:CHECKERBOARD[0], 0:CHECKERBOARD[1]].T.reshape(-1, 2)
    objp = objp * SquareSize

    log.info(f'objPts\n {objp}')

    fnames = 'PathToImages'
    images = glob.glob(fnames)

    params = cv2.SimpleBlobDetector_Params()
    params.minThreshold = 1
    params.maxThreshold = 255

    # params.filterByConvexity = True
    # params.minConvexity = 0.4

    params.filterByArea = True
    params.minArea = 50
    params.maxArea = 300

    params.filterByInertia = True
    params.minInertiaRatio = 0.5

    params.filterByCircularity = True
    params.minCircularity = 0.8

    params.minDistBetweenBlobs = 7

    detector = cv2.SimpleBlobDetector_create(params)

    for fname in images:
        ret, centres = circle_centres(fname)

        img = cv2.imread(fname)
        gray = cv2.cvtColor(img, cv2.COLOR_BGR2GRAY)

        ret, corners = cv2.findCirclesGrid(gray, CHECKERBOARD, None, flags=cv2.CALIB_CB_SYMMETRIC_GRID,blobDetector=detector)

        log.info(f'ret {ret}')

        if ret is True:
            imgCorners = cv2.drawChessboardCorners(img, CHECKERBOARD, corners, ret)
            resized = cv2.resize(imgCorners, (665, 500))
            cv2.imshow('Circular pattern', resized)
            cv2.waitKey()

if __name__ == "__main__":
    main()

关于如何让它工作的任何建议?

谢谢!

【问题讨论】:

  • 您可以将检测器馈送到 circleGridFinder:stackoverflow.com/questions/39703407/…
  • 这不是我已经用这条线做的吗? ret,corners = cv2.findCirclesGrid(灰色, CHECKERBOARD, None, flags=cv2.CALIB_CB_SYMMETRIC_GRID,blobDetector=detector)
  • 将您的 3x4 更改为 4x3 图案尺寸:stackoverflow.com/a/37604259/2393191
  • 事先也尝试过,但没有帮助,很遗憾。
  • 成功了,谢谢!我将添加一个链接回您的评论的答案(我似乎无法接受您的评论作为答案)。感谢您的帮助!

标签: python opencv camera-calibration


【解决方案1】:

因此,按照 Micka 的评论,将 cv2.CALIB_CB_CLUSTERING 添加到标志中就可以了!

ret, corners = cv2.findCirclesGrid(gray, CHECKERBOARD, None, flags=(cv2.CALIB_CB_SYMMETRIC_GRID + cv2.CALIB_CB_CLUSTERING),blobDetector=detector)

【讨论】:

    猜你喜欢
    • 2018-02-24
    • 2015-10-26
    • 2011-04-05
    • 1970-01-01
    • 1970-01-01
    • 2015-09-24
    • 2013-01-28
    • 2014-10-23
    • 2013-11-02
    相关资源
    最近更新 更多