Kaynağa Gözat

add crowdCounting demo

master
wangjin0928 11 ay önce
ebeveyn
işleme
f152998111
29 değiştirilmiş dosya ile 115 ekleme ve 31 silme
  1. +54
    -2
      demo.py
  2. +54
    -29
      demo3.0.py
  3. BIN
      images/crowdCounting/t1.jpg
  4. BIN
      images/crowdCounting/t2.jpg
  5. BIN
      images/crowdCounting/t3.jpg
  6. BIN
      images/crowdCounting/t4.jpg
  7. BIN
      images/crowdCounting/w1.jpg
  8. BIN
      images/crowdCounting/w2.jpg
  9. BIN
      images/crowdCounting/w3.jpg
  10. BIN
      images/crowdCounting/w4.jpg
  11. BIN
      images/results/2023-09-19-09-46-46_frame-18507-18787_type_20230919094646113613-2-0-0_OR.jpg
  12. BIN
      images/results/DJI_0974_15.jpg
  13. +3
    -0
      images/results/DJI_0974_15.txt
  14. BIN
      images/results/DJI_0974_15_mask.png
  15. BIN
      images/results/DJI_0988_20.jpg
  16. +4
    -0
      images/results/DJI_0988_20.txt
  17. BIN
      images/results/DJI_0988_20_mask.png
  18. BIN
      images/results/DJI_0996_104.jpg
  19. BIN
      images/results/DJI_20230626104206_0011_S_7.jpg
  20. +0
    -0
      images/results/DJI_20230626104206_0011_S_7.txt
  21. BIN
      images/results/DJI_20230626104206_0011_S_7_mask.png
  22. BIN
      images/results/t1.jpg
  23. BIN
      images/results/t2.jpg
  24. BIN
      images/results/t3.jpg
  25. BIN
      images/results/t4.jpg
  26. BIN
      images/results/w1.jpg
  27. BIN
      images/results/w2.jpg
  28. BIN
      images/results/w3.jpg
  29. BIN
      images/results/w4.jpg

+ 54
- 2
demo.py Dosyayı Görüntüle

@@ -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 Dosyayı Görüntüle

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

BIN
images/crowdCounting/t1.jpg Dosyayı Görüntüle

Önce Sonra
Genişlik: 800  |  Yükseklik: 524  |  Boyut: 147KB

BIN
images/crowdCounting/t2.jpg Dosyayı Görüntüle

Önce Sonra
Genişlik: 500  |  Yükseklik: 281  |  Boyut: 41KB

BIN
images/crowdCounting/t3.jpg Dosyayı Görüntüle

Önce Sonra

BIN
images/crowdCounting/t4.jpg Dosyayı Görüntüle

Önce Sonra
Genişlik: 4000  |  Yükseklik: 2250  |  Boyut: 3.4MB

BIN
images/crowdCounting/w1.jpg Dosyayı Görüntüle

Önce Sonra
Genişlik: 1063  |  Yükseklik: 597  |  Boyut: 148KB

BIN
images/crowdCounting/w2.jpg Dosyayı Görüntüle

Önce Sonra
Genişlik: 1050  |  Yükseklik: 595  |  Boyut: 133KB

BIN
images/crowdCounting/w3.jpg Dosyayı Görüntüle

Önce Sonra
Genişlik: 1059  |  Yükseklik: 597  |  Boyut: 141KB

BIN
images/crowdCounting/w4.jpg Dosyayı Görüntüle

Önce Sonra
Genişlik: 1033  |  Yükseklik: 558  |  Boyut: 124KB

BIN
images/results/2023-09-19-09-46-46_frame-18507-18787_type_20230919094646113613-2-0-0_OR.jpg Dosyayı Görüntüle

Önce Sonra
Genişlik: 720  |  Yükseklik: 540  |  Boyut: 138KB

BIN
images/results/DJI_0974_15.jpg Dosyayı Görüntüle

Önce Sonra
Genişlik: 3840  |  Yükseklik: 2160  |  Boyut: 2.7MB

+ 3
- 0
images/results/DJI_0974_15.txt Dosyayı Görüntüle

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

BIN
images/results/DJI_0974_15_mask.png Dosyayı Görüntüle

Önce Sonra
Genişlik: 5  |  Yükseklik: 6  |  Boyut: 102B

BIN
images/results/DJI_0988_20.jpg Dosyayı Görüntüle

Önce Sonra
Genişlik: 3840  |  Yükseklik: 2160  |  Boyut: 2.0MB

+ 4
- 0
images/results/DJI_0988_20.txt Dosyayı Görüntüle

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

BIN
images/results/DJI_0988_20_mask.png Dosyayı Görüntüle

Önce Sonra
Genişlik: 5  |  Yükseklik: 11  |  Boyut: 132B

BIN
images/results/DJI_0996_104.jpg Dosyayı Görüntüle

Önce Sonra
Genişlik: 3840  |  Yükseklik: 2160  |  Boyut: 2.7MB

BIN
images/results/DJI_20230626104206_0011_S_7.jpg Dosyayı Görüntüle

Önce Sonra
Genişlik: 1920  |  Yükseklik: 1080  |  Boyut: 937KB

+ 0
- 0
images/results/DJI_20230626104206_0011_S_7.txt Dosyayı Görüntüle


BIN
images/results/DJI_20230626104206_0011_S_7_mask.png Dosyayı Görüntüle

Önce Sonra
Genişlik: 5  |  Yükseklik: 10  |  Boyut: 126B

BIN
images/results/t1.jpg Dosyayı Görüntüle

Önce Sonra
Genişlik: 800  |  Yükseklik: 524  |  Boyut: 275KB

BIN
images/results/t2.jpg Dosyayı Görüntüle

Önce Sonra
Genişlik: 500  |  Yükseklik: 281  |  Boyut: 93KB

BIN
images/results/t3.jpg Dosyayı Görüntüle

Önce Sonra
Genişlik: 800  |  Yükseklik: 449  |  Boyut: 283KB

BIN
images/results/t4.jpg Dosyayı Görüntüle

Önce Sonra
Genişlik: 4000  |  Yükseklik: 2250  |  Boyut: 3.5MB

BIN
images/results/w1.jpg Dosyayı Görüntüle

Önce Sonra
Genişlik: 1063  |  Yükseklik: 597  |  Boyut: 362KB

BIN
images/results/w2.jpg Dosyayı Görüntüle

Önce Sonra
Genişlik: 1050  |  Yükseklik: 595  |  Boyut: 286KB

BIN
images/results/w3.jpg Dosyayı Görüntüle

Önce Sonra
Genişlik: 1059  |  Yükseklik: 597  |  Boyut: 309KB

BIN
images/results/w4.jpg Dosyayı Görüntüle

Önce Sonra
Genişlik: 1033  |  Yükseklik: 558  |  Boyut: 266KB

Yükleniyor…
İptal
Kaydet