#Python in Unity app

1 messages · Page 1 of 1 (latest)

prime cove
#

hey guys, I need help, i need the following python code in my game:

from cvzone.HandTrackingModule import HandDetector
import cv2
import socket

cap = cv2.VideoCapture(0)
cap.set(3, 1280)
cap.set(4, 720)
success, img = cap.read()
h, w, _ = img.shape
detector = HandDetector(detectionCon=0.8, maxHands=2)

sock = socket.socket(socket.AF_INET, socket.SOCK_DGRAM)
serverAddressPort = ("127.0.0.1", 5052)

while True:
    # Get image frame
    success, img = cap.read()
    # Find the hand and its landmarks
    hands, img = detector.findHands(img)  # with draw
    # hands = detector.findHands(img, draw=False)  # without draw
    data = []

    if hands:
        # Hand 1
        hand = hands[0]
        lmList = hand["lmList"]  # List of 21 Landmark points
        for lm in lmList:
            data.extend([lm[0], h - lm[1], lm[2]])
            print(lm[0], h - lm[1], lm[2])

        sock.sendto(str.encode(str(data)), serverAddressPort)

    # Display
    cv2.imshow("Image", img)
    cv2.waitKey(1)

The above script recognizes the 21 standard hand joint coordinates and sends them to unity via UDP.
how do i build the app so that this code can access the phone's camera and send the data via UDP to the unity world.
We are using google cardboard to provide VR experience while replicating the hand of the user in real time in the game. How do i use this script in cohesion with the build i will create for this app ?

floral isle
#

but i'll suggest writing the same code in C# instead of running python in it