-
Notifications
You must be signed in to change notification settings - Fork 3
/
app.py
58 lines (49 loc) · 2.02 KB
/
app.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
# pip install opencv-python
import cv2
from ultralytics import YOLO
model = YOLO('model.pt')
print(model.names)
webcamera = cv2.VideoCapture(0)
# webcamera.set(cv2.CAP_PROP_FRAME_WIDTH, 1920)
# webcamera.set(cv2.CAP_PROP_FRAME_HEIGHT, 1080)
while True:
success, frame = webcamera.read()
results = model.track(frame, classes=0, conf=0.8, imgsz=480)
cv2.putText(frame, f"Total: {len(results[0].boxes)}", (50, 50), cv2.FONT_HERSHEY_SIMPLEX, 1, (0, 0, 255), 2, cv2.LINE_AA)
cv2.imshow("Live Camera", results[0].plot())
if cv2.waitKey(1) == ord('q'):
break
webcamera.release()
cv2.destroyAllWindows()
# For Realsense camera
# def initialize_realsense():
# import pyrealsense2 as rs
# pipeline = rs.pipeline()
# camera_aconfig = rs.config()
# camera_aconfig.enable_stream(rs.stream.depth, *config.DEPTH_CAMERA_RESOLUTION, rs.format.z16, config.DEPTH_CAMERA_FPS)
# camera_aconfig.enable_stream(rs.stream.color, *config.COLOR_CAMERA_RESOLUTION, rs.format.bgr8, config.COLOR_CAMERA_FPS)
# pipeline.start(camera_aconfig)
# return pipeline
# try:
# # Try to initialize RealSense Camera
# camera = initialize_realsense()
# get_frame = get_frame_realsense
# except Exception as e:
# print("RealSense camera not found, using default webcam.")
# camera = initialize_webcam()
# get_frame = get_frame_webcam
# Function to get frames from RealSense
# def get_frame_realsense(pipeline):
# import pyrealsense2 as rs
# frames = pipeline.wait_for_frames()
# depth_frame = frames.get_depth_frame()
# color_frame = frames.get_color_frame()
# if not depth_frame or not color_frame:
# return None, None
# depth_image = np.asanyarray(depth_frame.get_data())
# color_image = np.asanyarray(color_frame.get_data())
# return depth_image, color_image
# # Function to get frame from webcam
# def get_frame_webcam(cap):
# ret, frame = cap.read()
# return None, frame if ret else None