Spaces:
Sleeping
Sleeping
| import cv2 | |
| # Load your image | |
| image = cv2.imread('/media/gjin/New Volume/BACKTEST_DATA/black_edition_rolling_window_50_candlestick_10/images_detection/4h/ADA_USDT_output_result_2024-10-09_16-00-00.jpg') | |
| original_image = image.copy() # Keep a copy of the original image to reset after every frame | |
| # Get the dimensions of the image | |
| height, width, _ = image.shape | |
| # Define the step size for the grid | |
| step_x = 50 # Step size for x-axis | |
| step_y = 50 # Step size for y-axis | |
| # Draw grid lines | |
| def draw_grid(img): | |
| for x in range(0, width, step_x): | |
| cv2.line(img, (x, 0), (x, height), (0, 255, 0), 1) # Draw green vertical lines | |
| cv2.putText(img, str(x), (x + 5, 20), cv2.FONT_HERSHEY_SIMPLEX, 0.5, (0, 255, 0), 1) | |
| for y in range(0, height, step_y): | |
| cv2.line(img, (0, y), (width, y), (0, 255, 0), 1) # Draw green horizontal lines | |
| cv2.putText(img, str(y), (5, y + 15), cv2.FONT_HERSHEY_SIMPLEX, 0.5, (0, 255, 0), 1) | |
| # Mouse callback function to display cursor details | |
| def show_mouse_position(event, x, y, flags, param): | |
| global image | |
| if event == cv2.EVENT_MOUSEMOVE: # Track mouse movement | |
| image = original_image.copy() # Reset to original image every frame | |
| draw_grid(image) | |
| # Get the BGR color of the pixel at the cursor position | |
| b, g, r = image[y, x] | |
| # Display the x, y coordinates and BGR color values on the image | |
| info_text = f"X: {x}, Y: {y}, Color: B: {b}, G: {g}, R: {r}" | |
| cv2.putText(image, info_text, (10, height - 10), cv2.FONT_HERSHEY_SIMPLEX, 0.5, (0, 0, 0), 1) # Text in black | |
| # Create a window | |
| cv2.namedWindow('Image with Grid and Coordinates', cv2.WND_PROP_FULLSCREEN) | |
| cv2.setWindowProperty('Image with Grid and Coordinates', cv2.WND_PROP_FULLSCREEN, cv2.WINDOW_FULLSCREEN) | |
| # Set the mouse callback function to track the cursor movement | |
| cv2.setMouseCallback('Image with Grid and Coordinates', show_mouse_position) | |
| # Draw initial grid | |
| draw_grid(image) | |
| # Display the image with grid and cursor details | |
| while True: | |
| cv2.imshow('Image with Grid and Coordinates', image) | |
| if cv2.waitKey(20) & 0xFF == 27: # Press 'Esc' to exit | |
| break | |
| cv2.destroyAllWindows() |