我试图校准我们的相机,但是cv2.findCirclesGrid函数有问题。
图像是非常低分辨率和模糊,这是不能改变(由于传感器的类型,我们正在使用)。我附了几张照片样本。
Cv2.simpleBobDetector很好地找到了圆,因为findCriclesGrid()函数是基于这个函数的,我很惊讶它不能工作,特别是使用相同的检测器参数。我已经附上了相同的样本图像,但与检测到的圆圈。
CirclesDetected CirclesDetected 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()
对如何让这件事起作用有什么建议吗?
谢谢!
发布于 2021-12-22 13:15:57
因此,按照Micka的评论,在标志中添加cv2.CALIB_CB_CLUSTERING就可以了!
ret, corners = cv2.findCirclesGrid(gray, CHECKERBOARD, None, flags=(cv2.CALIB_CB_SYMMETRIC_GRID + cv2.CALIB_CB_CLUSTERING),blobDetector=detector)
https://stackoverflow.com/questions/70446523
复制相似问题