forked from realizator/stereopi-fisheye-robot
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy path1_test.py
108 lines (87 loc) · 2.87 KB
/
1_test.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
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
# Copyright (C) 2019 Eugene a.k.a. Realizator, stereopi.com, virt2real team
#
# This file is part of StereoPi tutorial scripts.
#
# StereoPi tutorial is free software: you can redistribute it
# and/or modify it under the terms of the GNU General Public License
# as published by the Free Software Foundation, either version 3 of the
# License, or (at your option) any later version.
#
# StereoPi tutorial is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with StereoPi tutorial.
# If not, see <http://www.gnu.org/licenses/>.
#
# <><><> SPECIAL THANKS: <><><>
#
# Thanks to Adrian and http://pyimagesearch.com, as a lot of
# code in this tutorial was taken from his lessons.
#
# Thanks to RPi-tankbot project: https://github.com/Kheiden/RPi-tankbot
#
# Thanks to rakali project: https://github.com/sthysel/rakali
# this command should be run in the docker command prompt before anything
# export LD_PRELOAD=/usr/lib/aarch64-linux-gnu/libgomp.so.1
from __future__ import print_function
from threading import Thread
import time
import argparse
import sys
import glob
import os
import jetson.inference
import jetson.utils
import numpy as np
import cv2 as cv
class VideoStreamWidget(object):
def __init__(self,src):
self.capture = cv.VideoCapture(src)
self.thread=Thread(target=self.update,args=())
self.thread.daemon=True
self.thread.start()
def update(self):
while True:
if self.capture.isOpened():
_=self.capture.grab()
time.sleep(.01)
def get_frame(self):
_,self.frame=self.capture.retrieve()
return self.frame
def rel_frame(self):
self.capture.release()
if __name__=='__main__':
# File for captured image
filename = './scenes/photo.png'
# Camera settings
cam_width = 640
cam_height = 480
# Final image capture settings
scale_ratio = 1
# Camera resolution height must be dividable by 16, and width by 32
cam_width = int((cam_width+31)/32)*32
cam_height = int((cam_height+15)/16)*16
print ("Used camera resolution: "+str(cam_width)+" x "+str(cam_height))
# Initialize the camera
video_stream_widgetI = VideoStreamWidget('/dev/video0')
video_stream_widgetD = VideoStreamWidget('/dev/video1')
while True:
frameIzq = video_stream_widgetI.get_frame()
frameDer = video_stream_widgetD.get_frame()
frameStereo = np.concatenate((frameIzq, frameDer), axis=1)
cv.imshow('Izq',frameIzq)
cv.imshow('Der',frameDer)
cv.imshow('Stereo',frameStereo)
key = cv.waitKey(1)
if key == ord('q'):
if (os.path.isdir("./scenes")==False):
os.makedirs("./scenes")
cv.imwrite(filename, frameStereo)
break
video_stream_widgetI.rel_frame()
video_stream_widgetD.rel_frame()
cv.destroyAllWindows()
exit(1)