8
8
9
9
import socket
10
10
import time
11
+ import os
11
12
12
13
global imghsv
13
14
@@ -52,32 +53,26 @@ def connect(ip,port):
52
53
#http://www.vision.caltech.edu/bouguetj/calib_doc/
53
54
def triang_3D (col_1 , row_1 , col_2 , row_2 ) :
54
55
55
- #R matrix for camera 1 (west side)
56
- R1 = np .array ([[- 74.2709 , 637.41 , - 255.7461 ], [865.2027 , 273.6518 , - 92.0415 ], [0.1602 , 0.3172 , - 0.9347 ]])
57
- #T matrix for camera 1
58
- T1 = np .array ([[1.3248e5 ], [4.1268e4 ], [505.0954 ]])
59
- P1 = np .hstack ((R1 , T1 ))
60
-
61
- #R matrix for camera 2 (east side)
62
- R2 = np .array ([[- 20.0487 , 179.5963 , - 666.7510 ], [751.5431 , - 397.57 , - 330.23 ], [- 0.2329 , - 0.5675 , - 0.7898 ]])
63
- #T matrix for camera 2
64
- T2 = np .array ([[3.7547e5 ], [3.3423e5 ], [907.6034 ]])
65
- P2 = np .hstack ((R2 , T2 ))
56
+ #Corrected camera matrix for west side
57
+ P1 = np .array ([[408.4918 , - 1607.7562 , 3814.1879 , 490234.8756 ], [- 1793.2995 , - 707.4668 , - 45.8775 , 646489.5760 ], [0.1810 , - 0.9505 , - 0.2524 , 1285.5524 ]])
58
+
59
+ #Corrected camera matrix for east side
60
+ P2 = np .array ([[- 49.3179 , - 518.1547 , - 4126.6037 , 847220.0489 ], [- 1776.8193 , 738.4249 , - 127.1965 , 963513.3797 ], [0.2075 , 0.9387 , - 0.2753 , 1589.9759 ]])
66
61
67
62
#blimp position from camera 1
68
- #col_1 = 411
69
- #row_1 = 382
63
+ #col_1 = 396
64
+ #row_1 = 424
70
65
#m1 = np.array([
71
66
#blimp position from camera 2
72
- #col_2 = 531
73
- #row_2 = 178
67
+ #col_2 = 518
68
+ #row_2 = 538
74
69
75
70
76
71
#translated from matlab:
77
72
78
73
#Camera 1
79
- invR1 = LA .inv (R1 )
80
- m1T1 = - 1 * T1
74
+ invR1 = LA .inv (P1 [ 0 : 3 , 0 : 3 ] )
75
+ m1T1 = - 1 * P1 [:, 3 ]
81
76
C1 = np .dot (invR1 , m1T1 )
82
77
x0 = C1 [0 ]
83
78
y0 = C1 [1 ]
@@ -94,8 +89,8 @@ def triang_3D(col_1, row_1, col_2, row_2) :
94
89
c = z - z0
95
90
96
91
#Camera 2
97
- invR2 = LA .inv (R2 )
98
- m1T2 = - 1 * T2
92
+ invR2 = LA .inv (P2 [ 0 : 3 , 0 : 3 ] )
93
+ m1T2 = - 1 * P2 [:, 3 ]
99
94
C2 = np .dot (invR2 , m1T2 )
100
95
x1 = C2 [0 ]
101
96
y1 = C2 [1 ]
@@ -131,7 +126,7 @@ def triang_3D(col_1, row_1, col_2, row_2) :
131
126
v2L = v2L .transpose ()
132
127
v1R = v1R .transpose ()
133
128
v2R = v2R .transpose ()
134
-
129
+
135
130
d1 = LA .norm (np .cross (np .subtract (v1L , v2L ),np .subtract (M .transpose (),v2L )))/ LA .norm (np .subtract (v1L ,v2L ))
136
131
d2 = LA .norm (np .cross (np .subtract (v1R , v2R ),np .subtract (M .transpose (),v2R )))/ LA .norm (np .subtract (v1R ,v2R ))
137
132
err1 = d1 + d2 ;
@@ -142,6 +137,7 @@ def triang_3D(col_1, row_1, col_2, row_2) :
142
137
m1r = m1rn / m1rn [2 ]
143
138
m2r = m2rn / m2rn [2 ]
144
139
err2 = np .sqrt (np .sum (np .square (m1r [0 :2 ]- m1 [0 :2 ]))) + np .sqrt (np .sum (np .square (m2r [0 :2 ]- m2 [0 :2 ])))
140
+
145
141
146
142
return (x_coord [0 ], y_coord [0 ], z_coord [0 ], err1 , err2 )
147
143
@@ -166,7 +162,7 @@ def getthresholdedimg(im):
166
162
# determine HSV color thresholds for yellow, blue, and green
167
163
# cv.InRange(src, lowerbound, upperbound, dst)
168
164
# for imgblue, lowerbound is 95, and upperbound is 115
169
- cv .InRangeS (imghsv , cv .Scalar (55 ,100 ,100 ), cv .Scalar (155 ,255 ,255 ), imgblue )
165
+ cv .InRangeS (imghsv , cv .Scalar (70 ,100 ,100 ), cv .Scalar (155 ,255 ,255 ), imgblue )
170
166
171
167
# add color thresholds to blank 'threshold' image
172
168
cv .Add (imgthreshold , imgblue , imgthreshold )
@@ -209,7 +205,7 @@ def procImg(img,sideName,dispFlag):
209
205
if dispFlag :
210
206
print ("Area= " + str (area ))
211
207
212
- if (area > prevArea and area > 2000 ):
208
+ if (area > prevArea and area > 3000 ):
213
209
pt1 = (bound_rect [0 ], bound_rect [1 ])
214
210
pt2 = (bound_rect [0 ] + bound_rect [2 ], bound_rect [1 ] + bound_rect [3 ])
215
211
@@ -263,7 +259,18 @@ def procImg(img,sideName,dispFlag):
263
259
cv .NamedWindow ("west_threshold" ,cv .CV_WINDOW_AUTOSIZE )
264
260
cv .NamedWindow ("east_threshold" ,cv .CV_WINDOW_AUTOSIZE )
265
261
cv .NamedWindow ("west_hsv" ,cv .CV_WINDOW_AUTOSIZE )
266
- cv .NamedWindow ("east_hsv" ,cv .CV_WINDOW_AUTOSIZE )
262
+ cv .NamedWindow ("east_hsv" ,cv .CV_WINDOW_AUTOSIZE )
263
+
264
+ #Live images from the IP cameras
265
+ #(if not live, then this file needs to be in folder with a bunch of images)
266
+ #(if live, then need to be local at WID)
267
+ liveIP = 1
268
+ if liveIP == 0 :
269
+ #need to be in directory with a bunch of images
270
+ dirList = os .listdir (os .getcwd ())
271
+ num_base = 0
272
+ east_offset = 0
273
+ west_offset = 147
267
274
268
275
269
276
#address of the control server
@@ -276,9 +283,17 @@ def procImg(img,sideName,dispFlag):
276
283
277
284
278
285
while (1 ):
279
- #capture images from cameras, store images to file
280
- urllib .urlretrieve (url_west ,fname_west )
281
- urllib .urlretrieve (url_east ,fname_east )
286
+ if liveIP :
287
+ #capture images from cameras, store images to file
288
+ urllib .urlretrieve (url_west ,fname_west )
289
+ urllib .urlretrieve (url_east ,fname_east )
290
+ else :
291
+ num_base = (num_base + 1 )% 145
292
+ west_num = west_offset + num_base
293
+ east_num = east_offset + num_base
294
+ fname_west = dirList [west_num ]
295
+ fname_east = dirList [east_num ]
296
+ cv .WaitKey (2000 ) #wait for 2 seconds so I can see the output
282
297
283
298
#open the images from file
284
299
frame_west = cv .LoadImageM (fname_west ,cv .CV_LOAD_IMAGE_COLOR );
0 commit comments