Skip to content

Commit 31293d5

Browse files
committed
Corrected camera matrices, added looping offline
1 parent 5fe6e89 commit 31293d5

File tree

1 file changed

+41
-26
lines changed

1 file changed

+41
-26
lines changed

BlimpDetect-8-28_JB.py

Lines changed: 41 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88

99
import socket
1010
import time
11+
import os
1112

1213
global imghsv
1314

@@ -52,32 +53,26 @@ def connect(ip,port):
5253
#http://www.vision.caltech.edu/bouguetj/calib_doc/
5354
def triang_3D(col_1, row_1, col_2, row_2) :
5455

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]])
6661

6762
#blimp position from camera 1
68-
#col_1 = 411
69-
#row_1 = 382
63+
#col_1 = 396
64+
#row_1 = 424
7065
#m1 = np.array([
7166
#blimp position from camera 2
72-
#col_2 = 531
73-
#row_2 = 178
67+
#col_2 = 518
68+
#row_2 = 538
7469

7570

7671
#translated from matlab:
7772

7873
#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]
8176
C1 = np.dot(invR1, m1T1)
8277
x0 = C1[0]
8378
y0 = C1[1]
@@ -94,8 +89,8 @@ def triang_3D(col_1, row_1, col_2, row_2) :
9489
c = z-z0
9590

9691
#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]
9994
C2 = np.dot(invR2, m1T2)
10095
x1 = C2[0]
10196
y1 = C2[1]
@@ -131,7 +126,7 @@ def triang_3D(col_1, row_1, col_2, row_2) :
131126
v2L = v2L.transpose()
132127
v1R = v1R.transpose()
133128
v2R = v2R.transpose()
134-
129+
135130
d1 = LA.norm(np.cross(np.subtract(v1L, v2L),np.subtract(M.transpose(),v2L)))/LA.norm(np.subtract(v1L,v2L))
136131
d2 = LA.norm(np.cross(np.subtract(v1R, v2R),np.subtract(M.transpose(),v2R)))/LA.norm(np.subtract(v1R,v2R))
137132
err1 = d1 + d2;
@@ -142,6 +137,7 @@ def triang_3D(col_1, row_1, col_2, row_2) :
142137
m1r = m1rn/m1rn[2]
143138
m2r = m2rn/m2rn[2]
144139
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+
145141

146142
return (x_coord[0], y_coord[0], z_coord[0], err1, err2)
147143

@@ -166,7 +162,7 @@ def getthresholdedimg(im):
166162
# determine HSV color thresholds for yellow, blue, and green
167163
# cv.InRange(src, lowerbound, upperbound, dst)
168164
# 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 )
170166

171167
# add color thresholds to blank 'threshold' image
172168
cv.Add(imgthreshold, imgblue, imgthreshold)
@@ -209,7 +205,7 @@ def procImg(img,sideName,dispFlag):
209205
if dispFlag:
210206
print("Area= " + str(area))
211207

212-
if (area > prevArea and area > 2000):
208+
if (area > prevArea and area > 3000):
213209
pt1 = (bound_rect[0], bound_rect[1])
214210
pt2 = (bound_rect[0] + bound_rect[2], bound_rect[1] + bound_rect[3])
215211

@@ -263,7 +259,18 @@ def procImg(img,sideName,dispFlag):
263259
cv.NamedWindow("west_threshold",cv.CV_WINDOW_AUTOSIZE)
264260
cv.NamedWindow("east_threshold",cv.CV_WINDOW_AUTOSIZE)
265261
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
267274

268275

269276
#address of the control server
@@ -276,9 +283,17 @@ def procImg(img,sideName,dispFlag):
276283

277284

278285
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
282297

283298
#open the images from file
284299
frame_west = cv.LoadImageM(fname_west,cv.CV_LOAD_IMAGE_COLOR);

0 commit comments

Comments
 (0)