Spaces:
Runtime error
Runtime error
Update app.py
Browse files
app.py
CHANGED
|
@@ -130,21 +130,32 @@ def spatial_pyramid(image, num_bins):
|
|
| 130 |
# Concatenate histograms from all channels
|
| 131 |
feature_vector = np.concatenate(histograms)
|
| 132 |
return feature_vector
|
| 133 |
-
def
|
| 134 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 135 |
mask = np.zeros((height, width), dtype=np.uint8)
|
| 136 |
-
|
| 137 |
-
|
| 138 |
-
|
| 139 |
-
cv2.
|
| 140 |
-
|
| 141 |
-
|
| 142 |
-
|
| 143 |
-
|
| 144 |
-
|
| 145 |
-
|
| 146 |
-
black_frame[y_offset:y_offset + circular_frame.shape[0], x_offset:x_offset + circular_frame.shape[1]] = circular_frame
|
| 147 |
-
return black_frame
|
| 148 |
class VideoProcessor:
|
| 149 |
num_bins = 256
|
| 150 |
video_stopped = False
|
|
@@ -323,7 +334,7 @@ class VideoProcessor:
|
|
| 323 |
cv2.putText(frm, text, (20, 50), cv2.FONT_HERSHEY_SIMPLEX, 2, (0, 255, 0))
|
| 324 |
else:
|
| 325 |
cv2.putText(frm, text, (20, 50), cv2.FONT_HERSHEY_SIMPLEX, 2, (0, 0, 255))
|
| 326 |
-
frm =
|
| 327 |
return av.VideoFrame.from_ndarray(frm, format='bgr24')
|
| 328 |
# Inside your Streamlit app
|
| 329 |
|
|
|
|
| 130 |
# Concatenate histograms from all channels
|
| 131 |
feature_vector = np.concatenate(histograms)
|
| 132 |
return feature_vector
|
| 133 |
+
def add_circle_image_to_black_image(image):
|
| 134 |
+
# Convert the image to RGB format if it is not already
|
| 135 |
+
if len(image.shape) == 2:
|
| 136 |
+
image = cv2.cvtColor(image, cv2.COLOR_GRAY2BGR)
|
| 137 |
+
|
| 138 |
+
# Get the height and width of the input image
|
| 139 |
+
height, width, _ = image.shape
|
| 140 |
+
|
| 141 |
+
# Create a black image with the same height and width as the input image
|
| 142 |
+
black_image = np.zeros((height, width, 3), dtype=np.uint8)
|
| 143 |
+
|
| 144 |
+
# Calculate the radius of the circle
|
| 145 |
+
radius = int(min(height, width) / 2)
|
| 146 |
+
|
| 147 |
+
# Create a mask for the circle
|
| 148 |
mask = np.zeros((height, width), dtype=np.uint8)
|
| 149 |
+
cv2.circle(mask, (width // 2, height // 2), radius, (255, 255, 255), -1)
|
| 150 |
+
|
| 151 |
+
# Bitwise AND the input image with the mask to create a circular image
|
| 152 |
+
circular_image = cv2.bitwise_and(image, image, mask=mask)
|
| 153 |
+
|
| 154 |
+
# Add the circular image to the black image at the center
|
| 155 |
+
black_image[height // 2 - radius: height // 2 + radius, width // 2 - radius: width // 2 + radius] = circular_image
|
| 156 |
+
|
| 157 |
+
# Return the black image with the circular image in the center
|
| 158 |
+
return black_image
|
|
|
|
|
|
|
| 159 |
class VideoProcessor:
|
| 160 |
num_bins = 256
|
| 161 |
video_stopped = False
|
|
|
|
| 334 |
cv2.putText(frm, text, (20, 50), cv2.FONT_HERSHEY_SIMPLEX, 2, (0, 255, 0))
|
| 335 |
else:
|
| 336 |
cv2.putText(frm, text, (20, 50), cv2.FONT_HERSHEY_SIMPLEX, 2, (0, 0, 255))
|
| 337 |
+
frm = add_circle_image_to_black_image(frm)
|
| 338 |
return av.VideoFrame.from_ndarray(frm, format='bgr24')
|
| 339 |
# Inside your Streamlit app
|
| 340 |
|