123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960 |
- import numpy as np
- import cv2
- # Define the size of the image
- width, height = 1920, 1080
- # Define the size of the squares
- square_size = 80
- # Calculate the total size of the checkerboard
- checkerboard_width = 11 * square_size
- checkerboard_height = 8 * square_size
- # Create an empty image with white background
- image = np.ones((height, width, 3), dtype=np.uint8) * 255
- # Calculate the offsets to center the checkerboard
- x_offset = (width - checkerboard_width) // 2
- y_offset = (height - checkerboard_height) // 2
- # Create the checkerboard pattern within the offsets
- for y in range(8):
- for x in range(11):
- if (x + y) % 2 == 0:
- top_left_y = y_offset + y * square_size
- top_left_x = x_offset + x * square_size
- bottom_right_y = y_offset + (y + 1) * square_size
- bottom_right_x = x_offset + (x + 1) * square_size
- cv2.rectangle(image, (top_left_x, top_left_y), (bottom_right_x, bottom_right_y), (0, 0, 0), -1)
- # Determine the coordinates for the circle just right of the bottom-right white square
- right_most_white_x = x_offset + 10 * square_size # Rightmost column
- right_most_white_y = y_offset + 7 * square_size # Bottommost row
- # Check if the bottom-right square is white, if not adjust the x coordinate
- if (10 + 7) % 2 == 1: # If it's a black square, move one square to the left
- right_most_white_x -= square_size
- # Draw a circle to the right of the bottom-right white square
- cv2.circle(image, (right_most_white_x + square_size + square_size // 2, right_most_white_y + square_size // 2), 20, (255, 0, 0), -1)
- # Save the image with the circle but without coordinates
- cv2.imwrite('checkerboard_with_circle_no_coords.png', image)
- # Create a copy of the image to draw the coordinates
- image_with_coords = image.copy()
- # Calculate and mark all the corners
- for y in range(9): # Include one extra row for bottom edge points
- for x in range(12): # Include one extra column for right edge points
- corner_x = x_offset + x * square_size
- corner_y = y_offset + y * square_size
- if corner_x < width and corner_y < height: # Ensure points are within image bounds
- cv2.circle(image_with_coords, (corner_x, corner_y), 5, (0, 255, 0), -1) # Green dot
- cv2.putText(image_with_coords, f"({corner_x}, {corner_y})", (corner_x + 5, corner_y - 10),
- cv2.FONT_HERSHEY_SIMPLEX, 0.5, (0, 0, 255), 2) # Red color, thickness = 2 for bold
- # Save the image with both the circle and coordinates
- cv2.imwrite('checkerboard_with_circle_and_coords.png', image_with_coords)
|