Skip to content

Commit

Permalink
make jetson_test_cam.py work over ssh
Browse files Browse the repository at this point in the history
  • Loading branch information
BogGyver committed Apr 13, 2020
1 parent 6507934 commit 3da3f7d
Showing 1 changed file with 6 additions and 22 deletions.
28 changes: 6 additions & 22 deletions tools/webcam/jetson_test_cam.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,8 @@
import numpy as np
import time
import sys
import pygame
from pygame.locals import *
from selfdrive.car.tesla.readconfig import CarSettings
from PIL import Image

if __name__ == "__main__":
import cv2
Expand All @@ -15,45 +14,30 @@
" videoscale ! video/x-raw,width=%d,height=%d !"
" appsink ")
cs = CarSettings()
#cs.roadCameraID
#cs.driverCameraID
if len(sys.argv) != 2:
cam = str(sys.argv)
else:
cam = sys.argv[1]
if cam == "road" or cam == "driver":
print ("Processing camera [%s]\n" % cam)
pygame.init()
pygame.display.set_caption("OpenPilot Jetson camera stream on Pygame")
if cam == "road":
strm = strm_template % (cs.roadCameraID, 800, 600, 20, 1164,874)
screen = pygame.display.set_mode([1164,874])
else:
strm = strm_template % (cs.driverCameraID, 640, 480, 10, 1152,864)
screen = pygame.display.set_mode([1152,864])
print("Capturing with stream [%s}\n" % strm)
cap = cv2.VideoCapture(strm)
i = 0
try:
while True:
ret, frame = cap.read()
ret, img = cap.read()
if ret:
if i == 0:
print(frame.shape+'\r')
screen.fill([0,0,0])
frame = cv2.cvtColor(frame, cv2.COLOR_BGR2RGB)
frame = frame.swapaxes(0,1)
frame = pygame.surfarray.make_surface(frame)
screen.blit(frame, (0,0))
pygame.display.update()

for event in pygame.event.get():
if event.type == KEYDOWN:
sys.exit(0)
i = (i + 1) % 20
print(img.shape,end='\r')
cv2.imshow('preview',img)
cv2.waitKey(1)
except (KeyboardInterrupt, SystemExit):
pygame.quit()
cv2.destroyAllWindows()
else:
print ("\nUnknown arguments %s\n" % str(sys.argv))
print ("When using over ssh make sure you start seesion with 'ssh -Y user@jetson'\n")
print ("Usage: %s road|driver\n" % sys.argv[0])

0 comments on commit 3da3f7d

Please sign in to comment.