-
Notifications
You must be signed in to change notification settings - Fork 0
/
image_frame_detector.py
34 lines (27 loc) · 1.08 KB
/
image_frame_detector.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
import cv2
import numpy as np
def draw_chessboard_corners(image_path, grid_size=(7, 7)):
# Read the image
image = cv2.imread(image_path)
if image is None:
print("Error: Unable to load image.")
return
# Convert the image to grayscale
gray = cv2.cvtColor(image, cv2.COLOR_BGR2GRAY)
# Find the chessboard corners
ret, corners = cv2.findChessboardCorners(gray, grid_size, None)
if ret:
# Refine the corner positions
corners = cv2.cornerSubPix(gray, corners, (11, 11), (-1, -1),
criteria=(cv2.TERM_CRITERIA_EPS + cv2.TERM_CRITERIA_MAX_ITER, 30, 0.1))
# Draw the corners on the image
cv2.drawChessboardCorners(image, grid_size, corners, ret)
# Display the image with corners drawn
cv2.imshow('Chessboard Corners', image)
cv2.waitKey(0)
cv2.destroyAllWindows()
else:
print("Chessboard corners not found.")
# Example usage
image_path = 'chessboard.jpg' # Replace with your image path
draw_chessboard_corners(image_path, grid_size=(7, 7))