import cv2
import tensorflow as tf
# Load the pre-trained object detection model
model = tf.saved_model.load('ssd_mobilenet_v2/saved_model')
# Open the USB webcam
cap = cv2.VideoCapture(0)
while cap.isOpened():
ret, frame = cap.read()
if not ret:
print("Failed to capture image")
break
# Preprocess the frame for the model
input_tensor = tf.convert_to_tensor(frame)
input_tensor = input_tensor[tf.newaxis, ...]
# Perform object detection
detections = model(input_tensor)
# Display the frame
cv2.imshow('Frame', frame)
if cv2.waitKey(1) & 0xFF == ord('q'):
break
cap.release()
cv2.destroyAllWindows()
import cv2
import tensorflow as tf
# Load the pre-trained object detection model
model = tf.saved_model.load('ssd_mobilenet_v2/saved_model')
# Open the USB webcam
cap = cv2.VideoCapture(0)
while cap.isOpened():
ret, frame = cap.read()
if not ret:
print("Failed to capture image")
break
# Preprocess the frame for the model
input_tensor = tf.convert_to_tensor(frame)
input_tensor = input_tensor[tf.newaxis, ...]
# Perform object detection
detections = model(input_tensor)
# Display the frame
cv2.imshow('Frame', frame)
if cv2.waitKey(1) & 0xFF == ord('q'):
break
cap.release()
cv2.destroyAllWindows()