-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcamera_feed.py
47 lines (34 loc) · 1.43 KB
/
camera_feed.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
import cv2
import numpy as np
import pose_detection
import augment_shirt
import pose_model_class
global pose
def take_feed(frame_placeholder, stop_button_pressed):
# Create a VideoCapture object to access the default camera (usually camera index 0)
cap = cv2.VideoCapture(0)
cv2.namedWindow("Camera Feed", cv2.WINDOW_NORMAL)
while cap.isOpened() and not stop_button_pressed:
# Read a frame from the camera
ret, frame = cap.read()
if not ret:
break
# Process for pose detection on each frame returns image and keypoints after pose detection
li = pose_detection.process(frame)
frame = li[0]
keypoints = np.array(li[1])
if(keypoints.size != 0):
pose = pose_model_class.Pose(keypoints)
# cv2.IMREAD_UNCHANGED will be used to also take the alpha channel in the image
t_shirt = cv2.imread("T-shirt.jpg",cv2.IMREAD_UNCHANGED)
# Augment the Shirt by super imposing the images
frame = augment_shirt.augment(frame, pose, t_shirt)
# Display the captured frame
# cv2.imshow("Camera Feed", frame)
frame_placeholder.image(frame,channels="BGR")
# Break the loop when 'q' is pressed
if cv2.waitKey(1) & 0xFF == ord("q") or stop_button_pressed:
break
# Release the VideoCapture and close the OpenCV window
cap.release()
cv2.destroyAllWindows()