Skip to content

Commit

Permalink
勉强拍完了技术视频
Browse files Browse the repository at this point in the history
  • Loading branch information
Sciroccogti committed Aug 15, 2019
1 parent 8727c23 commit c37d073
Show file tree
Hide file tree
Showing 10 changed files with 86 additions and 65 deletions.
Binary file added 1.jpg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified JPEGImages/13.jpg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
34 changes: 19 additions & 15 deletions QT.py
Original file line number Diff line number Diff line change
Expand Up @@ -367,7 +367,7 @@ def save_result(self):
else:
for res in self.result:
f.write('GOAL_ID=%s;' % res[0])
f.write('GOAL_Radius%.1f\n' % (res[4] / res[1]))
f.write('GOAL_Radius=%.1f\n' % (res[4] / res[1]))
res[1] = res[2] = res[3] = res[4] = res[5] = 0
f.write('END')
print(' \33[0;32m第%s回合结果已保存\033[0m' % self.round)
Expand Down Expand Up @@ -455,11 +455,10 @@ def capture_camera(self, camera):
corners = np.matmul(corners, [[640, 0], [0, 480]])
corners = np.append(corners, [[1], [1], [1], [1]], axis=1)
transed, angle = corner.square_trans(Table_2D, corners)
np.mean([transed[i][0] for i in range(4)])
data.append(
'%.1f' % (np.mean([transed[i][0] for i in range(4)]) / 10)) # x
data.append(
'%.1f' % (np.mean([transed[i][1] for i in range(4)]) / 10)) # y
avgx = np.mean([transed[i][0] for i in range(4)])
avgy = np.mean([transed[i][1] for i in range(4)])
data.append('%.1f' % (avgx / 10)) # x
data.append('%.1f' % (avgy / 10)) # y
data.append('') # radius
data.append('%.1f' % angle) # angle
del corners
Expand All @@ -474,14 +473,14 @@ def capture_camera(self, camera):
corners = [bs[1], bs[3], bs[5], bs[7]]
corners = np.matmul(corners, [[640, 0], [0, 480]])
corners = np.append(corners, [[1], [1], [1], [1]], axis=1)
transed, angle = circle_fit.circle_trans(Circle_2D, corners, lined)
np.mean([transed[i][0] for i in range(4)])
data.append(
'%.1f' % (np.mean([transed[i][0] for i in range(4)]) / 10)) # x
data.append(
'%.1f' % (np.mean([transed[i][1] for i in range(4)]) / 10)) # y
data.append('') # radius
data.append('%.1f' % angle) # angle
transed = circle_fit.circle_trans(Circle_2D, corners)
avgx = np.mean([transed[i][0] for i in range(4)])
avgy = np.mean([transed[i][1] for i in range(4)])
radius = (avgx ** 2 + avgy ** 2) ** 0.5
data.append('') # x
data.append('') # y
data.append('%.1f' % (radius / 10)) # radius
data.append('') # angle
del corners

print(" \033[0;34m绘制预测中...\033[0m")
Expand All @@ -495,15 +494,20 @@ def capture_camera(self, camera):
for data in datas:
for res in self.result:
if data[0][0] == res[0]: # 名称一致
res[1] += float(data[0][1].strip('%')) / 100 # 置信度之和
if self.isSquare:
if (float(data[1]) >= 55 or float(data[1]) <= 0 or float(data[2]) >= 55 or float(data[2]) <= 0):
continue
res[1] += float(data[0][1].strip('%')) / 100 # 置信度之和
res[2] += float(data[1]) * float(data[0]
[1].strip('%')) / 100 # x之和
res[3] += float(data[2]) * float(data[0]
[1].strip('%')) / 100 # y之和
res[5] += float(data[4]) * float(data[0]
[1].strip('%')) / 100 # a之和
else:
if float(data[3]) >= 30: # 错误识别
continue
res[1] += float(data[0][1].strip('%')) / 100 # 置信度之和
res[4] += float(data[3]) * float(data[0]
[1].strip('%')) / 100 # r之和

Expand Down
70 changes: 31 additions & 39 deletions circle_fit.py
Original file line number Diff line number Diff line change
Expand Up @@ -82,36 +82,39 @@ def circle_line(origin, thresed, S_thre=(100000, 600000)):
contours, _ = cv2.findContours(thresed, cv2.RETR_TREE, cv2.CHAIN_APPROX_SIMPLE)
top = []; bottle = []; right = []; left = []; center = []
Circle_2D = []
last_longest = 4
des_ell = tuple()
for cnt in contours:
if len(cnt) > 0:
if len(cnt) > last_longest: # 确保输出点数最多(且面积不超标)的椭圆
ell=cv2.fitEllipse(cnt) # 返回椭圆所在的矩形框# 函数返回值为:椭圆的中心坐标,长短轴长度(2a,2b),旋转角度
S2 =math.pi*ell[1][0]*ell[1][1] # 椭圆面积
# if S2>= S_thre[0] and S2 <= S_thre[1]: # 过滤面积小的
des_ell = ell

top_x = ell[0][0] - 0.5 * ell[1][0] * math.cos(math.radians(ell[2]))
top_y = ell[0][1] - 0.5 * ell[1][0] * math.sin(math.radians(ell[2]))
bottle_x = ell[0][0] + 0.5 * ell[1][0] * math.cos(math.radians(ell[2]))
bottle_y = ell[0][1] + 0.5 * ell[1][0] * math.sin(math.radians(ell[2]))

right_x = ell[0][0] + 0.5 * ell[1][1] * math.sin(math.radians(ell[2]))
right_y = ell[0][1] - 0.5 * ell[1][1] * math.cos(math.radians(ell[2]))
left_x = ell[0][0] - 0.5 * ell[1][1] * math.sin(math.radians(ell[2]))
left_y = ell[0][1] + 0.5 * ell[1][1] * math.cos(math.radians(ell[2]))
if S2>= S_thre[0] and S2 <= S_thre[1]: # 过滤面积小的
last_longest = len(cnt)
des_ell = ell

top_x = ell[0][0] - 0.5 * ell[1][0] * math.cos(math.radians(ell[2]))
top_y = ell[0][1] - 0.5 * ell[1][0] * math.sin(math.radians(ell[2]))
bottle_x = ell[0][0] + 0.5 * ell[1][0] * math.cos(math.radians(ell[2]))
bottle_y = ell[0][1] + 0.5 * ell[1][0] * math.sin(math.radians(ell[2]))

right_x = ell[0][0] + 0.5 * ell[1][1] * math.sin(math.radians(ell[2]))
right_y = ell[0][1] - 0.5 * ell[1][1] * math.cos(math.radians(ell[2]))
left_x = ell[0][0] - 0.5 * ell[1][1] * math.sin(math.radians(ell[2]))
left_y = ell[0][1] + 0.5 * ell[1][1] * math.cos(math.radians(ell[2]))

top = (int(top_x), int(top_y))
bottle = (int(bottle_x), int(bottle_y))
right = (int(right_x), int(right_y))
left = (int(left_x), int(left_y))
center = (int(ell[0][0]), int(ell[0][1]))

origin = cv2.ellipse(origin, des_ell, (0, 255, 0), 2) # 绘制椭圆

drawpoi(origin, top)
drawpoi(origin, bottle)
drawpoi(origin, right)
drawpoi(origin, left)
drawpoi(origin, center)
top = (int(top_x), int(top_y))
bottle = (int(bottle_x), int(bottle_y))
right = (int(right_x), int(right_y))
left = (int(left_x), int(left_y))
center = (int(ell[0][0]), int(ell[0][1]))

origin = cv2.ellipse(origin, des_ell, (0, 255, 0), 2) # 绘制椭圆

drawpoi(origin, top)
drawpoi(origin, bottle)
drawpoi(origin, right)
drawpoi(origin, left)
drawpoi(origin, center)

# rate = ell[1][1]/ell[1][0]
# elif S2< S_thre[1]:
Expand All @@ -137,7 +140,7 @@ def circle_desk(num, x, canny, hough):

thresed = corner.thres(img, x)
thresed_new = corner.remove_small_objects(thresed)
lined, _, Circle_2D = circle_line(img, thresed_new, [150000, 600000])
lined, _, Circle_2D = circle_line(img, thresed_new, [100000, 600000])
# affine_table_2D = np.float32([[0,0],[0,550],[550,0],[550,550]])
# M = cv2.getPerspectiveTransform(Table_2D,affine_table_2D)
# marked = cv2.warpPerspective(lined,M,(550,550)) # Perspective_Transformation
Expand All @@ -161,8 +164,6 @@ def circle_trans(Cicle_2D: '上下右左', points: '物体底部四点', lined_i
a = [0 for i in range(4)]
for i in range(4):
a[i] = (int(transed_points[i][0]), int(transed_points[i][1]))
angle = np.degrees(np.arccos(
(a[0][0] - a[0][1]) / (((a[0][0] - a[0][1])**2 + (a[1][0] - a[1][1])**2) ** 0.5)))

if len(lined_img):
# Perspective_Transformation
Expand All @@ -173,15 +174,6 @@ def circle_trans(Cicle_2D: '上下右左', points: '物体底部四点', lined_i
cv2.line(transed, a[2], a[3], (0, 255, 0), 1)
cv2.imshow('perspective', transed)

return transed_points, angle


# if __name__ == '__main__':
# ima = cv2.imread("JPEGImages/1.jpg", 3)
# out, top, bottle, right, left = my_fun(ima)
# cv2.imshow("output1.jpg",out)
# cv2.waitKey(0)


return transed_points


12 changes: 6 additions & 6 deletions data1.txt
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
red_low = 180
red_high = 210
green_low = 180
green_high = 210
blue_low = 180
blue_high = 210
red_low = 185
red_high = 215
green_low = 185
green_high = 215
blue_low = 185
blue_high = 215
3 changes: 2 additions & 1 deletion debugger.py
Original file line number Diff line number Diff line change
Expand Up @@ -255,8 +255,9 @@ def setting_2(self):
ho[2] = self.lineEdit_12.text()
img = corner.thres(self.img, self.x)
thresed = corner.remove_small_objects(img)
# edges = circle_fit.circle_canny(self.img, ca)
# edges = corner.square_canny(thresed, ca)
# cv2.imshow('edges', edges)
# lined, Table_2D = corner.square_line(self.img, edges, ho)
lined, _, Circle_2D = circle_fit.circle_line(self.img, thresed)
cv2.imshow('lines', lined)

Expand Down
21 changes: 21 additions & 0 deletions test.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
from yolo6D.Predict import *

if __name__ == "__main__":
name = 'ZB008'
img_path = '1.jpg'
img = cv2.imread(img_path)
model = dn('yolo6D/yolo-pose.cfg')
model.load_weights('weights/' + name + '.weights')
boxes = detect(name, model, img_path)
best_conf_est = -1
for j in range(len(boxes)):
if (boxes[j][18] > best_conf_est):
box_pr = boxes[j]
best_conf_est = boxes[j][18]

bss = [np.array(np.reshape(box_pr[:18], [9, 2]), dtype='float32')]
strs = []
strs.append(name)
strs.append(str(int(best_conf_est.numpy() * 100)) + '%')
strss = [strs]
draw_predict(bss, strss, img, -1)
Binary file added yolo6D/1.jpg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
5 changes: 4 additions & 1 deletion 东南大学-LabVIEW-R1.txt
Original file line number Diff line number Diff line change
@@ -1,2 +1,5 @@
START
GOAL_ID=ZA001;
GOAL_ID=ZA001;GOAL_X=12.5;GOAL_Y=46.0;GOAL_Angle=133.8
GOAL_ID=ZA004;GOAL_X=34.6;GOAL_Y=28.3;GOAL_Angle=83.1
GOAL_ID=ZB008;GOAL_X=23.2;GOAL_Y=39.2;GOAL_Angle=154.3
END
6 changes: 3 additions & 3 deletions 东南大学-LabVIEW-R2.txt
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
START
GOAL_ID=copico;GOAL_X=-117.7;GOAL_Y=545.0;GOAL_Angle=
GOAL_ID=copico;GOAL_X=39.9;GOAL_Y=-179.4;GOAL_Angle=
GOAL_ID=copico;GOAL_X=-125.7;GOAL_Y=-229.4;GOAL_Angle=
GOAL_ID=ZA001;GOAL_Radius30.8
GOAL_ID=ZA004;GOAL_Radius27.4
GOAL_ID=ZB008;GOAL_Radius48.4
END

0 comments on commit c37d073

Please sign in to comment.