Senasu commited on
Commit
ef5521f
·
verified ·
1 Parent(s): 3fbacfb

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +30 -5
app.py CHANGED
@@ -1,12 +1,10 @@
1
- # app.py
2
-
3
- import cv2
4
  import numpy as np
5
  import cvlib as cv
6
  from cvlib.object_detection import draw_bbox
7
  import streamlit as st
8
  from PIL import Image
9
  from collections import Counter
 
10
 
11
  # Streamlit app title
12
  st.set_page_config(page_title="Object Detection App", page_icon="🖼️", layout="centered")
@@ -23,12 +21,39 @@ The application will display the image with bounding boxes around the objects.
23
  st.markdown("### Step 1: Upload an Image for Object Detection")
24
  uploaded_file = st.file_uploader("Choose an image...", type=["png", "jpg", "jpeg"])
25
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
26
  if uploaded_file is not None:
27
  # Convert image file to OpenCV format
28
  image = np.array(Image.open(uploaded_file))
29
 
30
- # Perform object detection
31
- box, label, count = cv.detect_common_objects(image)
32
 
33
  # Draw bounding boxes on the image
34
  output_image = draw_bbox(image, box, label, count)
 
 
 
 
1
  import numpy as np
2
  import cvlib as cv
3
  from cvlib.object_detection import draw_bbox
4
  import streamlit as st
5
  from PIL import Image
6
  from collections import Counter
7
+ import os
8
 
9
  # Streamlit app title
10
  st.set_page_config(page_title="Object Detection App", page_icon="🖼️", layout="centered")
 
21
  st.markdown("### Step 1: Upload an Image for Object Detection")
22
  uploaded_file = st.file_uploader("Choose an image...", type=["png", "jpg", "jpeg"])
23
 
24
+ # Function to disable progress bar in cvlib download function
25
+ def download_file_without_progress(url, file_name, dest_dir):
26
+ """
27
+ Downloads the file without displaying progress bar.
28
+ """
29
+ file_path = os.path.join(dest_dir, file_name)
30
+ if not os.path.exists(file_path):
31
+ # Perform the download without progress bar
32
+ print(f"Downloading {file_name}...")
33
+ os.system(f"wget {url} -O {file_path}")
34
+ return file_path
35
+
36
+ # Modify the detect_common_objects function to accept a skip_progress argument
37
+ def detect_common_objects_skip_progress(image, model='yolov3', skip_progress=False):
38
+ # If skip_progress is True, we modify the behavior of the model download process
39
+ if skip_progress:
40
+ # Manually set the file paths for the config and weights files if needed
41
+ model_config = 'path_to_config.cfg' # Provide the correct path to config file
42
+ model_weights = 'path_to_weights.weights' # Provide the correct path to weights file
43
+ else:
44
+ model_config = cv.download_file(url="https://github.com/opencv/opencv_contrib/blob/master/modules/dnn/data/yolov3.cfg", file_name="yolov3.cfg", dest_dir=".")
45
+ model_weights = cv.download_file(url="https://github.com/opencv/opencv_contrib/blob/master/modules/dnn/data/yolov3.weights", file_name="yolov3.weights", dest_dir=".")
46
+
47
+ # Run detection
48
+ box, label, count = cv.detect_common_objects(image, model=model)
49
+ return box, label, count
50
+
51
  if uploaded_file is not None:
52
  # Convert image file to OpenCV format
53
  image = np.array(Image.open(uploaded_file))
54
 
55
+ # Perform object detection with progress bar disabled
56
+ box, label, count = detect_common_objects_skip_progress(image, skip_progress=True)
57
 
58
  # Draw bounding boxes on the image
59
  output_image = draw_bbox(image, box, label, count)