Jovian
⭐️
Sign In

Grid Detection

In [1]:
import cv2
import matplotlib.pyplot as plt
%matplotlib inline
In [2]:
flat_chess = cv2.imread('../DATA/flat_chessboard.png')
In [3]:
plt.imshow(flat_chess,cmap='gray')
Out[3]:
<matplotlib.image.AxesImage at 0x2a73ad1fa58>
Notebook Image
In [4]:
found, corners = cv2.findChessboardCorners(flat_chess,(7,7))
In [5]:
if found:
    print('OpenCV was able to find the corners')
else:
    print("OpenCV did not find corners. Double check your patternSize.")
OpenCV was able to find the corners
In [6]:
corners.shape
Out[6]:
(49, 1, 2)
In [7]:

cv2.drawChessboardCorners(flat_chess, (7, 7), corners, found)
Out[7]:
array([[[158, 206, 255],
        [158, 206, 255],
        [158, 206, 255],
        ...,
        [ 71, 139, 209],
        [ 71, 139, 209],
        [ 71, 139, 209]],

       [[158, 206, 255],
        [158, 206, 255],
        [158, 206, 255],
        ...,
        [ 71, 139, 209],
        [ 71, 139, 209],
        [ 71, 139, 209]],

       [[158, 206, 255],
        [158, 206, 255],
        [158, 206, 255],
        ...,
        [ 71, 139, 209],
        [ 71, 139, 209],
        [ 71, 139, 209]],

       ...,

       [[ 71, 139, 209],
        [ 71, 139, 209],
        [ 71, 139, 209],
        ...,
        [158, 206, 255],
        [158, 206, 255],
        [158, 206, 255]],

       [[ 71, 139, 209],
        [ 71, 139, 209],
        [ 71, 139, 209],
        ...,
        [158, 206, 255],
        [158, 206, 255],
        [158, 206, 255]],

       [[ 71, 139, 209],
        [ 71, 139, 209],
        [ 71, 139, 209],
        ...,
        [158, 206, 255],
        [158, 206, 255],
        [158, 206, 255]]], dtype=uint8)
In [8]:
plt.imshow(flat_chess)
Out[8]:
<matplotlib.image.AxesImage at 0x2a73adbf2b0>
Notebook Image

Circle Based Grids

In [9]:
dots = cv2.imread('../DATA/dot_grid.png')
In [10]:
plt.imshow(dots)
Out[10]:
<matplotlib.image.AxesImage at 0x2a73ae25080>
Notebook Image
In [11]:
found, corners = cv2.findCirclesGrid(dots, (10,10), cv2.CALIB_CB_SYMMETRIC_GRID)
In [12]:
found
Out[12]:
True
In [13]:
dbg_image_circles = dots.copy()
cv2.drawChessboardCorners(dbg_image_circles, (10,10), corners, found)
Out[13]:
array([[[255, 255, 255],
        [255, 255, 255],
        [255, 255, 255],
        ...,
        [255, 255, 255],
        [255, 255, 255],
        [255, 255, 255]],

       [[255, 255, 255],
        [255, 255, 255],
        [255, 255, 255],
        ...,
        [255, 255, 255],
        [255, 255, 255],
        [255, 255, 255]],

       [[255, 255, 255],
        [255, 255, 255],
        [255, 255, 255],
        ...,
        [255, 255, 255],
        [255, 255, 255],
        [255, 255, 255]],

       ...,

       [[255, 255, 255],
        [255, 255, 255],
        [255, 255, 255],
        ...,
        [255, 255, 255],
        [255, 255, 255],
        [255, 255, 255]],

       [[255, 255, 255],
        [255, 255, 255],
        [255, 255, 255],
        ...,
        [255, 255, 255],
        [255, 255, 255],
        [255, 255, 255]],

       [[255, 255, 255],
        [255, 255, 255],
        [255, 255, 255],
        ...,
        [255, 255, 255],
        [255, 255, 255],
        [255, 255, 255]]], dtype=uint8)
In [14]:
plt.imshow(dbg_image_circles)
Out[14]:
<matplotlib.image.AxesImage at 0x2a73ae819e8>
Notebook Image

Keep this in mind for later lectures on camera calibration! We've only scratched the surface here :)

In [15]:
import jovian
In [ ]:
jovian.commit()

[jovian] Saving notebook..

Copyright by Pierian Data Inc.