wangjin0928 11 месяцев назад
Родитель
Сommit
f152998111
29 измененных файлов: 115 добавлений и 31 удалений
  1. +54
    -2
      demo.py
  2. +54
    -29
      demo3.0.py
  3. Двоичные данные
      images/crowdCounting/t1.jpg
  4. Двоичные данные
      images/crowdCounting/t2.jpg
  5. Двоичные данные
      images/crowdCounting/t3.jpg
  6. Двоичные данные
      images/crowdCounting/t4.jpg
  7. Двоичные данные
      images/crowdCounting/w1.jpg
  8. Двоичные данные
      images/crowdCounting/w2.jpg
  9. Двоичные данные
      images/crowdCounting/w3.jpg
  10. Двоичные данные
      images/crowdCounting/w4.jpg
  11. Двоичные данные
      images/results/2023-09-19-09-46-46_frame-18507-18787_type_20230919094646113613-2-0-0_OR.jpg
  12. Двоичные данные
      images/results/DJI_0974_15.jpg
  13. +3
    -0
      images/results/DJI_0974_15.txt
  14. Двоичные данные
      images/results/DJI_0974_15_mask.png
  15. Двоичные данные
      images/results/DJI_0988_20.jpg
  16. +4
    -0
      images/results/DJI_0988_20.txt
  17. Двоичные данные
      images/results/DJI_0988_20_mask.png
  18. Двоичные данные
      images/results/DJI_0996_104.jpg
  19. Двоичные данные
      images/results/DJI_20230626104206_0011_S_7.jpg
  20. +0
    -0
      images/results/DJI_20230626104206_0011_S_7.txt
  21. Двоичные данные
      images/results/DJI_20230626104206_0011_S_7_mask.png
  22. Двоичные данные
      images/results/t1.jpg
  23. Двоичные данные
      images/results/t2.jpg
  24. Двоичные данные
      images/results/t3.jpg
  25. Двоичные данные
      images/results/t4.jpg
  26. Двоичные данные
      images/results/w1.jpg
  27. Двоичные данные
      images/results/w2.jpg
  28. Двоичные данные
      images/results/w3.jpg
  29. Двоичные данные
      images/results/w4.jpg

+ 54
- 2
demo.py Просмотреть файл

@@ -959,12 +959,62 @@ def jkm_demo():
if isinstance(dataBack[key],list):
cv2.imwrite( 'images/results/%s_%s.jpg'%( imgp.replace('.jpg','').replace('.png',''),key),dataBack[key][0] ) ###返回值: dataBack
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=['river2','AnglerSwimmer', 'countryRoad','forest2', 'pedestrian' , 'smogfire' , 'vehicle','ship2',"highWay2","channelEmergency","cityMangement","drowning","noParking","illParking",'cityMangement2',"cityRoad"]
businessAll=['river2','AnglerSwimmer', 'countryRoad','forest2', 'pedestrian' , 'smogfire' , 'vehicle','ship2',"highWay2","channelEmergency","cityMangement","drowning","noParking","illParking",'cityMangement2',"cityRoad","crowdCounting"]
businessAll = ['cityMangement2']
businessAll = ['crowdCounting']
# forest 、 ocr2 、ocr_en 、 river 、 road 、 ship ,目前都没有在用
@@ -973,6 +1023,8 @@ if __name__=="__main__":
opt={'gpu':'2080Ti','business':busi}
if opt['business'] in ['highWay2','river2','drowning','noParking','river',"illParking","cityMangement2"]:
detSeg_demo(opt)
elif opt['business'] in ['crowdCounting'] :
crowd_demo(opt)
elif opt['business'] in ['ship2']:
OBB_demo(opt)
elif opt['business'] in ['ocr']:

+ 54
- 29
demo3.0.py Просмотреть файл

@@ -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 )

Двоичные данные
images/crowdCounting/t1.jpg Просмотреть файл

Before After
Width: 800  |  Height: 524  |  Size: 147KB

Двоичные данные
images/crowdCounting/t2.jpg Просмотреть файл

Before After
Width: 500  |  Height: 281  |  Size: 41KB

Двоичные данные
images/crowdCounting/t3.jpg Просмотреть файл

Before After

Двоичные данные
images/crowdCounting/t4.jpg Просмотреть файл

Before After
Width: 4000  |  Height: 2250  |  Size: 3.4MB

Двоичные данные
images/crowdCounting/w1.jpg Просмотреть файл

Before After
Width: 1063  |  Height: 597  |  Size: 148KB

Двоичные данные
images/crowdCounting/w2.jpg Просмотреть файл

Before After
Width: 1050  |  Height: 595  |  Size: 133KB

Двоичные данные
images/crowdCounting/w3.jpg Просмотреть файл

Before After
Width: 1059  |  Height: 597  |  Size: 141KB

Двоичные данные
images/crowdCounting/w4.jpg Просмотреть файл

Before After
Width: 1033  |  Height: 558  |  Size: 124KB

Двоичные данные
images/results/2023-09-19-09-46-46_frame-18507-18787_type_20230919094646113613-2-0-0_OR.jpg Просмотреть файл

Before After
Width: 720  |  Height: 540  |  Size: 138KB

Двоичные данные
images/results/DJI_0974_15.jpg Просмотреть файл

Before After
Width: 3840  |  Height: 2160  |  Size: 2.7MB

+ 3
- 0
images/results/DJI_0974_15.txt Просмотреть файл

@@ -0,0 +1,3 @@
4.0,716.0,521.0,1189.0,0.7485809326171875,2.0
1909.0,873.0,3017.0,1341.0,0.9105710983276367,0.0
740.0,803.0,1798.0,1279.0,0.9193859100341797,0.0

Двоичные данные
images/results/DJI_0974_15_mask.png Просмотреть файл

Before After
Width: 5  |  Height: 6  |  Size: 102B

Двоичные данные
images/results/DJI_0988_20.jpg Просмотреть файл

Before After
Width: 3840  |  Height: 2160  |  Size: 2.0MB

+ 4
- 0
images/results/DJI_0988_20.txt Просмотреть файл

@@ -0,0 +1,4 @@
1494.0,1604.0,2538.0,2068.0,0.9015560150146484,0.0
1579.0,486.0,2501.0,895.0,0.9098825454711914,0.0
775.0,1700.0,1252.0,2159.0,0.9259564876556396,3.0
1510.0,1192.0,2504.0,1622.0,0.9318015575408936,0.0

Двоичные данные
images/results/DJI_0988_20_mask.png Просмотреть файл

Before After
Width: 5  |  Height: 11  |  Size: 132B

Двоичные данные
images/results/DJI_0996_104.jpg Просмотреть файл

Before After
Width: 3840  |  Height: 2160  |  Size: 2.7MB

Двоичные данные
images/results/DJI_20230626104206_0011_S_7.jpg Просмотреть файл

Before After
Width: 1920  |  Height: 1080  |  Size: 937KB

+ 0
- 0
images/results/DJI_20230626104206_0011_S_7.txt Просмотреть файл


Двоичные данные
images/results/DJI_20230626104206_0011_S_7_mask.png Просмотреть файл

Before After
Width: 5  |  Height: 10  |  Size: 126B

Двоичные данные
images/results/t1.jpg Просмотреть файл

Before After
Width: 800  |  Height: 524  |  Size: 275KB

Двоичные данные
images/results/t2.jpg Просмотреть файл

Before After
Width: 500  |  Height: 281  |  Size: 93KB

Двоичные данные
images/results/t3.jpg Просмотреть файл

Before After
Width: 800  |  Height: 449  |  Size: 283KB

Двоичные данные
images/results/t4.jpg Просмотреть файл

Before After
Width: 4000  |  Height: 2250  |  Size: 3.5MB

Двоичные данные
images/results/w1.jpg Просмотреть файл

Before After
Width: 1063  |  Height: 597  |  Size: 362KB

Двоичные данные
images/results/w2.jpg Просмотреть файл

Before After
Width: 1050  |  Height: 595  |  Size: 286KB

Двоичные данные
images/results/w3.jpg Просмотреть файл

Before After
Width: 1059  |  Height: 597  |  Size: 309KB

Двоичные данные
images/results/w4.jpg Просмотреть файл

Before After
Width: 1033  |  Height: 558  |  Size: 266KB

Загрузка…
Отмена
Сохранить