-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathproject.py
More file actions
105 lines (86 loc) · 3.91 KB
/
project.py
File metadata and controls
105 lines (86 loc) · 3.91 KB
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
import matplotlib.pyplot as plt
import argparse
import cv2 as cv
import pandas as pd
import constants
from computeDisparityMap import computeDisparityMap
from computeChessboard import computeChessboard
# GET ARGUMENTS
def getParams():
parser = argparse.ArgumentParser(prog='CVproject',description='computer vision project',epilog='credits carnivuth')
parser.add_argument('-i','--imageDim',default='100',help='image box dimension to cut from original frames for disparity computation',type=int)
parser.add_argument('-d','--numDisparities',default='128',help='numDisparities parameter for disparity map algorithm',type=int)
parser.add_argument('-b','--blockSize',default=constants.BEST_BLOCKSIZE_VALUE,help='blocksize parameter for disparity map algorithm', type=int)
parser.add_argument('-c','--chessboard',help='Compute chessboard recognition',action='store_true')
parser.add_argument('-p','--cutted_frame',help='print cutted window frame',action='store_true')
return parser.parse_args()
def main(LCameraView,RCameraView,numDisparities,blockSize,chessboard,interval,cutted_frame):
if chessboard:
df = pd.DataFrame(columns = ['dMain','z in mm','Z in m','alarm','Hdiff','Wdiff'])
else:
df = pd.DataFrame(columns = ['dMain','z in mm','Z in m','alarm'])
try:
while LCameraView.isOpened() and RCameraView.isOpened():
# Extract frames
Lret, frameL = LCameraView.read()
Rret, frameR = RCameraView.read()
# Check for corrupted frames
if not Lret or frameL is None or not Rret or frameR is None:
LCameraView.release()
RCameraView.release()
break
# Get image frames
imgL = cv.cvtColor(frameL, cv.COLOR_BGR2GRAY)
imgR = cv.cvtColor(frameR, cv.COLOR_BGR2GRAY)
# disparity map computation
z,dMain=computeDisparityMap(imgL,imgR,frameL.shape,numDisparities,blockSize,interval,cutted_frame)
if (z/1000 < constants.MINIMUM_DISTANCE):
alarm=1
else:
alarm=0
# print output data, adding data to dataframe
if chessboard:
Hdiff,Wdiff = computeChessboard(imgL,z)
print("{},{},{},{},{},{}".format(dMain,z,z/1000,alarm,Hdiff,Wdiff))
output = {
'dMain': dMain,
'z in mm': z,
'Z in m': z/1000,
'alarm': alarm,
'Hdiff': Hdiff,
'Wdiff': Wdiff
}
df.loc[len(df)] = output
else:
print("{},{},{},{}".format(dMain,z,z/1000,alarm))
output = {
'dMain': dMain,
'z in mm': z,
'Z in m': z/1000,
'alarm': alarm
}
df.loc[len(df)] = output
if chessboard:
df= df[df['Hdiff'] != -100]
df= df[df['Wdiff'] != -100]
# smoothing curves by local mean filtering
df['Wdiff'] = df.Wdiff.rolling(constants.SMOOTH).mean()
df['Hdiff'] = df.Hdiff.rolling(constants.SMOOTH).mean()
# plotting dataframe
df.plot(subplots=True,)
plt.tight_layout()
GlobalHdiffError = df['Hdiff'].mean()
GlobalWdiffError = df['Wdiff'].mean()
plt.plot([GlobalHdiffError,GlobalWdiffError])
plt.show()
except KeyboardInterrupt:
LCameraView.release()
RCameraView.release()
print("Released Video Resource")
# READ PARAMS
args =getParams()
# LOAD VIDEOS
LCameraView= cv.VideoCapture('robotL.avi')
RCameraView= cv.VideoCapture('robotR.avi')
# MAIN COMPUTATION
main(LCameraView,RCameraView,args.numDisparities,args.blockSize,args.chessboard,args.imageDim,args.cutted_frame)