-
Notifications
You must be signed in to change notification settings - Fork 1
/
KamenProj.py
68 lines (58 loc) · 2.02 KB
/
KamenProj.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
59
60
61
62
63
64
65
66
67
68
import sys
import NicCode as nic
sys.path.append('../StanfordQuadruped')
import cv2 as cv
from cv2 import aruco
import numpy as np
import time
import os
import sys
"""
from src.IMU import IMU
from src.Controller import Controller
from src.JoystickInterface import JoystickInterface
from src.State import BehaviorState, State
from MangDang.mini_pupper.HardwareInterface import HardwareInterface
from MangDang.mini_pupper.Config import Configuration
from pupper.Kinematics import four_legs_inverse_kinematics, leg_explicit_inverse_kinematics
from MangDang.mini_pupper.display import Display
from src.MovementScheme import MovementScheme
from src.danceSample import MovementLib
from UDPComms import Publisher
"""
###CAMERA CODE (from pupper_detection.py)
marker_dict = aruco.Dictionary_get(aruco.DICT_4X4_50)
param_markers = aruco.DetectorParameters_create()
cap = cv.VideoCapture(0, cv.CAP_V4L2) #added (... , cv.CAP_V4L2) was giving an error in GStramer pipeline
while True:
ret, frame = cap.read()
if not ret:
break
gray_frame = cv.cvtColor(frame, cv.COLOR_BGR2GRAY)
marker_corners, marker_IDs, reject = aruco.detectMarkers(
gray_frame, marker_dict, parameters=param_markers
)
if marker_corners:
for ids, corners in zip(marker_IDs, marker_corners):
cv.polylines(
frame, [corners.astype(np.int32)], True, (0, 255, 255), 4, cv.LINE_AA
)
corners = corners.reshape(4, 2)
corners = corners.astype(int)
top_right = corners[0].ravel()
top_left = corners[1].ravel()
bottom_right = corners[2].ravel()
bottom_left = corners[3].ravel()
cv.putText(
frame,
f"id: {ids[0]}",
top_right,
cv.FONT_HERSHEY_PLAIN,
1.3,
(200, 100, 0),
2,
cv.LINE_AA,
)
print(ids, " ", corners)
if ids == 18:
nic.main()