Kaynağa Gözat

degug trafficV7

master
wangjin0928 1 yıl önce
ebeveyn
işleme
589b9e3098
4 değiştirilmiş dosya ile 68 ekleme ve 40 silme
  1. +1
    -1
      AI.py
  2. BIN
      __pycache__/AI.cpython-38.pyc
  3. BIN
      segutils/__pycache__/trafficUtils.cpython-38.pyc
  4. +67
    -39
      segutils/trafficUtils.py

+ 1
- 1
AI.py Dosyayı Görüntüle

@@ -116,9 +116,9 @@ def AI_process(im0s,model,segmodel,names,label_arraylist,rainbows,objectPar={ 'h
postPar['mask']=seg_pred;postPar['det']=deepcopy(det_coords)
postPar['label_info']=label_info
tlist = list(postPar.keys()); tlist.sort()
if len(det_coords)> 0:
list8, image,time_infos = trafficPostProcessingV2(postPar)
print('##list8:',list8)
Accident_results = np.array(list8,dtype=object)
acc_det=[]
for bpoints in list8:

BIN
__pycache__/AI.cpython-38.pyc Dosyayı Görüntüle


BIN
segutils/__pycache__/trafficUtils.cpython-38.pyc Dosyayı Görüntüle


+ 67
- 39
segutils/trafficUtils.py Dosyayı Görüntüle

@@ -707,6 +707,8 @@ def trafficPostProcessingV2(traffic_dict, debug=False):
list3 = [] # # 存储vehicle最小外接矩形的最短边
list4 = [] # list4存储车辆的box参数
list5 = [] # 存储vehicle的宽高
list14 = []
list15 = []
for cnt in contours: # 道路
rect = cv2.minAreaRect(cnt)
if rect[1][0] * rect[1][1] > traffic_dict['speedRoadArea']: # 过滤掉面积小于阈值的speedRoad
@@ -730,13 +732,13 @@ def trafficPostProcessingV2(traffic_dict, debug=False):
list1.append(rect[1]) # 将道路的宽高存储在list1中
list2.append(list1)
list1 = []
if len(list2) == 0:
print("分割出的speedRoad区域的面积小于设定值,请调整设定值!")
# if len(list2) == 0:
# print("分割出的speedRoad区域的面积小于设定值,请调整设定值!")
# print("line213", list2)
list14 = []
list15 = []
count = 0
for i in range(0, len(traffic_dict['vehicleCoordinate']), 2):
list16 = [] # 5.6
mask = np.zeros(image_vehicle.shape[:2], dtype="uint8")
x0 = int(traffic_dict['vehicleCoordinate'][i][0] * traffic_dict['ZoomFactor']['x'])
@@ -755,8 +757,52 @@ def trafficPostProcessingV2(traffic_dict, debug=False):
contours2, hierarchy2 = cv2.findContours(img2, cv2.RETR_EXTERNAL, cv2.CHAIN_APPROX_NONE)
if len(contours2) != 0:
list10.append(contours2)
list14.append(traffic_dict['det'][count])
if len(contours2) > 1: # 这里我通过比较同一检测框内各个contours对应的最小外接矩形的面积,来剔除那些存在干扰的contours,最终只保留一个contours
for j in range(len(contours2)):
contours_j = contours2[j]
rect = cv2.minAreaRect(contours_j)
list16.append(rect[1][0] * rect[1][1])
if max(list16) >= traffic_dict['vehicleArea']:
maxAreaIndex = list16.index(max(list16))
maxAreacontours = contours2[maxAreaIndex]
if len(maxAreacontours) >= 6:
list10.append(maxAreacontours)
list14.append(traffic_dict['det'][count])
else:
traffic_dict['det'][int(i / 2)].append(5)
traffic_dict['det'][int(i / 2)].append(0.5)
traffic_dict['det'][int(i / 2)].append(15)
traffic_dict['det'][int(i / 2)].append(0.01)
traffic_dict['det'][int(i / 2)].append(3)
list15.append(traffic_dict['det'][int(i / 2)])
else:
traffic_dict['det'][int(i / 2)].append(5)
traffic_dict['det'][int(i / 2)].append(0.5)
traffic_dict['det'][int(i / 2)].append(15)
traffic_dict['det'][int(i / 2)].append(0.01)
traffic_dict['det'][int(i / 2)].append(3)
list15.append(traffic_dict['det'][int(i / 2)])
elif len(contours2) == 1:
contours_j = contours2[0]
rect = cv2.minAreaRect(contours_j)
if rect[1][0] * rect[1][1] >= traffic_dict['vehicleArea']:
if len(contours_j) >= 6:
list10.append(contours_j)
list14.append(traffic_dict['det'][count])
else:
traffic_dict['det'][int(i / 2)].append(5)
traffic_dict['det'][int(i / 2)].append(0.5)
traffic_dict['det'][int(i / 2)].append(15)
traffic_dict['det'][int(i / 2)].append(0.01)
traffic_dict['det'][int(i / 2)].append(3)
list15.append(traffic_dict['det'][int(i / 2)])
else:
traffic_dict['det'][int(i / 2)].append(5)
traffic_dict['det'][int(i / 2)].append(0.5)
traffic_dict['det'][int(i / 2)].append(15)
traffic_dict['det'][int(i / 2)].append(0.01)
traffic_dict['det'][int(i / 2)].append(3)
list15.append(traffic_dict['det'][int(i / 2)])
else:
traffic_dict['det'][int(i/2)].append(5)
traffic_dict['det'][int(i/2)].append(0.5)
@@ -766,42 +812,22 @@ def trafficPostProcessingV2(traffic_dict, debug=False):
list15.append(traffic_dict['det'][int(i/2)])
count += 1
traffic_dict['det'] = list14
# list12 = []
if len(list10) != 0:
for i in range(len(list10)): # 选取落在检测框范围内的分割区域,存在一个问题,就是其他vehicle的一小部分分割区域可能也落在了检测框中,这时会产生多个contours,
list12 = []
if len(list10[i]) > 1: # 这里我通过比较同一检测框内各个contours对应的最小外接矩形的面积,来剔除那些存在干扰的contours,最终只保留一个contours
for j in range(len(list10[i])):
contours_j = list10[i][j]
rect = cv2.minAreaRect(contours_j)
list12.append(rect)
list13 = [list12[g][1][0] * list12[g][1][1] for g in range(len(list12))]
maxAreaIndex = list13.index(max(list13))
rect = list12[maxAreaIndex]
box = cv2.boxPoints(rect).astype(np.int32)
maxAreacontours = list10[i][maxAreaIndex]
ellipse = cv2.fitEllipse(maxAreacontours) # (中心点坐标(x,y),(短轴长度,长轴长度),短轴与水平线的夹角)
if ellipse[2] >= 0 and ellipse[2] < 90:
vehicleAngle = 90 + ellipse[2]
elif ellipse[2] >= 90 and ellipse[2] < 180:
vehicleAngle = ellipse[2] - 90
elif ellipse[2] == 180:
vehicleAngle = 90
elif len(list10[i]) == 1:
rect = cv2.minAreaRect(np.array(list10[i][0]))
box = cv2.boxPoints(rect).astype(np.int32)
maxAreacontours = list10[i][0]
ellipse = cv2.fitEllipse(maxAreacontours)
if ellipse[2] >= 0 and ellipse[2] < 90:
vehicleAngle = 90 + ellipse[2]
elif ellipse[2] >= 90 and ellipse[2] < 180:
vehicleAngle = ellipse[2] - 90
elif ellipse[2] == 180:
vehicleAngle = 90
for i in range(len(list10)): # 选取落在检测框范围内的分割区域,存在一个问题,就是其他vehicle的一小部分分割区域可能也落在了检测框中,这时会产生多个contours.
ellipse = cv2.fitEllipse(list10[i])
if ellipse[2] >= 0 and ellipse[2] < 90:
vehicleAngle = 90 + ellipse[2]
elif ellipse[2] >= 90 and ellipse[2] < 180:
vehicleAngle = ellipse[2] - 90
elif ellipse[2] == 180:
vehicleAngle = 90
rect = cv2.minAreaRect(list10[i])
box = cv2.boxPoints(rect).astype(np.int32)
list3.append(min(rect[1]))
list4.append(box)
list5.append(rect[1])
for j in range(len(list2)):
if (rect[0][0] > list2[j][0] and rect[0][0] < list2[j][1]) and (rect[0][1] > list2[j][2] and rect[0][1] < list2[j][3]): # 判断车辆矩形框的中心点坐标是否在道路矩形框Xmin,Xmax,Ymin和Ymax的范围内;
box = cv2.boxPoints(rect).astype(np.int32) # 将Box2D结构作为输入并返回4个角点。
@@ -890,11 +916,13 @@ def trafficPostProcessingV2(traffic_dict, debug=False):
list23.append(list15[i])
# print("line372", list23) # 目标对象, [[cls, x0, y0, x1, y1, score, 角度, 长宽比, 最小距离, max([角度得分, 长宽比得分, 最小距离得分]), 类别], ...]
else:
print("分割模型未检测到vehicle!")
list23 = traffic_dict['det']
# print("分割模型未检测到vehicle!")
list23 = list15
print("line418", list23)
t6 = time.time()
time_infos = 'postTime:%.2f (分割时间:%.2f, findContours:%.2f ruleJudge:%.2f)' % (
get_ms(t6, t3), get_ms(t4, t3), get_ms(t5, t4), get_ms(t6, t5))
return list23, image, time_infos

Yükleniyor…
İptal
Kaydet