-
Notifications
You must be signed in to change notification settings - Fork 25
/
3_pairs_cut.py
72 lines (62 loc) · 2.22 KB
/
3_pairs_cut.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
# 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
import cv2
import os
# Global variables preset
total_photos = 50
# Photos to be cutted resolution
photo_width = 1280
photo_height = 480
# Left and right images resolution
img_width = 640
img_height = 480
# Visualization options
ShowImages = False
# Counter setup
photo_counter = 0
# Main pair cut cycle
if (os.path.isdir("./pairs")==False):
os.makedirs("./pairs")
while photo_counter != total_photos:
photo_counter +=1
filename = './scenes/scene_'+str(photo_width)+'x'+str(photo_height)+\
'_'+str(photo_counter) + '.png'
if os.path.isfile(filename) == False:
print ("No file named "+filename)
continue
pair_img = cv2.imread(filename,-1)
if (ShowImages):
cv2.imshow("ImagePair", pair_img)
cv2.waitKey(0)
imgLeft = pair_img [0:img_height,0:img_width] #Y+H and X+W
imgRight = pair_img [0:img_height,img_width:photo_width]
leftName = './pairs/left_'+str(photo_counter).zfill(2)+'.png'
rightName = './pairs/right_'+str(photo_counter).zfill(2)+'.png'
cv2.imwrite(leftName, imgLeft)
cv2.imwrite(rightName, imgRight)
print ('Pair No '+str(photo_counter)+' saved.')
print ('End cycle')