Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
@@ -662,7 +662,7 @@ latest_image = {
|
|
662 |
"color_percentages": {"green": 0, "yellow": 0, "brown": 0}
|
663 |
}
|
664 |
|
665 |
-
def
|
666 |
image_bytes.seek(0)
|
667 |
file_bytes = np.asarray(bytearray(image_bytes.read()), dtype=np.uint8)
|
668 |
img = cv2.imdecode(file_bytes, cv2.IMREAD_COLOR)
|
@@ -670,16 +670,21 @@ def analyze_fixed_color(image_bytes, target_color_hsv):
|
|
670 |
# Преобразуем в HSV
|
671 |
hsv = cv2.cvtColor(img, cv2.COLOR_BGR2HSV)
|
672 |
|
673 |
-
#
|
674 |
-
|
|
|
|
|
675 |
|
676 |
total_pixels = img.shape[0] * img.shape[1]
|
677 |
|
678 |
-
|
679 |
-
|
|
|
680 |
|
681 |
return {
|
682 |
-
"
|
|
|
|
|
683 |
}
|
684 |
|
685 |
|
|
|
662 |
"color_percentages": {"green": 0, "yellow": 0, "brown": 0}
|
663 |
}
|
664 |
|
665 |
+
def analyze_colors(image_bytes):
|
666 |
image_bytes.seek(0)
|
667 |
file_bytes = np.asarray(bytearray(image_bytes.read()), dtype=np.uint8)
|
668 |
img = cv2.imdecode(file_bytes, cv2.IMREAD_COLOR)
|
|
|
670 |
# Преобразуем в HSV
|
671 |
hsv = cv2.cvtColor(img, cv2.COLOR_BGR2HSV)
|
672 |
|
673 |
+
# Диапазоны цветов в HSV
|
674 |
+
green_mask = cv2.inRange(hsv, (36, 40, 40), (86, 255, 255))
|
675 |
+
yellow_mask = cv2.inRange(hsv, (50, 30, 180), (60, 100, 255))
|
676 |
+
brown_mask = cv2.inRange(hsv, (8, 50, 30), (18, 255, 130))
|
677 |
|
678 |
total_pixels = img.shape[0] * img.shape[1]
|
679 |
|
680 |
+
green_percent = int((cv2.countNonZero(green_mask) / total_pixels) * 100)
|
681 |
+
yellow_percent = int((cv2.countNonZero(yellow_mask) / total_pixels) * 100)
|
682 |
+
brown_percent = int((cv2.countNonZero(brown_mask) / total_pixels) * 100)
|
683 |
|
684 |
return {
|
685 |
+
"green": green_percent,
|
686 |
+
"yellow": yellow_percent,
|
687 |
+
"brown": brown_percent
|
688 |
}
|
689 |
|
690 |
|