EngAbod commited on
Commit
c5f080d
·
1 Parent(s): 6a052f0

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +26 -15
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 apply_circular_mask(frame, input_frame):
134
- height, width, _ = frame.shape
 
 
 
 
 
 
 
 
 
 
 
 
 
135
  mask = np.zeros((height, width), dtype=np.uint8)
136
- center = (width // 2, height // 2)
137
- radius = min(width, height) // 2
138
-
139
- cv2.circle(mask, center, radius, 255, -1) # Create a circular mask
140
- circular_frame = cv2.bitwise_and(frame, frame, mask=mask) # Apply the circular mask
141
-
142
- # Overlay the circular frame onto a black background with the same shape as the input frame
143
- black_frame = np.zeros_like(input_frame)
144
- x_offset = (input_frame.shape[1] - circular_frame.shape[1]) // 2
145
- y_offset = (input_frame.shape[0] - circular_frame.shape[0]) // 2
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 = apply_circular_mask(frm, frame.to_ndarray(format="bgr24"))
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