首页
学习
活动
专区
圈层
工具
发布
首页
学习
活动
专区
圈层
工具
MCP广场
社区首页 >问答首页 >摄像机校准用cv2. cv2.findCirclesGrid网格未被检测到

摄像机校准用cv2. cv2.findCirclesGrid网格未被检测到
EN

Stack Overflow用户
提问于 2021-12-22 09:02:25
回答 1查看 985关注 0票数 1

我试图校准我们的相机,但是cv2.findCirclesGrid函数有问题。

图像是非常低分辨率和模糊,这是不能改变(由于传感器的类型,我们正在使用)。我附了几张照片样本。

Sample1 Sample2 Sample3

Cv2.simpleBobDetector很好地找到了圆,因为findCriclesGrid()函数是基于这个函数的,我很惊讶它不能工作,特别是使用相同的检测器参数。我已经附上了相同的样本图像,但与检测到的圆圈。

CirclesDetected CirclesDetected CirclesDetected

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

下面是用于simpleBlobDetector()的代码:

代码语言:javascript
运行
复制
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()使用的代码:

代码语言:javascript
运行
复制
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()

对如何让这件事起作用有什么建议吗?

谢谢!

EN

Stack Overflow用户

发布于 2021-12-22 13:15:57

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

代码语言:javascript
运行
复制
ret, corners = cv2.findCirclesGrid(gray, CHECKERBOARD, None, flags=(cv2.CALIB_CB_SYMMETRIC_GRID + cv2.CALIB_CB_CLUSTERING),blobDetector=detector)
票数 1
EN
查看全部 1 条回答
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/70446523

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档