-
-
Notifications
You must be signed in to change notification settings - Fork 4.9k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Color difference, how to detect it #12694
Comments
Detecting color differences is not inherently supported through typical object classification or detection with YOLOv8 models, as these models primarily focus on object shapes and sizes. However, you can approach this challenge from a couple of angles:
Here’s a simple code snippet for reading an image and plotting the color distribution of detected objects to help start with the pre-processing approach: import cv2
from matplotlib import pyplot as plt
from ultralytics import YOLO
# Load the model
model = YOLO('path/to/model.pt')
# Load image and get detections
image = cv2.imread('path/to/image.jpg')
results = model(image)
# For each detection, calculate and plot histogram
for i, det in enumerate(results.pandas().xyxy[0].to_numpy()):
x1, y1, x2, y2 = map(int, det[:4])
cropped_image = image[y1:y2, x1:x2]
for j, color in enumerate(['b', 'g', 'r']):
hist = cv2.calcHist([cropped_image], [j], None, [256], [0, 256])
plt.plot(hist, color=color)
plt.title(f'Color Distribution for Detection {i+1}')
plt.show() This script loads an image, detects objects using a YOLO model, crops these objects out, and then plots color histograms for each detected object. Customize and expand upon this code based on specific application needs. |
Search before asking
Question
Color difference, how to detect it
Classification detection cannot detect color difference
Additional
No response
The text was updated successfully, but these errors were encountered: