|
|
@@ -806,33 +806,6 @@ def OCR_demo2(opt): |
|
|
|
|
|
|
|
def OBB_track_demo(opt):
|
|
|
|
###倾斜框(OBB)的ship目标检测
|
|
|
|
'''
|
|
|
|
par={
|
|
|
|
'model_size':(608,608), #width,height
|
|
|
|
'K':100, #Maximum of objects'
|
|
|
|
'conf_thresh':0.18,##Confidence threshold, 0.1 for general evaluation
|
|
|
|
'device':"cuda:0",
|
|
|
|
|
|
|
|
'down_ratio':4,'num_classes':15,
|
|
|
|
#'weights':'../AIlib2/weights/conf/ship2/obb_608X608.engine',
|
|
|
|
'weights':'../weights/%s/AIlib2/%s/obb_608X608_%s_fp16.engine'%(opt['gpu'],opt['business'],opt['gpu']),
|
|
|
|
'dataset':'dota',
|
|
|
|
'test_dir': '/mnt/thsw2/DSP2/videos/obbShips',
|
|
|
|
'outpth': 'images/results',
|
|
|
|
'half': False,
|
|
|
|
'mean':(0.5, 0.5, 0.5),
|
|
|
|
'std':(1, 1, 1),
|
|
|
|
'model_size':(608,608),##width,height
|
|
|
|
'trackPar':{'sort_max_age':2,'sort_min_hits':3,'sort_iou_thresh':0.2,'det_cnt':10,'windowsize':29,'patchCnt':100},
|
|
|
|
'heads': {'hm': None,'wh': 10,'reg': 2,'cls_theta': 1},
|
|
|
|
'decoder':None,
|
|
|
|
'test_flag':True,
|
|
|
|
'postFile': '../AIlib2/weights/conf/%s/para.json'%(opt['business'] ),###后处理参数文件
|
|
|
|
'drawBox':True,#####是否画框
|
|
|
|
'digitWordFont': { 'line_thickness':2,'boxLine_thickness':1,'wordSize':40, 'fontSize':1.0,'label_location':'leftTop'},
|
|
|
|
'labelnames':"../AIlib2/weights/conf/%s/labelnames.json"%(opt['business'] ), ###检测类别对照表
|
|
|
|
}
|
|
|
|
'''
|
|
|
|
par={
|
|
|
|
|
|
|
|
'obbModelPar':{
|
|
|
@@ -917,17 +890,69 @@ def OBB_track_demo(opt): |
|
|
|
for video_url in video_urls:
|
|
|
|
process_video(video_url, parIn ,mode='obbTrack')
|
|
|
|
|
|
|
|
def crowd_demo(opt):
|
|
|
|
if opt['business']=='crowdCounting':
|
|
|
|
|
|
|
|
from crowd import crowdModel as Model
|
|
|
|
par={
|
|
|
|
'mean':[0.485, 0.456, 0.406], 'std':[0.229, 0.224, 0.225],'threshold':0.5,
|
|
|
|
'input_profile_shapes':[(1,3,256,256),(1,3,1024,1024),(1,3,2048,2048)],
|
|
|
|
'modelPar':{'backbone':'vgg16_bn', 'gpu_id':0,'anchorFlag':False, 'width':None,'height':None ,'line':2, 'row':2},
|
|
|
|
|
|
|
|
'weights':"../weights/%s/AIlib2/%s/crowdCounting_%s_dynamic.engine"%(opt['gpu'], opt['business'] ,opt['gpu'] ),###检测模型路径
|
|
|
|
'testImgPath':'images/%s'%(opt['business'] ),###测试图像的位置
|
|
|
|
'testOutPath':'images/results/',###输出测试图像位置
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
#weights='weights/best_mae.pth'
|
|
|
|
cmodel = Model(par['weights'],par)
|
|
|
|
|
|
|
|
img_path = par['testImgPath']
|
|
|
|
File = os.listdir(img_path)
|
|
|
|
targetList = []
|
|
|
|
for file in File[0:]:
|
|
|
|
COORlist = []
|
|
|
|
imgPath = img_path + os.sep + file
|
|
|
|
|
|
|
|
|
|
|
|
img_raw = cv2.cvtColor(cv2.imread(imgPath),cv2.COLOR_BGR2RGB)
|
|
|
|
# cmodel.eval---
|
|
|
|
# 输入读取的RGB数组
|
|
|
|
# 输出:list,0--原图,1-人头坐标list,2-对接OBB的格式数据,其中4个坐标均相同,2-格式如下:
|
|
|
|
# [ [ [ (x0,y0),(x1,y1),(x2,y2),(x3,y3) ],score, cls ], [ [ (x0,y0),(x1,y1),(x2,y2),(x3,y3) ],score ,cls ],........ ]
|
|
|
|
|
|
|
|
prets, infos = cmodel.eval(img_raw)
|
|
|
|
|
|
|
|
|
|
|
|
print(file,infos,' 人数:',len(prets[1]))
|
|
|
|
|
|
|
|
|
|
|
|
img_to_draw = cv2.cvtColor(np.array(img_raw), cv2.COLOR_RGB2BGR)
|
|
|
|
# 打印预测图像中人头的个数
|
|
|
|
for p in prets[1]:
|
|
|
|
img_to_draw = cv2.circle(img_to_draw, (int(p[0]), int(p[1])), 2, (0, 255, 0), -1)
|
|
|
|
COORlist.append((int(p[0]), int(p[1])))
|
|
|
|
# 将各测试图像中的人头坐标存储在targetList中, 格式:[[(x1, y1),(x2, y2),...], [(X1, Y1),(X2, Y2),..], ...]
|
|
|
|
targetList.append(COORlist)
|
|
|
|
#time.sleep(2)
|
|
|
|
# 保存预测图片
|
|
|
|
cv2.imwrite(os.path.join(par['testOutPath'], file), img_to_draw)
|
|
|
|
|
|
|
|
if __name__=="__main__":
|
|
|
|
|
|
|
|
#jkm_demo()
|
|
|
|
#businessAll=['river', 'river2','highWay2','noParking','drowning','forest2','vehicle','pedestrian','smogfire' , 'AnglerSwimmer','channelEmergency', 'countryRoad','cityMangement','ship2','cityMangement2','cityRoad','illParking']
|
|
|
|
businessAll = ['cityMangement2']
|
|
|
|
businessAll=['river', 'river2','highWay2','noParking','drowning','forest2','vehicle','pedestrian','smogfire' , 'AnglerSwimmer','channelEmergency', 'countryRoad','cityMangement','ship2','cityMangement2','cityRoad','illParking',"crowdCounting"]
|
|
|
|
businessAll = ['crowdCounting']
|
|
|
|
|
|
|
|
for busi in businessAll:
|
|
|
|
print('-'*40,'beg to test:',busi,'-'*40)
|
|
|
|
opt={'gpu':'2080Ti','business':busi}
|
|
|
|
if busi in ['ship2']:
|
|
|
|
OBB_track_demo(opt)
|
|
|
|
elif opt['business'] in ['crowdCounting'] :
|
|
|
|
crowd_demo(opt)
|
|
|
|
else:
|
|
|
|
#if opt['business'] in ['river','highWay2','noParking','drowning','']:
|
|
|
|
det_track_demo(opt )
|