wangjin0928 1 ano atrás
pai
commit
9b54ae6597
6 arquivos alterados com 38 adições e 31 exclusões
  1. +20
    -17
      AI.py
  2. BIN
      __pycache__/AI.cpython-38.pyc
  3. BIN
      segutils/__pycache__/trafficUtils.cpython-38.pyc
  4. +8
    -1
      segutils/trafficUtils.py
  5. BIN
      utilsK/__pycache__/queRiver.cpython-38.pyc
  6. +10
    -13
      utilsK/queRiver.py

+ 20
- 17
AI.py Ver arquivo

@@ -37,7 +37,7 @@ def get_postProcess_para(parfile):
return parPost["conf_thres"],parPost["iou_thres"],parPost["classes"],parPost["rainbows"]
def AI_process(im0s,model,segmodel,names,label_arraylist,rainbows,objectPar={ 'half':True,'device':'cuda:0' ,'conf_thres':0.25,'iou_thres':0.45,'allowedList':[0,1,2,3],'slopeIndex':[5,6,7],'segRegionCnt':1, 'trtFlag_det':False,'trtFlag_seg':False }, font={ 'line_thickness':None, 'fontSize':None,'boxLine_thickness':None,'waterLineColor':(0,255,255),'waterLineWidth':3} ,segPar={'modelSize':(640,360),'mean':(0.485, 0.456, 0.406),'std' :(0.229, 0.224, 0.225),'numpy':False, 'RGB_convert_first':True},mode='others',postPar=None):
print('########line40:',mode )
#输入参数
# im0s---原始图像列表
# model---检测模型,segmodel---分割模型(如若没有用到,则为None)
@@ -91,6 +91,7 @@ def AI_process(im0s,model,segmodel,names,label_arraylist,rainbows,objectPar={ 'h
time2=time.time()
datas = [[''], img, im0s, None,pred,seg_pred,10]
ObjectPar={ 'object_config':allowedList, 'slopeIndex':slopeIndex ,'segmodel':segFlag,'segRegionCnt':segRegionCnt }
p_result,timeOut = post_process_(datas,conf_thres, iou_thres,names,label_arraylist,rainbows,10,ObjectPar=ObjectPar,font=font,padInfos=padInfos)
if mode=='highWay3.0':
@@ -118,22 +119,24 @@ def AI_process(im0s,model,segmodel,names,label_arraylist,rainbows,objectPar={ 'h
postPar['mask']=seg_pred;postPar['det']=deepcopy(det_coords_original)
postPar['label_info']=label_info
tlist = list(postPar.keys()); tlist.sort()
list8, image,time_infos = trafficPostProcessingV2(postPar)
Accident_results = np.array(list8,dtype=object)
acc_det=[]
for bpoints in list8:
if bpoints[9]>conf_thres:
xyxy=bpoints[1:5];xyxy=[int(x) for x in xyxy]
cls=9;conf=bpoints[9];
box_acc = [cls,*xyxy,conf]
acc_det.append(box_acc)
p_result[1] = draw_painting_joint(xyxy,p_result[1],label_arraylist[int(cls)],score=conf,color=rainbows[int(cls)%20],font=font,socre_location="leftBottom")
det_coords_original.extend(acc_det)
p_result[2]= deepcopy(det_coords_original)
if len(det_coords_original)> 0:
list8, image,time_infos = trafficPostProcessingV2(postPar)
Accident_results = np.array(list8,dtype=object)
acc_det=[]
for bpoints in list8:
if bpoints[9]>conf_thres:
xyxy=bpoints[1:5];xyxy=[int(x) for x in xyxy]
cls=9;conf=bpoints[9];
box_acc = [cls,*xyxy,conf]
acc_det.append(box_acc)
if cls in allowedList:
p_result[1] = draw_painting_joint(xyxy,p_result[1],label_arraylist[int(cls)],score=conf,color=rainbows[int(cls)%20],font=font,socre_location="leftBottom")
det_coords_original.extend(acc_det)
p_result[2]= deepcopy(det_coords_original)
#print( ' time:',time_infos,' results.shape:',Accident_results.shape, p_result[2])
time_info = 'letterbox:%.1f, seg:%.1f , infer:%.1f,%s, seginfo:%s'%( (time01-time0)*1000, (time1-time01)*1000 ,(time2-time1)*1000,timeOut , segstr )

BIN
__pycache__/AI.cpython-38.pyc Ver arquivo


BIN
segutils/__pycache__/trafficUtils.cpython-38.pyc Ver arquivo


+ 8
- 1
segutils/trafficUtils.py Ver arquivo

@@ -863,7 +863,14 @@ def trafficPostProcessingV2(traffic_dict, debug=False):
# print("line347", traffic_dict['det']) # [[cls, x0, y0, x1, y1, score, 角度, 长宽比, 最小距离, [角度得分, 长宽比得分, 最小距离得分], 类别], ...]
list23 = traffic_dict['det']
for i in range(len(list23)):
list23[i][9] = max(list23[i][9])
if len(list23[i]) != 11:
list23[i].append(90)
list23[i].append(0.7)
list23[i].append(10)
list23[i].append(1)
list23[i].append(2)
else:
list23[i][9] = max(list23[i][9])
# print("line351", list23) # 目标对象, [[cls, x0, y0, x1, y1, score, 角度, 长宽比, 最小距离, max([角度得分, 长宽比得分, 最小距离得分]), 类别], ...]
else:
print("分割模型未检测到vehicle!")

BIN
utilsK/__pycache__/queRiver.cpython-38.pyc Ver arquivo


+ 10
- 13
utilsK/queRiver.py Ver arquivo

@@ -69,7 +69,7 @@ def drawWater(pred,image_array0,river={'color':(0,255,255),'line_width':3,'segRe
return image_array0,water
max_ids = get_largest_contours(contours,river['segRegionCnt']);
for max_id in max_ids:
cv2.fillPoly(water, [contours[max_id][:,0,:]], 1)
cv2.fillPoly(water, [contours[max_id][:,0,:]], 1)
if river['segLineShow']:
cv2.drawContours(image_array0,contours,max_id,river['color'],river['line_width'] )
return image_array0,water
@@ -98,7 +98,7 @@ def img_pad(img, size, pad_value=[114,114,114]):
pad_image = cv2.copyMakeBorder(img_r, top, bottom, left, right, cv2.BORDER_CONSTANT,value=pad_value)
return pad_image,(top, left,r)

def post_process_(datas,conf_thres, iou_thres,names,label_arraylist,rainbows,iframe,ObjectPar={ 'object_config':[0,1,2,3,4], 'slopeIndex':[5,6,7] ,'segmodel':True,'segRegionCnt':1 },font={ 'line_thickness':None, 'fontSize':None,'boxLine_thickness':None,'segLineShow':True,'waterLineColor':(0,255,255),'waterLineWidth':3},padInfos=None ):
def post_process_(datas,conf_thres, iou_thres,names,label_arraylist,rainbows,iframe,ObjectPar={ 'object_config':[0,1,2,3,4], 'slopeIndex':[5,6,7] ,'segmodel':True,'segRegionCnt':1 },font={ 'line_thickness':None, 'fontSize':None,'boxLine_thickness':None,'waterLineColor':(0,255,255),'waterLineWidth':3},padInfos=None ):
object_config,slopeIndex,segmodel,segRegionCnt=ObjectPar['object_config'],ObjectPar['slopeIndex'],ObjectPar['segmodel'],ObjectPar['segRegionCnt']
##输入dataset genereate 生成的数据,model预测的结果pred,nms参数
##主要操作NMS ---> 坐标转换 ---> 画图
@@ -117,14 +117,12 @@ def post_process_(datas,conf_thres, iou_thres,names,label_arraylist,rainbows,ifr
time1_3 = time.time()
det_xywh=[];
#im0_brg=cv2.cvtColor(im0,cv2.COLOR_RGB2BGR);
#if 'segLineShow' in font.keys():
if segmodel:
if segmodel:
if len(seg_pred)==2:
im0,water = illBuildings(seg_pred,im0)
else:
river={ 'color':font['waterLineColor'],'line_width':font['waterLineWidth'],'segRegionCnt':segRegionCnt,'segLineShow':font['segLineShow'] }
im0,water = drawWater(seg_pred,im0,river)
im0,water = drawWater(seg_pred,im0,river)
time2=time.time()
#plt.imshow(im0);plt.show()
if len(det)>0:
@@ -144,24 +142,23 @@ def post_process_(datas,conf_thres, iou_thres,names,label_arraylist,rainbows,ifr
det_c = det.clone(); det_c=det_c.cpu().numpy()
try:
area_factors = np.array([np.sum(water[int(x[1]):int(x[3]), int(x[0]):int(x[2])] )*1.0/(1.0*(x[2]-x[0])*(x[3]-x[1])+0.00001) for x in det_c] )
except Exception as e:
print('*****************************line143: error:',det_c, e)
except:
print('*****************************line143: error:',det_c)
water_flag = np.array(area_factors>0.1)
det = det[water_flag|slope_flag]##如果是水上目标,则需要与水的iou超过0.1;如果是岸坡目标,则直接保留。
#对检测匡绘图
for *xyxy, conf, cls in reversed(det):
xywh = (xyxy2xywh(torch.tensor(xyxy).view(1, 4)) / gn).view(-1).tolist() # normalized xywh
cls_c = cls.cpu().numpy()
conf_c = conf.cpu().numpy()
tt=[ int(x.cpu()) for x in xyxy]
line = [float(cls_c), *tt, float(conf_c)] # label format
det_xywh.append(line)

if int(cls_c) not in object_config: ###如果不是所需要的目标,则不显示;但依然输出到result。
continue

label = f'{names[int(cls)]} {conf:.2f}'
if int(cls_c) not in object_config: ###如果不是所需要的目标,则不显示
continue
im0 = draw_painting_joint(xyxy,im0,label_arraylist[int(cls)],score=conf,color=rainbows[int(cls)%20],font=font)
time3=time.time()
strout='nms:%s drawWater:%s,copy:%s,toTensor:%s,detDraw:%s '%(get_ms(time0,time1),get_ms(time1,time2),get_ms(time1_1,time1_2),get_ms(time1_2,time1_3), get_ms(time2,time3) )

Carregando…
Cancelar
Salvar