Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
|
@@ -666,28 +666,25 @@ 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)
|
| 669 |
-
|
| 670 |
-
# Преобразуем в HSV
|
| 671 |
hsv = cv2.cvtColor(img, cv2.COLOR_BGR2HSV)
|
| 672 |
|
| 673 |
-
#
|
| 674 |
-
|
| 675 |
-
|
| 676 |
-
|
| 677 |
-
|
|
|
|
|
|
|
| 678 |
|
| 679 |
total_pixels = img.shape[0] * img.shape[1]
|
|
|
|
| 680 |
|
| 681 |
-
|
| 682 |
-
|
| 683 |
-
|
| 684 |
-
|
| 685 |
-
return {
|
| 686 |
-
"green": green_percent,
|
| 687 |
-
"yellow": yellow_percent,
|
| 688 |
-
"brown": brown_percent
|
| 689 |
-
}
|
| 690 |
|
|
|
|
| 691 |
|
| 692 |
|
| 693 |
@app.route('/last_image', methods=['GET'])
|
|
|
|
| 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)
|
|
|
|
|
|
|
| 669 |
hsv = cv2.cvtColor(img, cv2.COLOR_BGR2HSV)
|
| 670 |
|
| 671 |
+
# Обновлённые диапазоны HSV (Hue, Saturation, Value)
|
| 672 |
+
color_ranges = {
|
| 673 |
+
"green": ((36, 40, 40), (86, 255, 255)), # Зелёный
|
| 674 |
+
"yellow": ((20, 100, 100), (30, 255, 255)), # Жёлтый
|
| 675 |
+
"brown": ((10, 50, 20), (20, 150, 150)), # Коричневый
|
| 676 |
+
"orange": ((5, 100, 100), (15, 255, 255)) # Оранжевый
|
| 677 |
+
}
|
| 678 |
|
| 679 |
total_pixels = img.shape[0] * img.shape[1]
|
| 680 |
+
result = {}
|
| 681 |
|
| 682 |
+
for color, (lower, upper) in color_ranges.items():
|
| 683 |
+
mask = cv2.inRange(hsv, np.array(lower), np.array(upper))
|
| 684 |
+
percent = int((cv2.countNonZero(mask) / total_pixels) * 100)
|
| 685 |
+
result[color] = percent
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 686 |
|
| 687 |
+
return result
|
| 688 |
|
| 689 |
|
| 690 |
@app.route('/last_image', methods=['GET'])
|