I am working on a project where I need to identify and calculate the free area within a vanning slot in a warehouse. The vanning slot is marked with yellow color, and there are pallets occupying some of the space within this yellow-marked area.
I have already implemented a Python code using OpenCV to isolate the yellow color and extract the gray area covered by the yellow lines. The code is provided below:
from PIL import Image from IPython.display import display # Replace 'your_image_path.jpg' with the actual path to your image file image_path = 'C:/Users/CSR/Desktop/tracking_images/Half Vanning.jpg' # Open the image file img = Image.open(image_path) # Display the image display(img) import cv2 import numpy as np from PIL import Image from IPython.display import display # Load the image image_path = 'C:/Users/CSR/Desktop/tracking_images/Half Vanning.jpg' image = cv2.imread(image_path) # Convert the image to grayscale gray = cv2.cvtColor(image, cv2.COLOR_BGR2GRAY) # Define the lower and upper bounds for the yellow color in HSV lower_yellow = np.array([20, 100, 100], dtype=np.uint8) upper_yellow = np.array([40, 255, 255], dtype=np.uint8) # Convert the image to HSV color space hsv = cv2.cvtColor(image, cv2.COLOR_BGR2HSV) # Create a binary mask for the yellow color yellow_mask = cv2.inRange(hsv, lower_yellow, upper_yellow) # Apply a bitwise AND operation to extract the gray area covered by yellow lines gray_area = cv2.bitwise_and(gray, gray, mask=yellow_mask) # Save the result output_path = 'C:/Users/CSR/Desktop/04-08-2023/bz.jpg' # Change this to the desired output path cv2.imwrite(output_path, gray_area) print("Result image saved to:", output_path) # Open the image file img = Image.open(output_path) # Display the image display(img)
However, I am struggling to determine the free area within this yellow-marked vanning slot – the area not occupied by pallets. I would like to calculate and visualize this free space. Could you please provide guidance on how to achieve this? Specifically, how can I identify and calculate the unoccupied (free) area within the yellow-marked vanning slot?