|
|
|
|
|
|
|
|
return image_array0,water |
|
|
return image_array0,water |
|
|
max_ids = get_largest_contours(contours,river['segRegionCnt']); |
|
|
max_ids = get_largest_contours(contours,river['segRegionCnt']); |
|
|
for max_id in max_ids: |
|
|
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']: |
|
|
if river['segLineShow']: |
|
|
cv2.drawContours(image_array0,contours,max_id,river['color'],river['line_width'] ) |
|
|
cv2.drawContours(image_array0,contours,max_id,river['color'],river['line_width'] ) |
|
|
return image_array0,water |
|
|
return image_array0,water |
|
|
|
|
|
|
|
|
pad_image = cv2.copyMakeBorder(img_r, top, bottom, left, right, cv2.BORDER_CONSTANT,value=pad_value) |
|
|
pad_image = cv2.copyMakeBorder(img_r, top, bottom, left, right, cv2.BORDER_CONSTANT,value=pad_value) |
|
|
return pad_image,(top, left,r) |
|
|
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'] |
|
|
object_config,slopeIndex,segmodel,segRegionCnt=ObjectPar['object_config'],ObjectPar['slopeIndex'],ObjectPar['segmodel'],ObjectPar['segRegionCnt'] |
|
|
##输入dataset genereate 生成的数据,model预测的结果pred,nms参数 |
|
|
##输入dataset genereate 生成的数据,model预测的结果pred,nms参数 |
|
|
##主要操作NMS ---> 坐标转换 ---> 画图 |
|
|
##主要操作NMS ---> 坐标转换 ---> 画图 |
|
|
|
|
|
|
|
|
time1_3 = time.time() |
|
|
time1_3 = time.time() |
|
|
det_xywh=[]; |
|
|
det_xywh=[]; |
|
|
#im0_brg=cv2.cvtColor(im0,cv2.COLOR_RGB2BGR); |
|
|
#im0_brg=cv2.cvtColor(im0,cv2.COLOR_RGB2BGR); |
|
|
#if 'segLineShow' in font.keys(): |
|
|
|
|
|
if segmodel: |
|
|
|
|
|
|
|
|
if segmodel: |
|
|
if len(seg_pred)==2: |
|
|
if len(seg_pred)==2: |
|
|
im0,water = illBuildings(seg_pred,im0) |
|
|
im0,water = illBuildings(seg_pred,im0) |
|
|
else: |
|
|
else: |
|
|
river={ 'color':font['waterLineColor'],'line_width':font['waterLineWidth'],'segRegionCnt':segRegionCnt,'segLineShow':font['segLineShow'] } |
|
|
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() |
|
|
time2=time.time() |
|
|
#plt.imshow(im0);plt.show() |
|
|
#plt.imshow(im0);plt.show() |
|
|
if len(det)>0: |
|
|
if len(det)>0: |
|
|
|
|
|
|
|
|
det_c = det.clone(); det_c=det_c.cpu().numpy() |
|
|
det_c = det.clone(); det_c=det_c.cpu().numpy() |
|
|
try: |
|
|
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] ) |
|
|
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) |
|
|
water_flag = np.array(area_factors>0.1) |
|
|
det = det[water_flag|slope_flag]##如果是水上目标,则需要与水的iou超过0.1;如果是岸坡目标,则直接保留。 |
|
|
det = det[water_flag|slope_flag]##如果是水上目标,则需要与水的iou超过0.1;如果是岸坡目标,则直接保留。 |
|
|
#对检测匡绘图 |
|
|
#对检测匡绘图 |
|
|
for *xyxy, conf, cls in reversed(det): |
|
|
for *xyxy, conf, cls in reversed(det): |
|
|
xywh = (xyxy2xywh(torch.tensor(xyxy).view(1, 4)) / gn).view(-1).tolist() # normalized xywh |
|
|
xywh = (xyxy2xywh(torch.tensor(xyxy).view(1, 4)) / gn).view(-1).tolist() # normalized xywh |
|
|
cls_c = cls.cpu().numpy() |
|
|
cls_c = cls.cpu().numpy() |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
conf_c = conf.cpu().numpy() |
|
|
conf_c = conf.cpu().numpy() |
|
|
tt=[ int(x.cpu()) for x in xyxy] |
|
|
tt=[ int(x.cpu()) for x in xyxy] |
|
|
line = [float(cls_c), *tt, float(conf_c)] # label format |
|
|
line = [float(cls_c), *tt, float(conf_c)] # label format |
|
|
det_xywh.append(line) |
|
|
det_xywh.append(line) |
|
|
|
|
|
|
|
|
if int(cls_c) not in object_config: ###如果不是所需要的目标,则不显示;但依然输出到result。 |
|
|
|
|
|
continue |
|
|
|
|
|
|
|
|
|
|
|
label = f'{names[int(cls)]} {conf:.2f}' |
|
|
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) |
|
|
im0 = draw_painting_joint(xyxy,im0,label_arraylist[int(cls)],score=conf,color=rainbows[int(cls)%20],font=font) |
|
|
time3=time.time() |
|
|
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) ) |
|
|
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) ) |