File size: 1,624 Bytes
833e5ca
78155ae
833e5ca
 
66f2e47
 
78155ae
a1cb746
 
 
 
 
 
78155ae
 
 
 
 
 
 
833e5ca
78155ae
 
 
 
833e5ca
 
 
78155ae
833e5ca
 
78155ae
833e5ca
 
78155ae
833e5ca
 
78155ae
833e5ca
 
78155ae
833e5ca
 
 
 
78155ae
833e5ca
78155ae
5a4e6c9
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
import cv2
import mediapipe as mp
import streamlit as st
from streamlit_webrtc import VideoTransformerBase, webrtc_streamer
import os
from twilio.rest import Client

account_sid = os.environ['TWILIO_ACCOUNT_SID']
auth_token = os.environ['TWILIO_AUTH_TOKEN']
client = Client(account_sid, auth_token)

token = client.tokens.create()

# Initialize mediapipe pose solution
mp_pose = mp.solutions.pose
mp_draw = mp.solutions.drawing_utils
pose = mp_pose.Pose()

# Load the background image
background_img_path = 'stage.jpg'
background_img = cv2.imread(background_img_path)

# Initialize Streamlit app
st.title("SwiftAi Avatar Dance")

class PoseTransformer(VideoTransformerBase):
    def __init__(self):
        self.pose = mp_pose.Pose()

    def transform(self, frame):
        img = frame.to_ndarray(format="bgr24")

        # Resize the frame to fit the display window
        img = cv2.resize(img, (600, 400))

        # Perform pose detection on the frame
        results = self.pose.process(img)

        # Resize the background image to match the size of the frame
        background_img_resized = cv2.resize(background_img, (600, 400))

        # Draw extracted pose on the background image with green color
        mp_draw.draw_landmarks(background_img_resized, results.pose_landmarks, mp_pose.POSE_CONNECTIONS,
                               mp_draw.DrawingSpec((0, 255, 0), 4, 4),
                               mp_draw.DrawingSpec((0, 255, 0), 6, 6))

        return background_img_resized

webrtc_streamer(rtc_configuration={"iceServers": token.ice_servers},key="example", video_transformer_factory=PoseTransformer)