krishnamishra8848 commited on
Commit
40f8621
·
verified ·
1 Parent(s): 63bf93b

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +8 -3
app.py CHANGED
@@ -39,15 +39,17 @@ def detect_and_crop_license_plate(image):
39
  img_bgr = cv2.cvtColor(np.array(image), cv2.COLOR_RGB2BGR)
40
  results = full_plate_model(img_bgr)
41
 
 
42
  cropped_images = []
43
  for result in results:
44
  if hasattr(result, 'boxes') and result.boxes is not None:
45
  for box in result.boxes.xyxy:
46
  x1, y1, x2, y2 = map(int, box)
 
47
  cropped_image = img_bgr[y1:y2, x1:x2]
48
  cropped_images.append(cropped_image)
49
 
50
- return cropped_images, img_bgr
51
 
52
  # Function to detect characters
53
  def detect_characters(image):
@@ -69,7 +71,10 @@ if uploaded_file is not None:
69
 
70
  # Detect license plates and characters
71
  with st.spinner("Processing image..."):
72
- cropped_plates, original_image = detect_and_crop_license_plate(image)
 
 
 
73
 
74
  if cropped_plates:
75
  st.write(f"Detected {len(cropped_plates)} license plate(s). Showing results:")
@@ -80,7 +85,7 @@ if uploaded_file is not None:
80
  st.image(cv2.cvtColor(annotated_plate, cv2.COLOR_BGR2RGB), caption=f"License Plate {idx} with Characters", use_container_width=True)
81
  else:
82
  st.write("No license plates detected. Running character detection on the full image.")
83
- annotated_image = detect_characters(original_image.copy())
84
  st.image(cv2.cvtColor(annotated_image, cv2.COLOR_BGR2RGB), caption="Full Image with Characters", use_container_width=True)
85
 
86
  st.success("Processing complete!")
 
39
  img_bgr = cv2.cvtColor(np.array(image), cv2.COLOR_RGB2BGR)
40
  results = full_plate_model(img_bgr)
41
 
42
+ detected_image = img_bgr.copy()
43
  cropped_images = []
44
  for result in results:
45
  if hasattr(result, 'boxes') and result.boxes is not None:
46
  for box in result.boxes.xyxy:
47
  x1, y1, x2, y2 = map(int, box)
48
+ cv2.rectangle(detected_image, (x1, y1), (x2, y2), (255, 0, 0), 2) # Draw bounding box
49
  cropped_image = img_bgr[y1:y2, x1:x2]
50
  cropped_images.append(cropped_image)
51
 
52
+ return cropped_images, detected_image
53
 
54
  # Function to detect characters
55
  def detect_characters(image):
 
71
 
72
  # Detect license plates and characters
73
  with st.spinner("Processing image..."):
74
+ cropped_plates, detected_image = detect_and_crop_license_plate(image)
75
+
76
+ # Show the image with detected license plates
77
+ st.image(cv2.cvtColor(detected_image, cv2.COLOR_BGR2RGB), caption="Detected License Plates", use_container_width=True)
78
 
79
  if cropped_plates:
80
  st.write(f"Detected {len(cropped_plates)} license plate(s). Showing results:")
 
85
  st.image(cv2.cvtColor(annotated_plate, cv2.COLOR_BGR2RGB), caption=f"License Plate {idx} with Characters", use_container_width=True)
86
  else:
87
  st.write("No license plates detected. Running character detection on the full image.")
88
+ annotated_image = detect_characters(detected_image.copy())
89
  st.image(cv2.cvtColor(annotated_image, cv2.COLOR_BGR2RGB), caption="Full Image with Characters", use_container_width=True)
90
 
91
  st.success("Processing complete!")