changed box size
This commit is contained in:
parent
eb37dc8a74
commit
238f159cab
1 changed files with 8 additions and 8 deletions
|
@ -43,7 +43,7 @@ def generate_frames():
|
|||
"""Capture video frames, apply object detection, and stream as MJPEG."""
|
||||
stream_url = get_stream_url()
|
||||
if not stream_url:
|
||||
print("❌ Failed to fetch stream URL!")
|
||||
print(" Failed to fetch stream URL!")
|
||||
return
|
||||
|
||||
print("🎥 Starting FFmpeg stream...")
|
||||
|
@ -57,7 +57,7 @@ def generate_frames():
|
|||
while True:
|
||||
raw_frame = ffmpeg_process.stdout.read(frame_width * frame_height * 3) # Read raw BGR frame
|
||||
if not raw_frame:
|
||||
print("❌ No frame received!")
|
||||
print("No frame received!")
|
||||
break
|
||||
|
||||
frame = np.frombuffer(raw_frame, np.uint8).reshape((frame_height, frame_width, 3)) # Convert to NumPy array
|
||||
|
@ -67,12 +67,12 @@ def generate_frames():
|
|||
detections = results.pandas().xyxy[0] # Convert detections to Pandas DataFrame
|
||||
|
||||
if detections.empty:
|
||||
print("🚫 No objects detected in this frame.")
|
||||
print("No objects detected in this frame.")
|
||||
frame = frame.copy() # Make a writable copy
|
||||
frame[:] = 0 # Make entire frame black
|
||||
|
||||
else:
|
||||
print(f"✅ Detected {len(detections)} objects!")
|
||||
print(f"Detected {len(detections)} objects!")
|
||||
print(detections[["name", "confidence"]]) # Print detected object names and confidence
|
||||
|
||||
mask = np.zeros_like(frame) # Create black mask
|
||||
|
@ -81,9 +81,9 @@ def generate_frames():
|
|||
if row["confidence"] > CONFIDENCE_THRESHOLD and row["name"].lower() in OBJECT_LIST:
|
||||
x1, y1, x2, y2 = int(row["xmin"]), int(row["ymin"]), int(row["xmax"]), int(row["ymax"])
|
||||
|
||||
# Expand bounding box by 50px
|
||||
x1, y1 = max(0, x1 - 50), max(0, y1 - 50)
|
||||
x2, y2 = min(frame_width, x2 + 50), min(frame_height, y2 + 50)
|
||||
# Expand bounding box by 75px
|
||||
x1, y1 = max(0, x1 - 75), max(0, y1 - 75)
|
||||
x2, y2 = min(frame_width, x2 + 75), min(frame_height, y2 + 75)
|
||||
|
||||
# Copy detected object to mask
|
||||
mask[y1:y2, x1:x2] = frame[y1:y2, x1:x2]
|
||||
|
@ -106,6 +106,6 @@ def video_feed():
|
|||
return Response(generate_frames(), mimetype='multipart/x-mixed-replace; boundary=frame')
|
||||
|
||||
if __name__ == '__main__':
|
||||
print("🚀 Server running at http://localhost:5000/video")
|
||||
print("Running at http://localhost:5000/video") #port
|
||||
app.run(host='0.0.0.0', port=5000, debug=True, threaded=True)
|
||||
|
||||
|
|
Loading…
Add table
Reference in a new issue