-
Notifications
You must be signed in to change notification settings - Fork 27
/
Copy pathrun_webcam_tx2.py
69 lines (49 loc) · 1.92 KB
/
run_webcam_tx2.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
import logging
import sys
import time
import math
import cv2
import numpy as np
from openpose import pyopenpose as op
if __name__ == '__main__':
fps_time = 0
params = dict()
params["model_folder"] = "../../models/"
# Starting OpenPose
opWrapper = op.WrapperPython()
opWrapper.configure(params)
opWrapper.start()
print("OpenPose start")
stream = "nvarguscamerasrc ! video/x-raw(memory:NVMM), width=(int)640, height=(int)480,format=(string)NV12, framerate=(fraction)30/1 ! nvvidconv flip-method=0 ! video/x-raw, format=(string)BGRx ! videoconvert ! video/x-raw, format=(string)BGR ! appsink"
cap = cv2.VideoCapture(stream, cv2.CAP_GSTREAMER)
# cap.set(cv2.CAP_PROP_FRAME_WIDTH, 640)
# cap.set(cv2.CAP_PROP_FRAME_HEIGHT, 480)
ret_val, img = cap.read()
fourcc = cv2.VideoWriter_fourcc('m', 'p', '4', 'v')
out_video = cv2.VideoWriter('/tmp/output.mp4', fourcc, cap.get(cv2.CAP_PROP_FPS), (640, 480))
count = 0
if cap is None:
print("Camera Open Error")
sys.exit(0)
while cap.isOpened() and count < 30:
ret_val, dst = cap.read()
if ret_val == False:
print("Camera read Error")
break
#dst = cv2.resize(image, dsize=(320, 240), interpolation=cv2.INTER_AREA)
#cv2.imshow("OpenPose 1.5.1 - Tutorial Python API", dst)
#continue
datum = op.Datum()
datum.cvInputData = dst
opWrapper.emplaceAndPop([datum])
fps = 1.0 / (time.time() - fps_time)
fps_time = time.time()
newImage = datum.cvOutputData[:, :, :]
cv2.putText(newImage , "FPS: %f" % (fps), (20, 40), cv2.FONT_HERSHEY_SIMPLEX, 1, (0, 255, 0), 2)
out_video.write(newImage)
print("captured fps %f"%(fps))
cv2.imshow("OpenPose 1.5.1 - Tutorial Python API", newImage)
count += 1
cv2.destroyAllWindows()
out_video.release()
cap.release()