Fix conflicts

This commit is contained in:
Timothyxxx
2023-12-16 21:32:43 +08:00
43 changed files with 4124 additions and 631 deletions

View File

@@ -0,0 +1,34 @@
import cv2
from matplotlib import pyplot as plt
# Load the image
image = cv2.imread('../../mm_agents/stackoverflow.png')
# Convert to grayscale
gray = cv2.cvtColor(image, cv2.COLOR_BGR2GRAY)
# Apply adaptive thresholding to get a binary image
thresh = cv2.adaptiveThreshold(
gray, 255, cv2.ADAPTIVE_THRESH_GAUSSIAN_C, cv2.THRESH_BINARY_INV, 11, 2
)
# Find contours
contours, _ = cv2.findContours(thresh, cv2.RETR_EXTERNAL, cv2.CHAIN_APPROX_SIMPLE)
# Filter out contours that are not of cell size
# This is done by assuming that cells will have a relatively standard size
# The size filter is just a placeholder, real values depend on the actual image size
min_cell_size = 500
max_cell_size = 5000
cell_contours = [cnt for cnt in contours if min_cell_size < cv2.contourArea(cnt) < max_cell_size]
# Draw contours on the image
contour_output = image.copy()
cv2.drawContours(contour_output, cell_contours, -1, (0, 255, 0), 2)
# Display the image with cell contours
plt.figure(figsize=(12,6))
plt.imshow(cv2.cvtColor(contour_output, cv2.COLOR_BGR2RGB))
plt.title('Spreadsheet with Cell Contours')
plt.axis('off')
plt.show()

View File

@@ -0,0 +1,32 @@
from PIL import Image, ImageDraw
def mark_point(image_path: str, x: int, y: int, radius: int = 5, color: str = 'red') -> str:
"""
Mark a point on an image and save the image.
"""
# Load the image
image = Image.open(image_path)
# Create a draw object
draw = ImageDraw.Draw(image)
# Draw a small circle to mark the point
draw.ellipse((x - radius, y - radius, x + radius, y + radius), fill=color, outline=color)
# Save the image with the point marked
marked_image_path = image_path[:-4] + '_marked' + image_path[-4:]
image.save(marked_image_path)
return marked_image_path
if __name__ == '__main__':
image_path = 'chrome_start.png'
x = 100
y = 200
radius = 30
color = 'red'
marked_image_path = mark_point(image_path, x, y, radius, color)
print(f"Marked image saved to {marked_image_path}")