Ashegh-Sad-Warrior commited on
Commit
f846ba5
·
verified ·
1 Parent(s): 42fe02f

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +6 -5
app.py CHANGED
@@ -11,7 +11,7 @@ import tempfile
11
  import os
12
 
13
  # بارگذاری مدل آموزش‌دیده شما
14
- model = YOLO('weights/best.pt') # یا '/content/best.pt' بر اساس مدل مورد نظر شما
15
 
16
  # تعریف نام کلاس‌ها به انگلیسی و فارسی
17
  class_names = {
@@ -44,12 +44,13 @@ colors = {
44
  7: (255, 165, 0), # نارنجی
45
  8: (0, 128, 0), # سبز تیره
46
  9: (128, 128, 0), # زیتونی
47
- 10: (128, 0, 0), # سرخ کلید
48
  11: (0, 128, 128), # سبز نفتی
49
  12: (0, 0, 128), # نیوی
50
  13: (75, 0, 130), # ایندیگو
51
  14: (199, 21, 133) # رز متوسط
52
  }
 
53
  # تابع برای تشخیص اشیاء در تصاویر
54
  def detect_and_draw_image(input_image):
55
  try:
@@ -94,8 +95,8 @@ def detect_and_draw_image(input_image):
94
  rect = ((x_center, y_center), (width, height), rotation * 180.0 / np.pi) # تبدیل رادیان به درجه
95
  box_points = cv2.boxPoints(rect)
96
  box_points = np.int0(box_points)
97
- color = colors.get(class_id, (0, 255, 0))
98
- cv2.drawContours(image_cv, [box_points], 0, color, 2)
99
  print(f"Drawn OBB for class_id {class_id} with confidence {confidence}.")
100
 
101
  # رسم برچسب
@@ -173,7 +174,7 @@ def detect_and_draw_video(video_path):
173
  box_points = cv2.boxPoints(rect)
174
  box_points = np.int0(box_points)
175
  color = colors.get(class_id, (0, 255, 0))
176
- cv2.drawContours(frame, [box_points], 0, color, 2)
177
  print(f"Drawn OBB for class_id {class_id} with confidence {confidence} in frame {frame_count}.")
178
 
179
  # رسم برچسب
 
11
  import os
12
 
13
  # بارگذاری مدل آموزش‌دیده شما
14
+ model = YOLO('/content/best.pt') # مسیر مدل شما
15
 
16
  # تعریف نام کلاس‌ها به انگلیسی و فارسی
17
  class_names = {
 
44
  7: (255, 165, 0), # نارنجی
45
  8: (0, 128, 0), # سبز تیره
46
  9: (128, 128, 0), # زیتونی
47
+ 10: (0, 255, 0), # تغییر به سبز روشن برای class_id=10
48
  11: (0, 128, 128), # سبز نفتی
49
  12: (0, 0, 128), # نیوی
50
  13: (75, 0, 130), # ایندیگو
51
  14: (199, 21, 133) # رز متوسط
52
  }
53
+
54
  # تابع برای تشخیص اشیاء در تصاویر
55
  def detect_and_draw_image(input_image):
56
  try:
 
95
  rect = ((x_center, y_center), (width, height), rotation * 180.0 / np.pi) # تبدیل رادیان به درجه
96
  box_points = cv2.boxPoints(rect)
97
  box_points = np.int0(box_points)
98
+ color = colors.get(class_id, (0, 255, 0)) # استفاده از رنگ مشخص برای هر کلاس
99
+ cv2.drawContours(image_cv, [box_points], 0, color, 3) # افزایش ضخامت جعبه
100
  print(f"Drawn OBB for class_id {class_id} with confidence {confidence}.")
101
 
102
  # رسم برچسب
 
174
  box_points = cv2.boxPoints(rect)
175
  box_points = np.int0(box_points)
176
  color = colors.get(class_id, (0, 255, 0))
177
+ cv2.drawContours(frame, [box_points], 0, color, 3) # افزایش ضخامت جعبه
178
  print(f"Drawn OBB for class_id {class_id} with confidence {confidence} in frame {frame_count}.")
179
 
180
  # رسم برچسب