diff --git a/AI.py b/AI.py index 7bffa44..9fb0da2 100644 --- a/AI.py +++ b/AI.py @@ -18,6 +18,7 @@ import torch.nn.functional as F from copy import deepcopy from scipy import interpolate import glob +from loguru import logger def get_images_videos(impth, imageFixs=['.jpg','.JPG','.PNG','.png'],videoFixs=['.MP4','.mp4','.avi']): imgpaths=[];###获取文件里所有的图像 @@ -74,6 +75,17 @@ def score_filter_byClass(pdetections,score_para_2nd): if score > score_th: ret.append(det) return ret +# 按类过滤 +def filter_byClass(pdetections,allowedList): + ret=[] + for det in pdetections: + score,cls = det[4],det[5] + if int(cls) in allowedList: + ret.append(det) + elif str(int(cls)) in allowedList: + ret.append(det) + + return ret 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],'segRegionCnt':1, 'trtFlag_det':False,'trtFlag_seg':False,'score_byClass':{x:0.1 for x in range(30)} }, 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): @@ -118,13 +130,22 @@ def AI_process(im0s,model,segmodel,names,label_arraylist,rainbows,objectPar={ 'h img /= 255.0 time01=time.time() - - if segmodel: - seg_pred,segstr = segmodel.eval(im0s[0] ) - segFlag=True - else: - seg_pred = None;segFlag=False;segstr='Not implemented' - + if segmodel: + seg_pred, segstr = segmodel.eval(im0s[0]) + # 当不存在分割信息,无需做分类检测 + # segFlag = True + logger.info("分割信息seg_prd: {} 数据类型:{} ", seg_pred, np.count_nonzero(seg_pred)) + if not np.any(seg_pred != 0): + time_info = 'No SegMentInfo' + return [], time_info + + else: + # seg_pred = None; + # segFlag = False; + # segstr = 'Not implemented' + time_info = 'No SegMentInfo' + return [], time_info + time1=time.time() if trtFlag_det: pred = yolov5Trtforward(model,img) @@ -154,7 +175,8 @@ def AI_process(im0s,model,segmodel,names,label_arraylist,rainbows,objectPar={ 'h timeMixPost=':0 ms' #print('#### line121: segstr:%s timeMixPost:%s timeOut:%s'%( segstr.strip(), timeMixPost,timeOut )) time_info = 'letterbox:%.1f, seg:%.1f , infer:%.1f,%s, seginfo:%s ,timeMixPost:%s '%( (time01-time0)*1000, (time1-time01)*1000 ,(time2-time1)*1000,timeOut , segstr.strip(),timeMixPost ) - #if mode=='highWay3.0': + if allowedList: + p_result[2] = filter_byClass(p_result[2],allowedList) print('-'*10,p_result[2]) return p_result,time_info diff --git a/DMPRUtils/__pycache__/DMPR_process.cpython-38.pyc b/DMPRUtils/__pycache__/DMPR_process.cpython-38.pyc deleted file mode 100644 index 666e4cb..0000000 Binary files a/DMPRUtils/__pycache__/DMPR_process.cpython-38.pyc and /dev/null differ diff --git a/DMPRUtils/__pycache__/DMPR_process.cpython-39.pyc b/DMPRUtils/__pycache__/DMPR_process.cpython-39.pyc deleted file mode 100644 index e521b63..0000000 Binary files a/DMPRUtils/__pycache__/DMPR_process.cpython-39.pyc and /dev/null differ diff --git a/DMPRUtils/__pycache__/jointUtil.cpython-38.pyc b/DMPRUtils/__pycache__/jointUtil.cpython-38.pyc deleted file mode 100644 index e3f71cc..0000000 Binary files a/DMPRUtils/__pycache__/jointUtil.cpython-38.pyc and /dev/null differ diff --git a/DMPRUtils/__pycache__/yolo_net.cpython-38.pyc b/DMPRUtils/__pycache__/yolo_net.cpython-38.pyc deleted file mode 100644 index 6da6be9..0000000 Binary files a/DMPRUtils/__pycache__/yolo_net.cpython-38.pyc and /dev/null differ diff --git a/DMPRUtils/model/__pycache__/__init__.cpython-38.pyc b/DMPRUtils/model/__pycache__/__init__.cpython-38.pyc index a0de1d8..68f2e9a 100644 Binary files a/DMPRUtils/model/__pycache__/__init__.cpython-38.pyc and b/DMPRUtils/model/__pycache__/__init__.cpython-38.pyc differ diff --git a/DMPRUtils/model/__pycache__/detector.cpython-38.pyc b/DMPRUtils/model/__pycache__/detector.cpython-38.pyc index fd9a8da..a3e3b75 100644 Binary files a/DMPRUtils/model/__pycache__/detector.cpython-38.pyc and b/DMPRUtils/model/__pycache__/detector.cpython-38.pyc differ diff --git a/DMPRUtils/model/__pycache__/network.cpython-38.pyc b/DMPRUtils/model/__pycache__/network.cpython-38.pyc index 6b3f075..0d963e3 100644 Binary files a/DMPRUtils/model/__pycache__/network.cpython-38.pyc and b/DMPRUtils/model/__pycache__/network.cpython-38.pyc differ diff --git a/__pycache__/AI.cpython-38.pyc b/__pycache__/AI.cpython-38.pyc deleted file mode 100644 index f2b389a..0000000 Binary files a/__pycache__/AI.cpython-38.pyc and /dev/null differ diff --git a/__pycache__/DMPR.cpython-38.pyc b/__pycache__/DMPR.cpython-38.pyc deleted file mode 100644 index 7ee4b2f..0000000 Binary files a/__pycache__/DMPR.cpython-38.pyc and /dev/null differ diff --git a/__pycache__/crowd.cpython-38.pyc b/__pycache__/crowd.cpython-38.pyc deleted file mode 100644 index 0885d79..0000000 Binary files a/__pycache__/crowd.cpython-38.pyc and /dev/null differ diff --git a/__pycache__/ocr.cpython-38.pyc b/__pycache__/ocr.cpython-38.pyc deleted file mode 100644 index 3485300..0000000 Binary files a/__pycache__/ocr.cpython-38.pyc and /dev/null differ diff --git a/__pycache__/stdc.cpython-38.pyc b/__pycache__/stdc.cpython-38.pyc deleted file mode 100644 index 96e5f15..0000000 Binary files a/__pycache__/stdc.cpython-38.pyc and /dev/null differ diff --git a/__pycache__/yolov5.cpython-38.pyc b/__pycache__/yolov5.cpython-38.pyc deleted file mode 100644 index c4440e5..0000000 Binary files a/__pycache__/yolov5.cpython-38.pyc and /dev/null differ diff --git a/conf/highWayCthc/labelnames.json b/conf/highWayCthc/labelnames.json new file mode 100644 index 0000000..8f3726d --- /dev/null +++ b/conf/highWayCthc/labelnames.json @@ -0,0 +1,3 @@ +{ + "labelnames":["危化品","罐体","危险标识","普通车"] +} diff --git a/conf/highWayCthc/para.json b/conf/highWayCthc/para.json new file mode 100644 index 0000000..2bbe0cf --- /dev/null +++ b/conf/highWayCthc/para.json @@ -0,0 +1,3 @@ +{ + "post_process":{ "name":"post_process","conf_thres":0.88,"iou_thres":0.45,"classes":5,"rainbows":[ [0,0,255],[0,255,0],[255,0,0],[255,0,255],[255,255,0],[255,129,0],[255,0,127],[127,255,0],[0,255,127],[0,127,255],[127,0,255],[255,127,255],[255,255,127],[127,255,255],[0,255,255],[255,127,255],[127,255,255], [0,127,0],[0,0,127],[0,255,255]] } +} diff --git a/conf/highWaySpill/para.json b/conf/highWaySpill/para.json new file mode 100644 index 0000000..cbd4262 --- /dev/null +++ b/conf/highWaySpill/para.json @@ -0,0 +1,6 @@ +{ + "post_process":{ + "name":"post_process","conf_thres":0.5,"iou_thres":0.25,"classes":3, + "rainbows":[ [0,0,255],[0,255,0],[255,0,0],[255,0,0],[255,255,0],[255,0,0],[255,0,127],[255,0,0],[0,255,127],[0,127,255],[127,0,255],[255,127,255],[255,255,127],[127,255,255],[0,255,255],[255,127,255],[127,255,255], [0,127,0],[0,0,127],[0,255,255]] + } +} diff --git a/conf/infraredPerson/labelnames.json b/conf/infraredPerson/labelnames.json new file mode 100644 index 0000000..062ee2e --- /dev/null +++ b/conf/infraredPerson/labelnames.json @@ -0,0 +1,3 @@ +{ + "labelnames":["行人"] +} diff --git a/conf/infraredPerson/para.json b/conf/infraredPerson/para.json new file mode 100644 index 0000000..b53d470 --- /dev/null +++ b/conf/infraredPerson/para.json @@ -0,0 +1,7 @@ +{ + + + "post_process":{ "name":"post_process","conf_thres":0.25,"iou_thres":0.45,"classes":1,"rainbows":[ [0,0,255],[0,255,0],[255,0,0],[255,0,255],[255,255,0],[255,129,0],[255,0,127],[127,255,0],[0,255,127],[0,127,255],[127,0,255],[255,127,255],[255,255,127],[127,255,255],[0,255,255],[255,127,255],[127,255,255], [0,127,0],[0,0,127],[0,255,255]] } + + +} diff --git a/conf/infraredPerson/yolov5.pt b/conf/infraredPerson/yolov5.pt new file mode 100644 index 0000000..6affc16 Binary files /dev/null and b/conf/infraredPerson/yolov5.pt differ diff --git a/conf/nightFireSmoke/labelnames.json b/conf/nightFireSmoke/labelnames.json new file mode 100644 index 0000000..0429c7a --- /dev/null +++ b/conf/nightFireSmoke/labelnames.json @@ -0,0 +1,3 @@ +{ + "labelnames":["火","烟"] +} diff --git a/conf/nightFireSmoke/para.json b/conf/nightFireSmoke/para.json new file mode 100644 index 0000000..b53d470 --- /dev/null +++ b/conf/nightFireSmoke/para.json @@ -0,0 +1,7 @@ +{ + + + "post_process":{ "name":"post_process","conf_thres":0.25,"iou_thres":0.45,"classes":1,"rainbows":[ [0,0,255],[0,255,0],[255,0,0],[255,0,255],[255,255,0],[255,129,0],[255,0,127],[127,255,0],[0,255,127],[0,127,255],[127,0,255],[255,127,255],[255,255,127],[127,255,255],[0,255,255],[255,127,255],[127,255,255], [0,127,0],[0,0,127],[0,255,255]] } + + +} diff --git a/conf/nightFireSmoke/yolov5.pt b/conf/nightFireSmoke/yolov5.pt new file mode 100644 index 0000000..34d3b32 Binary files /dev/null and b/conf/nightFireSmoke/yolov5.pt differ diff --git a/conf/pannel/labelnames.json b/conf/pannel/labelnames.json new file mode 100644 index 0000000..0f17455 --- /dev/null +++ b/conf/pannel/labelnames.json @@ -0,0 +1,3 @@ +{ + "labelnames":[ "光伏板","覆盖物","裂缝" ] +} \ No newline at end of file diff --git a/conf/pannel/para.json b/conf/pannel/para.json new file mode 100644 index 0000000..ba3f563 --- /dev/null +++ b/conf/pannel/para.json @@ -0,0 +1,6 @@ +{ + "post_process":{ + "name":"post_process","conf_thres":0.5,"iou_thres":0.25,"classes":3, + "rainbows":[ [0,0,255],[0,255,0],[255,0,0],[255,0,0],[255,255,0],[255,0,0],[255,0,127],[255,0,0],[0,255,127],[0,127,255],[127,0,255],[255,127,255],[255,255,127],[127,255,255],[0,255,255],[255,127,255],[127,255,255], [0,127,0],[0,0,127],[0,255,255]] + } +} \ No newline at end of file diff --git a/crowdUtils/__pycache__/engine.cpython-38.pyc b/crowdUtils/__pycache__/engine.cpython-38.pyc deleted file mode 100644 index 3494fb8..0000000 Binary files a/crowdUtils/__pycache__/engine.cpython-38.pyc and /dev/null differ diff --git a/crowdUtils/__pycache__/engine.cpython-39.pyc b/crowdUtils/__pycache__/engine.cpython-39.pyc deleted file mode 100644 index b6924be..0000000 Binary files a/crowdUtils/__pycache__/engine.cpython-39.pyc and /dev/null differ diff --git a/models/__pycache__/__init__.cpython-37.pyc b/models/__pycache__/__init__.cpython-37.pyc deleted file mode 100644 index 2d10de3..0000000 Binary files a/models/__pycache__/__init__.cpython-37.pyc and /dev/null differ diff --git a/models/__pycache__/__init__.cpython-38.pyc b/models/__pycache__/__init__.cpython-38.pyc deleted file mode 100644 index 8e5a885..0000000 Binary files a/models/__pycache__/__init__.cpython-38.pyc and /dev/null differ diff --git a/models/__pycache__/common.cpython-37.pyc b/models/__pycache__/common.cpython-37.pyc deleted file mode 100644 index 8a36cab..0000000 Binary files a/models/__pycache__/common.cpython-37.pyc and /dev/null differ diff --git a/models/__pycache__/common.cpython-38.pyc b/models/__pycache__/common.cpython-38.pyc deleted file mode 100644 index 86d91ac..0000000 Binary files a/models/__pycache__/common.cpython-38.pyc and /dev/null differ diff --git a/models/__pycache__/experimental.cpython-37.pyc b/models/__pycache__/experimental.cpython-37.pyc deleted file mode 100644 index 75ca459..0000000 Binary files a/models/__pycache__/experimental.cpython-37.pyc and /dev/null differ diff --git a/models/__pycache__/experimental.cpython-38.pyc b/models/__pycache__/experimental.cpython-38.pyc deleted file mode 100644 index 2cd7482..0000000 Binary files a/models/__pycache__/experimental.cpython-38.pyc and /dev/null differ diff --git a/models/__pycache__/yolo.cpython-38.pyc b/models/__pycache__/yolo.cpython-38.pyc deleted file mode 100644 index 2ca764a..0000000 Binary files a/models/__pycache__/yolo.cpython-38.pyc and /dev/null differ diff --git a/obbUtils/__pycache__/__init__.cpython-38.pyc b/obbUtils/__pycache__/__init__.cpython-38.pyc deleted file mode 100644 index b05b9b4..0000000 Binary files a/obbUtils/__pycache__/__init__.cpython-38.pyc and /dev/null differ diff --git a/obbUtils/__pycache__/decoder.cpython-38.pyc b/obbUtils/__pycache__/decoder.cpython-38.pyc deleted file mode 100644 index 1a56eea..0000000 Binary files a/obbUtils/__pycache__/decoder.cpython-38.pyc and /dev/null differ diff --git a/obbUtils/__pycache__/func_utils.cpython-38.pyc b/obbUtils/__pycache__/func_utils.cpython-38.pyc deleted file mode 100644 index b0bafe9..0000000 Binary files a/obbUtils/__pycache__/func_utils.cpython-38.pyc and /dev/null differ diff --git a/obbUtils/__pycache__/load_obb_model.cpython-38.pyc b/obbUtils/__pycache__/load_obb_model.cpython-38.pyc deleted file mode 100644 index 426fa11..0000000 Binary files a/obbUtils/__pycache__/load_obb_model.cpython-38.pyc and /dev/null differ diff --git a/obbUtils/__pycache__/ocrTrt.cpython-38.pyc b/obbUtils/__pycache__/ocrTrt.cpython-38.pyc deleted file mode 100644 index 3c3c1ea..0000000 Binary files a/obbUtils/__pycache__/ocrTrt.cpython-38.pyc and /dev/null differ diff --git a/obbUtils/__pycache__/shipUtils.cpython-38.pyc b/obbUtils/__pycache__/shipUtils.cpython-38.pyc deleted file mode 100644 index 8a05aab..0000000 Binary files a/obbUtils/__pycache__/shipUtils.cpython-38.pyc and /dev/null differ diff --git a/obbUtils/obbmodels/__pycache__/ctrbox_net.cpython-38.pyc b/obbUtils/obbmodels/__pycache__/ctrbox_net.cpython-38.pyc index 98b988b..8ca8983 100644 Binary files a/obbUtils/obbmodels/__pycache__/ctrbox_net.cpython-38.pyc and b/obbUtils/obbmodels/__pycache__/ctrbox_net.cpython-38.pyc differ diff --git a/obbUtils/obbmodels/__pycache__/model_parts.cpython-38.pyc b/obbUtils/obbmodels/__pycache__/model_parts.cpython-38.pyc index 3dbe33e..07563ae 100644 Binary files a/obbUtils/obbmodels/__pycache__/model_parts.cpython-38.pyc and b/obbUtils/obbmodels/__pycache__/model_parts.cpython-38.pyc differ diff --git a/obbUtils/obbmodels/__pycache__/resnet.cpython-38.pyc b/obbUtils/obbmodels/__pycache__/resnet.cpython-38.pyc index 71b0dfe..9b9adb6 100644 Binary files a/obbUtils/obbmodels/__pycache__/resnet.cpython-38.pyc and b/obbUtils/obbmodels/__pycache__/resnet.cpython-38.pyc differ diff --git a/ocrUtils/__pycache__/ocrTrt.cpython-38.pyc b/ocrUtils/__pycache__/ocrTrt.cpython-38.pyc deleted file mode 100644 index 6ccbfdf..0000000 Binary files a/ocrUtils/__pycache__/ocrTrt.cpython-38.pyc and /dev/null differ diff --git a/ocrUtils/__pycache__/ocrUtils.cpython-38.pyc b/ocrUtils/__pycache__/ocrUtils.cpython-38.pyc deleted file mode 100644 index 1a2c8aa..0000000 Binary files a/ocrUtils/__pycache__/ocrUtils.cpython-38.pyc and /dev/null differ diff --git a/ocrUtils2/__pycache__/crnnCh.cpython-38.pyc b/ocrUtils2/__pycache__/crnnCh.cpython-38.pyc index c60e537..9c78153 100644 Binary files a/ocrUtils2/__pycache__/crnnCh.cpython-38.pyc and b/ocrUtils2/__pycache__/crnnCh.cpython-38.pyc differ diff --git a/ocrUtils2/__pycache__/ocrUtils.cpython-38.pyc b/ocrUtils2/__pycache__/ocrUtils.cpython-38.pyc index dab6f03..2be44f0 100644 Binary files a/ocrUtils2/__pycache__/ocrUtils.cpython-38.pyc and b/ocrUtils2/__pycache__/ocrUtils.cpython-38.pyc differ diff --git a/segutils/__pycache__/GPUtils.cpython-38.pyc b/segutils/__pycache__/GPUtils.cpython-38.pyc deleted file mode 100644 index 0873cfb..0000000 Binary files a/segutils/__pycache__/GPUtils.cpython-38.pyc and /dev/null differ diff --git a/segutils/__pycache__/model_stages.cpython-38.pyc b/segutils/__pycache__/model_stages.cpython-38.pyc deleted file mode 100644 index 8ee5c1c..0000000 Binary files a/segutils/__pycache__/model_stages.cpython-38.pyc and /dev/null differ diff --git a/segutils/__pycache__/segWaterBuilding.cpython-38.pyc b/segutils/__pycache__/segWaterBuilding.cpython-38.pyc deleted file mode 100644 index aa7c0c5..0000000 Binary files a/segutils/__pycache__/segWaterBuilding.cpython-38.pyc and /dev/null differ diff --git a/segutils/__pycache__/segmodel.cpython-38.pyc b/segutils/__pycache__/segmodel.cpython-38.pyc deleted file mode 100644 index 9270136..0000000 Binary files a/segutils/__pycache__/segmodel.cpython-38.pyc and /dev/null differ diff --git a/segutils/__pycache__/segmodel_trt.cpython-38.pyc b/segutils/__pycache__/segmodel_trt.cpython-38.pyc deleted file mode 100644 index 373ad6a..0000000 Binary files a/segutils/__pycache__/segmodel_trt.cpython-38.pyc and /dev/null differ diff --git a/segutils/__pycache__/stdcnet.cpython-38.pyc b/segutils/__pycache__/stdcnet.cpython-38.pyc deleted file mode 100644 index 8dc17a8..0000000 Binary files a/segutils/__pycache__/stdcnet.cpython-38.pyc and /dev/null differ diff --git a/segutils/__pycache__/trafficUtils.cpython-38.pyc b/segutils/__pycache__/trafficUtils.cpython-38.pyc deleted file mode 100644 index 92877f2..0000000 Binary files a/segutils/__pycache__/trafficUtils.cpython-38.pyc and /dev/null differ diff --git a/segutils/__pycache__/trtUtils.cpython-38.pyc b/segutils/__pycache__/trtUtils.cpython-38.pyc deleted file mode 100644 index c8855a4..0000000 Binary files a/segutils/__pycache__/trtUtils.cpython-38.pyc and /dev/null differ diff --git a/segutils/__pycache__/trtUtils2.cpython-38.pyc b/segutils/__pycache__/trtUtils2.cpython-38.pyc deleted file mode 100644 index 6324ee8..0000000 Binary files a/segutils/__pycache__/trtUtils2.cpython-38.pyc and /dev/null differ diff --git a/segutils/core/__pycache__/__init__.cpython-38.pyc b/segutils/core/__pycache__/__init__.cpython-38.pyc index 95ec37e..12ebadb 100644 Binary files a/segutils/core/__pycache__/__init__.cpython-38.pyc and b/segutils/core/__pycache__/__init__.cpython-38.pyc differ diff --git a/segutils/core/data/__pycache__/__init__.cpython-38.pyc b/segutils/core/data/__pycache__/__init__.cpython-38.pyc index f520d20..770421c 100644 Binary files a/segutils/core/data/__pycache__/__init__.cpython-38.pyc and b/segutils/core/data/__pycache__/__init__.cpython-38.pyc differ diff --git a/segutils/core/models/__pycache__/__init__.cpython-38.pyc b/segutils/core/models/__pycache__/__init__.cpython-38.pyc index 48ed7e1..f60b988 100644 Binary files a/segutils/core/models/__pycache__/__init__.cpython-38.pyc and b/segutils/core/models/__pycache__/__init__.cpython-38.pyc differ diff --git a/segutils/core/models/__pycache__/bisenet.cpython-38.pyc b/segutils/core/models/__pycache__/bisenet.cpython-38.pyc index dfcc199..8b262c9 100644 Binary files a/segutils/core/models/__pycache__/bisenet.cpython-38.pyc and b/segutils/core/models/__pycache__/bisenet.cpython-38.pyc differ diff --git a/segutils/core/models/__pycache__/ccnet.cpython-38.pyc b/segutils/core/models/__pycache__/ccnet.cpython-38.pyc index 867f289..bd8e8e6 100644 Binary files a/segutils/core/models/__pycache__/ccnet.cpython-38.pyc and b/segutils/core/models/__pycache__/ccnet.cpython-38.pyc differ diff --git a/segutils/core/models/__pycache__/cgnet.cpython-38.pyc b/segutils/core/models/__pycache__/cgnet.cpython-38.pyc index f31085c..afbb401 100644 Binary files a/segutils/core/models/__pycache__/cgnet.cpython-38.pyc and b/segutils/core/models/__pycache__/cgnet.cpython-38.pyc differ diff --git a/segutils/core/models/__pycache__/danet.cpython-38.pyc b/segutils/core/models/__pycache__/danet.cpython-38.pyc index ac98e12..39a8d6c 100644 Binary files a/segutils/core/models/__pycache__/danet.cpython-38.pyc and b/segutils/core/models/__pycache__/danet.cpython-38.pyc differ diff --git a/segutils/core/models/__pycache__/deeplabv3.cpython-38.pyc b/segutils/core/models/__pycache__/deeplabv3.cpython-38.pyc index ac74b1c..ceb25f6 100644 Binary files a/segutils/core/models/__pycache__/deeplabv3.cpython-38.pyc and b/segutils/core/models/__pycache__/deeplabv3.cpython-38.pyc differ diff --git a/segutils/core/models/__pycache__/deeplabv3_plus.cpython-38.pyc b/segutils/core/models/__pycache__/deeplabv3_plus.cpython-38.pyc index 8fa10cd..aef1c3d 100644 Binary files a/segutils/core/models/__pycache__/deeplabv3_plus.cpython-38.pyc and b/segutils/core/models/__pycache__/deeplabv3_plus.cpython-38.pyc differ diff --git a/segutils/core/models/__pycache__/denseaspp.cpython-38.pyc b/segutils/core/models/__pycache__/denseaspp.cpython-38.pyc index db1cc0a..27daf14 100644 Binary files a/segutils/core/models/__pycache__/denseaspp.cpython-38.pyc and b/segutils/core/models/__pycache__/denseaspp.cpython-38.pyc differ diff --git a/segutils/core/models/__pycache__/dfanet.cpython-38.pyc b/segutils/core/models/__pycache__/dfanet.cpython-38.pyc index f5e5e5d..b00ea43 100644 Binary files a/segutils/core/models/__pycache__/dfanet.cpython-38.pyc and b/segutils/core/models/__pycache__/dfanet.cpython-38.pyc differ diff --git a/segutils/core/models/__pycache__/dinknet.cpython-38.pyc b/segutils/core/models/__pycache__/dinknet.cpython-38.pyc index cb57b1e..2b9b6b6 100644 Binary files a/segutils/core/models/__pycache__/dinknet.cpython-38.pyc and b/segutils/core/models/__pycache__/dinknet.cpython-38.pyc differ diff --git a/segutils/core/models/__pycache__/dunet.cpython-38.pyc b/segutils/core/models/__pycache__/dunet.cpython-38.pyc index 046e32c..26aa9a6 100644 Binary files a/segutils/core/models/__pycache__/dunet.cpython-38.pyc and b/segutils/core/models/__pycache__/dunet.cpython-38.pyc differ diff --git a/segutils/core/models/__pycache__/encnet.cpython-38.pyc b/segutils/core/models/__pycache__/encnet.cpython-38.pyc index 53233c5..807982b 100644 Binary files a/segutils/core/models/__pycache__/encnet.cpython-38.pyc and b/segutils/core/models/__pycache__/encnet.cpython-38.pyc differ diff --git a/segutils/core/models/__pycache__/enet.cpython-38.pyc b/segutils/core/models/__pycache__/enet.cpython-38.pyc index 0ba49ab..1067596 100644 Binary files a/segutils/core/models/__pycache__/enet.cpython-38.pyc and b/segutils/core/models/__pycache__/enet.cpython-38.pyc differ diff --git a/segutils/core/models/__pycache__/espnet.cpython-38.pyc b/segutils/core/models/__pycache__/espnet.cpython-38.pyc index 492ed6a..e32d5ba 100644 Binary files a/segutils/core/models/__pycache__/espnet.cpython-38.pyc and b/segutils/core/models/__pycache__/espnet.cpython-38.pyc differ diff --git a/segutils/core/models/__pycache__/fcn.cpython-38.pyc b/segutils/core/models/__pycache__/fcn.cpython-38.pyc index 29bfa09..28b5a1c 100644 Binary files a/segutils/core/models/__pycache__/fcn.cpython-38.pyc and b/segutils/core/models/__pycache__/fcn.cpython-38.pyc differ diff --git a/segutils/core/models/__pycache__/fcnv2.cpython-38.pyc b/segutils/core/models/__pycache__/fcnv2.cpython-38.pyc index 7e72276..e59cf69 100644 Binary files a/segutils/core/models/__pycache__/fcnv2.cpython-38.pyc and b/segutils/core/models/__pycache__/fcnv2.cpython-38.pyc differ diff --git a/segutils/core/models/__pycache__/icnet.cpython-38.pyc b/segutils/core/models/__pycache__/icnet.cpython-38.pyc index 6cff1a7..bac24f1 100644 Binary files a/segutils/core/models/__pycache__/icnet.cpython-38.pyc and b/segutils/core/models/__pycache__/icnet.cpython-38.pyc differ diff --git a/segutils/core/models/__pycache__/lednet.cpython-38.pyc b/segutils/core/models/__pycache__/lednet.cpython-38.pyc index 1de43b8..0535d57 100644 Binary files a/segutils/core/models/__pycache__/lednet.cpython-38.pyc and b/segutils/core/models/__pycache__/lednet.cpython-38.pyc differ diff --git a/segutils/core/models/__pycache__/model_zoo.cpython-38.pyc b/segutils/core/models/__pycache__/model_zoo.cpython-38.pyc index ba15c98..e7a0aed 100644 Binary files a/segutils/core/models/__pycache__/model_zoo.cpython-38.pyc and b/segutils/core/models/__pycache__/model_zoo.cpython-38.pyc differ diff --git a/segutils/core/models/__pycache__/ocnet.cpython-38.pyc b/segutils/core/models/__pycache__/ocnet.cpython-38.pyc index b8d2497..637de94 100644 Binary files a/segutils/core/models/__pycache__/ocnet.cpython-38.pyc and b/segutils/core/models/__pycache__/ocnet.cpython-38.pyc differ diff --git a/segutils/core/models/__pycache__/psanet.cpython-38.pyc b/segutils/core/models/__pycache__/psanet.cpython-38.pyc index 8a6ec15..79b8b0f 100644 Binary files a/segutils/core/models/__pycache__/psanet.cpython-38.pyc and b/segutils/core/models/__pycache__/psanet.cpython-38.pyc differ diff --git a/segutils/core/models/__pycache__/pspnet.cpython-38.pyc b/segutils/core/models/__pycache__/pspnet.cpython-38.pyc index e27b922..2aa538f 100644 Binary files a/segutils/core/models/__pycache__/pspnet.cpython-38.pyc and b/segutils/core/models/__pycache__/pspnet.cpython-38.pyc differ diff --git a/segutils/core/models/__pycache__/segbase.cpython-38.pyc b/segutils/core/models/__pycache__/segbase.cpython-38.pyc index 3d4c0fc..fcb58d9 100644 Binary files a/segutils/core/models/__pycache__/segbase.cpython-38.pyc and b/segutils/core/models/__pycache__/segbase.cpython-38.pyc differ diff --git a/segutils/core/models/base_models/__pycache__/__init__.cpython-38.pyc b/segutils/core/models/base_models/__pycache__/__init__.cpython-38.pyc index e5ae56e..808fa12 100644 Binary files a/segutils/core/models/base_models/__pycache__/__init__.cpython-38.pyc and b/segutils/core/models/base_models/__pycache__/__init__.cpython-38.pyc differ diff --git a/segutils/core/models/base_models/__pycache__/densenet.cpython-38.pyc b/segutils/core/models/base_models/__pycache__/densenet.cpython-38.pyc index 7573364..6affddd 100644 Binary files a/segutils/core/models/base_models/__pycache__/densenet.cpython-38.pyc and b/segutils/core/models/base_models/__pycache__/densenet.cpython-38.pyc differ diff --git a/segutils/core/models/base_models/__pycache__/eespnet.cpython-38.pyc b/segutils/core/models/base_models/__pycache__/eespnet.cpython-38.pyc index d176152..5a65a91 100644 Binary files a/segutils/core/models/base_models/__pycache__/eespnet.cpython-38.pyc and b/segutils/core/models/base_models/__pycache__/eespnet.cpython-38.pyc differ diff --git a/segutils/core/models/base_models/__pycache__/resnet.cpython-38.pyc b/segutils/core/models/base_models/__pycache__/resnet.cpython-38.pyc index eef4340..56da0a9 100644 Binary files a/segutils/core/models/base_models/__pycache__/resnet.cpython-38.pyc and b/segutils/core/models/base_models/__pycache__/resnet.cpython-38.pyc differ diff --git a/segutils/core/models/base_models/__pycache__/resnetv1b.cpython-38.pyc b/segutils/core/models/base_models/__pycache__/resnetv1b.cpython-38.pyc index 2ff0e2b..3275899 100644 Binary files a/segutils/core/models/base_models/__pycache__/resnetv1b.cpython-38.pyc and b/segutils/core/models/base_models/__pycache__/resnetv1b.cpython-38.pyc differ diff --git a/segutils/core/models/base_models/__pycache__/vgg.cpython-38.pyc b/segutils/core/models/base_models/__pycache__/vgg.cpython-38.pyc index 0b17313..94a13b4 100644 Binary files a/segutils/core/models/base_models/__pycache__/vgg.cpython-38.pyc and b/segutils/core/models/base_models/__pycache__/vgg.cpython-38.pyc differ diff --git a/segutils/core/models/base_models/__pycache__/xception.cpython-38.pyc b/segutils/core/models/base_models/__pycache__/xception.cpython-38.pyc index 4ce0ab5..26e6aca 100644 Binary files a/segutils/core/models/base_models/__pycache__/xception.cpython-38.pyc and b/segutils/core/models/base_models/__pycache__/xception.cpython-38.pyc differ diff --git a/segutils/core/nn/__pycache__/__init__.cpython-38.pyc b/segutils/core/nn/__pycache__/__init__.cpython-38.pyc index 47509c0..1e5a396 100644 Binary files a/segutils/core/nn/__pycache__/__init__.cpython-38.pyc and b/segutils/core/nn/__pycache__/__init__.cpython-38.pyc differ diff --git a/segutils/core/nn/__pycache__/basic.cpython-38.pyc b/segutils/core/nn/__pycache__/basic.cpython-38.pyc index 2dbe948..6e19e45 100644 Binary files a/segutils/core/nn/__pycache__/basic.cpython-38.pyc and b/segutils/core/nn/__pycache__/basic.cpython-38.pyc differ diff --git a/segutils/core/nn/__pycache__/ca_block.cpython-38.pyc b/segutils/core/nn/__pycache__/ca_block.cpython-38.pyc index c82438d..a9deb03 100644 Binary files a/segutils/core/nn/__pycache__/ca_block.cpython-38.pyc and b/segutils/core/nn/__pycache__/ca_block.cpython-38.pyc differ diff --git a/segutils/core/nn/__pycache__/jpu.cpython-38.pyc b/segutils/core/nn/__pycache__/jpu.cpython-38.pyc index d96afae..60d837d 100644 Binary files a/segutils/core/nn/__pycache__/jpu.cpython-38.pyc and b/segutils/core/nn/__pycache__/jpu.cpython-38.pyc differ diff --git a/segutils/core/nn/__pycache__/psa_block.cpython-38.pyc b/segutils/core/nn/__pycache__/psa_block.cpython-38.pyc index c3340e7..7f31a1d 100644 Binary files a/segutils/core/nn/__pycache__/psa_block.cpython-38.pyc and b/segutils/core/nn/__pycache__/psa_block.cpython-38.pyc differ diff --git a/segutils/core/utils/__pycache__/__init__.cpython-38.pyc b/segutils/core/utils/__pycache__/__init__.cpython-38.pyc index 85dca56..8364a79 100644 Binary files a/segutils/core/utils/__pycache__/__init__.cpython-38.pyc and b/segutils/core/utils/__pycache__/__init__.cpython-38.pyc differ diff --git a/segutils/core/utils/__pycache__/download.cpython-38.pyc b/segutils/core/utils/__pycache__/download.cpython-38.pyc index 2c538fe..c21f1cc 100644 Binary files a/segutils/core/utils/__pycache__/download.cpython-38.pyc and b/segutils/core/utils/__pycache__/download.cpython-38.pyc differ diff --git a/segutils/core/utils/__pycache__/filesystem.cpython-38.pyc b/segutils/core/utils/__pycache__/filesystem.cpython-38.pyc index 2684129..d667caf 100644 Binary files a/segutils/core/utils/__pycache__/filesystem.cpython-38.pyc and b/segutils/core/utils/__pycache__/filesystem.cpython-38.pyc differ diff --git a/segutils/trafficUtils.py b/segutils/trafficUtils.py index 7f60249..4495431 100644 --- a/segutils/trafficUtils.py +++ b/segutils/trafficUtils.py @@ -1,520 +1,520 @@ -# 设定开关,将最小外接矩形中心点间的距离作为vehicle之间的距离 -import numpy as np -import math, cv2, time -from copy import deepcopy - -def get_ms(time2, time1): - return (time2 - time1) * 1000.0 - - -def two_points_distance(x1, y1, x2, y2): - distance = math.sqrt((x1 - x2) ** 2 + (y1 - y2) ** 2) - return distance - - -# 保存正常vehicle和非正常vehicle的信息(当contours顶点数小于6时,无法拟合最小外接矩形,定义为非正常vehicle) -def saveVehicle1(traffic_dict, contours, normVehicleBD, normVehicle, count, i, unnormVehicle, normVehicleCOOR): - if len(contours) >= 6: - normVehicleBD.append(contours) - normVehicle.append(traffic_dict['det'][count]) - rect = cv2.minAreaRect(contours) - normVehicleCOOR.append(rect[0]) - else: - traffic_dict['det'][int(i / 2)] = traffic_dict['det'][int(i / 2)] + [0, 0.3, 999, -1, 3] - unnormVehicle.append(traffic_dict['det'][int(i / 2)]) - return normVehicleBD, normVehicle, unnormVehicle, normVehicleCOOR - - -# saveVehicle2和saveVehicle1有区别 -def saveVehicle2(traffic_dict, contours, normVehicleBD, normVehicle, count, i, unnormVehicle, normVehicleCOOR, centerCOOR): - if len(contours) >= 6: - normVehicleBD.append(contours) - normVehicle.append(traffic_dict['det'][count]) - normVehicleCOOR.append(centerCOOR) - else: - traffic_dict['det'][int(i / 2)] = traffic_dict['det'][int(i / 2)] + [0, 0.3, 999, -1, 3] - unnormVehicle.append(traffic_dict['det'][int(i / 2)]) - return normVehicleBD, normVehicle, unnormVehicle, normVehicleCOOR - - -# 对于不在道路上的vehicle,将输出信息补全 -def supplementInformation(traffic_dict, i, roundness, y_min, y_max, imgVehicle, rect): - score = -1 - traffic_dict['det'][i] = traffic_dict['det'][i] + [0, roundness, 999, [-1, -1, -1], 666] - if y_min > 0 and y_max < imgVehicle.shape[0] and roundness > traffic_dict['roundness']: # 过滤掉上下方被speedRoad的边界截断的vehicle - score = (min(rect[1]) - max(rect[1]) * traffic_dict['roundness']) / (max(rect[1]) * (1 - traffic_dict['roundness'])) - return score - - -# 判断交通事故类型 -def judgeAccidentType(traffic_dict, b): - if max(traffic_dict['det'][b][9]) == traffic_dict['det'][b][9][0] and traffic_dict['det'][b][9][0] != -1: - return 0 - elif max(traffic_dict['det'][b][9]) == traffic_dict['det'][b][9][1] and traffic_dict['det'][b][9][1] != -1: - return 1 - elif max(traffic_dict['det'][b][9]) == traffic_dict['det'][b][9][2] and traffic_dict['det'][b][9][2] != -1: - return 2 - else: - return 3 - - -# 计算距离得分 -def distanceScore(vehicleWH, index1, index2, smallestDistance, traffic_dict): - d1 = (min(vehicleWH[index1]) + min(vehicleWH[index2])) / 2 - d2 = min(min(vehicleWH[index1]), min(vehicleWH[index2])) + max(min(vehicleWH[index1]), min(vehicleWH[index2])) / 2 - if smallestDistance == d1: - score1 = 1 - traffic_dict['det'][index2][9][2] = score1 - traffic_dict['det'][index2][10] = judgeAccidentType(traffic_dict, index2) - elif smallestDistance < d2: - score1 = 1 - (smallestDistance - d1) / (d2 - d1) - if 0 < score1 < 1: - traffic_dict['det'][index2][9][2] = score1 - traffic_dict['det'][index2][10] = judgeAccidentType(traffic_dict, index2) - else: - traffic_dict['det'][index2][10] = judgeAccidentType(traffic_dict, index2) - else: - traffic_dict['det'][index2][10] = judgeAccidentType(traffic_dict, index2) - return traffic_dict['det'] - - -# 计算两个contours之间的最短距离 -def array_distance(arr1, arr2): - ''' - 计算两个数组中,每任意两个点之间L2距离 - arr1和arr2都必须是numpy数组 - 且维度分别是mx2,nx2 - 输出数组维度为mxn - ''' - m, _ = arr1.shape - n, _ = arr2.shape - arr1_power = np.power(arr1, 2) - arr1_power_sum = arr1_power[:, 0] + arr1_power[:, 1] # 第1区域,x与y的平方和 - arr1_power_sum = np.tile(arr1_power_sum, (n, 1)) # 将arr1_power_sum沿着y轴复制n倍,沿着x轴复制1倍,这里用于与arr2进行计算。 n x m 维度 - arr1_power_sum = arr1_power_sum.T # 将arr1_power_sum进行转置 - arr2_power = np.power(arr2, 2) - arr2_power_sum = arr2_power[:, 0] + arr2_power[:, 1] # 第2区域,x与y的平方和 - arr2_power_sum = np.tile(arr2_power_sum, (m, 1)) # 将arr1_power_sum沿着y轴复制m倍,沿着x轴复制1倍,这里用于与arr1进行计算。 m x n 维度 - dis = arr1_power_sum + arr2_power_sum - (2 * np.dot(arr1, arr2.T)) # np.dot(arr1, arr2.T)矩阵相乘,得到xy的值。 - dis = np.sqrt(dis) - return dis - - -# 存储所有道路的信息 -def storageRoad(contours, allRoadContent, traffic_dict): - speedRoadAngle = 0 - for cnt in contours: # 道路 - rect = cv2.minAreaRect(cnt) - if rect[1][0] * rect[1][1] > traffic_dict['RoadArea']: # 过滤掉面积小于阈值的speedRoad - if rect[1][0] <= rect[1][1]: - if rect[2] >= 0 and rect[2] < 90: - speedRoadAngle = rect[2] + 90 - elif rect[2] == 90: - speedRoadAngle = 0 - else: - if rect[2] >= 0 and rect[2] <= 90: - speedRoadAngle = rect[2] - allRoadContent.append([cnt, speedRoadAngle, rect[1]]) - return allRoadContent - - -# 存储所有vehicle的信息,方法1 -def storageVehicle1(traffic_dict, normVehicleBD, normVehicle, unnormVehicle, normVehicleCOOR, imgVehicle): - #输入: - # - #输出:traffic_dict['det'], normVehicleBD, unnormVehicle, normVehicleCOOR - # traffic_dict['det']:resize缩小之后的坐标,类别,得分.[cls,x0,y0,x1,y1,score] - - # normVehicleBD : 正常车辆的contours。(正常车辆指的是countrous定点数>=6) - # unnormVehicle : resize缩小之后的异常车辆坐标,类别,得分.[cls,x0,y0,x1,y1,score] - count = 0 - for i in range(0, len(traffic_dict['vehicleCOOR']), 2): - mask = np.zeros(imgVehicle.shape[:2], dtype="uint8") - x0 = int(traffic_dict['vehicleCOOR'][i][0] * traffic_dict['ZoomFactor']['y']) - y0 = int(traffic_dict['vehicleCOOR'][i][1] * traffic_dict['ZoomFactor']['x']) - x1 = int(traffic_dict['vehicleCOOR'][i + 1][0] * traffic_dict['ZoomFactor']['y']) - y1 = int(traffic_dict['vehicleCOOR'][i + 1][1] * traffic_dict['ZoomFactor']['x']) - cv2.rectangle(mask, (x0, y0), (x1, y1), 255, -1, lineType=cv2.LINE_AA) - imgVehicle_masked = cv2.bitwise_and(imgVehicle, imgVehicle, mask=mask) - img2 = cv2.cvtColor(imgVehicle_masked, cv2.COLOR_BGR2GRAY) - contours2, hierarchy2 = cv2.findContours(img2, cv2.RETR_EXTERNAL, cv2.CHAIN_APPROX_NONE) - if len(contours2) != 0: - if len(contours2) > 1: # 这里我通过比较同一检测框内各个contours对应的最小外接矩形的面积,来剔除那些存在干扰的contours,最终只保留一个contours - vehicleArea = [] # 存储vehicle的最小外接矩形的面积 - for j in range(len(contours2)): - rect = cv2.minAreaRect(contours2[j]) - vehicleArea.append(rect[1][0] * rect[1][1]) - maxAreaIndex = vehicleArea.index(max(vehicleArea)) - maxAreaContours = contours2[maxAreaIndex] - normVehicleBD, normVehicle, unnormVehicle, normVehicleCOOR = saveVehicle1(traffic_dict,maxAreaContours,normVehicleBD,normVehicle,count,i,unnormVehicle, normVehicleCOOR) - elif len(contours2) == 1: - normVehicleBD, normVehicle, unnormVehicle, normVehicleCOOR = saveVehicle1(traffic_dict,contours2[0],normVehicleBD,normVehicle,count,i,unnormVehicle, normVehicleCOOR) - else: - traffic_dict['det'][int(i / 2)] = traffic_dict['det'][int(i / 2)] + [0, 0.3, 999, -1, 3] - unnormVehicle.append(traffic_dict['det'][int(i / 2)]) - count += 1 - traffic_dict['det'] = normVehicle - return traffic_dict['det'], normVehicleBD, unnormVehicle, normVehicleCOOR - - -# 存储所有vehicle的信息,方法2 -def storageVehicle2(traffic_dict, normVehicleBD, normVehicle, unnormVehicle, normVehicleCOOR, imgVehicle): - img = cv2.cvtColor(imgVehicle, cv2.COLOR_BGR2GRAY) - count = 0 - for i in range(0, len(traffic_dict['vehicleCOOR']), 2): - row1 = int(traffic_dict['vehicleCOOR'][i][1] * traffic_dict['ZoomFactor']['x']) - row2 = int(traffic_dict['vehicleCOOR'][i + 1][1] * traffic_dict['ZoomFactor']['x']) - col1 = int(traffic_dict['vehicleCOOR'][i][0] * traffic_dict['ZoomFactor']['y']) - col2 = int(traffic_dict['vehicleCOOR'][i + 1][0] * traffic_dict['ZoomFactor']['y']) - - if row1 >= 2: - row1 = row1 - 2 - if row2 <= (traffic_dict['modelSize'][1] - 2): - row2 = row2 + 2 - if col1 >= 2: - col1 = col1 - 2 - if col2 <= (traffic_dict['modelSize'][0] - 2): - col2 = col2 + 2 - centerCOOR = (int((col1 + col2) / 2), int((row1 + row2) / 2)) - img1 = img[row1:row2, col1:col2] - up = np.zeros((20, (col2 - col1)), dtype='uint8') - left = np.zeros(((40 + row2 - row1), 20), dtype='uint8') - - img1 = np.concatenate((up, img1), axis=0) - img1 = np.concatenate((img1, up), axis=0) - - img1 = np.concatenate((left, img1), axis=1) - img2 = np.concatenate((img1, left), axis=1) - contours2, hierarchy = cv2.findContours(img2, cv2.RETR_EXTERNAL, cv2.CHAIN_APPROX_NONE) - if len(contours2) != 0: - if len(contours2) > 1: - vehicleArea = [] # 存储vehicle的最小外接矩形的面积 - for j in range(len(contours2)): - rect = cv2.minAreaRect(contours2[j]) - vehicleArea.append(rect[1][0] * rect[1][1]) - maxAreaIndex = vehicleArea.index(max(vehicleArea)) - maxAreaContours = contours2[maxAreaIndex] - normVehicleBD, normVehicle, unnormVehicle, normVehicleCOOR = saveVehicle2(traffic_dict,maxAreaContours,normVehicleBD,normVehicle,count,i,unnormVehicle,normVehicleCOOR,centerCOOR) - elif len(contours2) == 1: - normVehicleBD, normVehicle, unnormVehicle, normVehicleCOOR = saveVehicle2(traffic_dict,contours2[0],normVehicleBD,normVehicle,count,i,unnormVehicle,normVehicleCOOR,centerCOOR) - else: - traffic_dict['det'][int(i / 2)] = traffic_dict['det'][int(i / 2)] + [0, 0.3, 999, -1, 3] - unnormVehicle.append(traffic_dict['det'][int(i / 2)]) - count += 1 - traffic_dict['det'] = normVehicle - return traffic_dict['det'], normVehicleBD, unnormVehicle, normVehicleCOOR - - -# 计算角度和长宽比得分 -def angleRoundness(normVehicleBD, vehicleBox, vehicleWH, allRoadContent, traffic_dict, normVehicleCOOR, imgVehicle): - ##输出:vehicleBox, vehicleWH, traffic_dict['det'] - # vehicleBox--正常车辆通过contours得出的box,[ (x0,y0),(x1,y1),(x2,y2),(x3,y3)] - # vehicleWH--正常车辆通过contours得出的box,[ (w,h)] - # traffic_dict['det']--[[cls, x0, y0, x1, y1, score, 角度, 长宽比, 最小距离, max([角度得分, 长宽比得分, 最小距离得分]), 交通事故类别], ...] - for i in range(len(normVehicleBD)): - ellipse = cv2.fitEllipse(normVehicleBD[i]) - vehicleAngle = 0 - if ellipse[2] >= 0 and ellipse[2] < 90: - vehicleAngle = 90 + ellipse[2] - elif ellipse[2] >= 90 and ellipse[2] < 180: - vehicleAngle = ellipse[2] - 90 - elif ellipse[2] == 180: - vehicleAngle = 90 - rect = cv2.minAreaRect(normVehicleBD[i]) - box = cv2.boxPoints(rect).astype(np.int32) - center = normVehicleCOOR[i] - vehicleBox.append(box) - vehicleWH.append(rect[1]) - roundness = min(rect[1]) / max(rect[1]) - y_min = np.min(box[:, 1]) - y_max = np.max(box[:, 1]) - if len(allRoadContent) != 0: - for j in range(len(allRoadContent)): - flag = cv2.pointPolygonTest(allRoadContent[j][0], center, False) - if flag >= 0: - roadVehicleAngle = abs(vehicleAngle - allRoadContent[j][1]) - traffic_dict['det'][i] = traffic_dict['det'][i] + [roadVehicleAngle, roundness, 999, [-1, -1, -1], 666] - if y_min > 0 and y_max < imgVehicle.shape[0]: # 过滤掉上下方被speedRoad的边界截断的vehicle - if roadVehicleAngle >= traffic_dict['roadVehicleAngle']: # 当道路同水平方向的夹角与车辆同水平方向的夹角的差值在15°和75°之间时,需要将车辆框出来 - if roadVehicleAngle > 90: - score1 = float((180 - roadVehicleAngle) / 90) - else: - score1 = float(roadVehicleAngle / 90) - traffic_dict['det'][i][9][0] = score1 - if roundness > traffic_dict['roundness']: - score2 = (min(rect[1]) - max(rect[1]) * traffic_dict['roundness']) / (max(rect[1]) * (1 - traffic_dict['roundness'])) - traffic_dict['det'][i][9][1] = score2 - break - else: - j += 1 - if len(traffic_dict['det'][i]) == 6: - traffic_dict['det'][i][9][1] = supplementInformation(traffic_dict, i, roundness, y_min, y_max, imgVehicle, rect) - else: - traffic_dict['det'][i][9][1] = supplementInformation(traffic_dict, i, roundness, y_min, y_max, imgVehicle, rect) - i += 1 - return vehicleBox, vehicleWH, traffic_dict['det'] - - -# 对于某一vehicle,以该vehicle的最小外接矩形的中心点为圆心O1,划定半径范围,求O1与半径范围内的其他vehicle的中心点之间的距离 -def vehicleDistance1(normVehicleCOOR, normVehicleBD, traffic_dict, vehicleWH): - if len(normVehicleCOOR) > 1: - for b in range(len(normVehicleCOOR)): - contoursMinDistance = [] # 存储contours之间的最短距离 - tmp = normVehicleCOOR[b] - normVehicleCOOR[b] = normVehicleCOOR[0] - normVehicleCOOR[0] = tmp - targetContours = [] # 存储目标vehicle和中心点同目标车辆中心点之间的距离小于traffic_dict['radius']的vehicle的box - for c in range(1, len(normVehicleCOOR)): - if two_points_distance(normVehicleCOOR[0][0], normVehicleCOOR[0][1], normVehicleCOOR[c][0], normVehicleCOOR[c][1]) <= traffic_dict['radius']: - if normVehicleBD[b] not in targetContours: - targetContours.append(normVehicleBD[b]) - if c == b: - targetContours.append(normVehicleBD[0]) - else: - targetContours.append(normVehicleBD[c]) - if len(targetContours) != 0: - goalVehicleContour = np.squeeze(targetContours[0], 1) - for d in range(1, len(targetContours)): - elseVehicleContour = np.squeeze(targetContours[d], 1) - dist_arr = array_distance(goalVehicleContour, elseVehicleContour) - min_dist = dist_arr[dist_arr > 0].min() - contoursMinDistance.append(min_dist) - traffic_dict['det'][b][8] = min(contoursMinDistance) - if traffic_dict['det'][b][8] < min(vehicleWH[b]) * traffic_dict['vehicleFactor']: - score1 = 1 - traffic_dict['det'][b][8] / (min(vehicleWH[b]) * traffic_dict['vehicleFactor']) - traffic_dict['det'][b][9][2] = score1 - traffic_dict['det'][b][10] = judgeAccidentType(traffic_dict, b) - else: - traffic_dict['det'][b][8] = 999 - traffic_dict['det'][b][10] = judgeAccidentType(traffic_dict, b) - tmp = normVehicleCOOR[b] - normVehicleCOOR[b] = normVehicleCOOR[0] - normVehicleCOOR[0] = tmp - else: # 路上只有一辆车 - if max(traffic_dict['det'][0][9]) == traffic_dict['det'][0][9][0] and traffic_dict['det'][0][9][0] != -1: - traffic_dict['det'][0][10] = 0 - elif max(traffic_dict['det'][0][9]) == traffic_dict['det'][0][9][1] and traffic_dict['det'][0][9][1] != -1: - traffic_dict['det'][0][10] = 1 - else: - traffic_dict['det'][0][10] = 3 - return traffic_dict['det'] - - -# 计算vehicle的最小外接矩形中心点之间的距离和距离得分 -def vehicleDistance2(normVehicleCOOR, traffic_dict, vehicleWH): - if len(normVehicleCOOR) > 1: # 有多辆车 - for b in range(len(normVehicleCOOR)): - centerDistance = [] # 存储contours之间的最短距离 - tmp = normVehicleCOOR[b] - normVehicleCOOR[b] = normVehicleCOOR[0] - normVehicleCOOR[0] = tmp - for c in range(1, len(normVehicleCOOR)): - centerDistance.append(two_points_distance(normVehicleCOOR[0][0], normVehicleCOOR[0][1], normVehicleCOOR[c][0], normVehicleCOOR[c][1])) - smallestDistance = min(centerDistance) - index = centerDistance.index(smallestDistance) - traffic_dict['det'][b][8] = smallestDistance - if index == b - 1: # 序号0和b对应的vehicle - traffic_dict['det'] = distanceScore(vehicleWH, 0, b, smallestDistance, traffic_dict) - else: - traffic_dict['det'] = distanceScore(vehicleWH, index+1, b, smallestDistance, traffic_dict) - tmp = normVehicleCOOR[b] - normVehicleCOOR[b] = normVehicleCOOR[0] - normVehicleCOOR[0] = tmp - else: # 路上只有一辆车 - if max(traffic_dict['det'][0][9]) == traffic_dict['det'][0][9][0] and traffic_dict['det'][0][9][0] != -1: - traffic_dict['det'][0][10] = 0 - elif max(traffic_dict['det'][0][9]) == traffic_dict['det'][0][9][1] and traffic_dict['det'][0][9][1] != -1: - traffic_dict['det'][0][10] = 1 - else: - traffic_dict['det'][0][10] = 3 - return traffic_dict['det'] - - -def PostProcessing( traffic_dict): - """ - 对于字典traffic_dict中的各个键,说明如下: - RoadArea:speedRoad的最小外接矩形的面积 - roadVehicleAngle:判定发生交通事故的speedRoad与vehicle间的最小夹角 - vehicleCOOR:是一个列表,用于存储被检测出的vehicle的坐标(vehicle检测模型) - roundness:长宽比 ,vehicle的长与宽的比率,设置为0.7,若宽与长的比值大于0.7,则判定该vehicle发生交通事故 - ZoomFactor:存储的是图像在H和W方向上的缩放因子,其值小于1 - 'cls':类别号 - 'vehicleFactor':两辆车之间的安全距离被定义为:min(车辆1的宽,车辆2的宽) * vehicleFactor - 'radius':半径,以某一vehicle的最小外接矩形的中点为圆心,以radius为半径,划定范围,过滤车辆 - 'distanceFlag':开关。计算vehicle之间的距离时,可选择不同的函数 - 'vehicleFlag':开关。存储vehicle的信息时,可选择不同的函数 - 未发生交通事故时,得分为-1,”事故类型“为3 - 最终输出格式:[[cls, x0, y0, x1, y1, score, 角度, 长宽比, 最小距离, max([角度得分, 长宽比得分, 最小距离得分]), 交通事故类别], ...] - 交通事故类别:0表示角度,1表示长宽比,2表示最短距离,3表示未发生交通事故 - """ - - det_cors = [] - #print('###line338:', traffic_dict['det']) - for bb in traffic_dict['det']: - det_cors.append((int(bb[1]), int(bb[2]))) - det_cors.append((int(bb[3]), int(bb[4]))) - traffic_dict['vehicleCOOR'] = det_cors - - - #testImageArray = testImageArray[:, :, 0] - #H, W = testImageArray.shape[0:2] # sourceImage的分辨率为1080x1920 - - traffic_dict['modelSize']=[640,360] - #traffic_dict['mask'] = cv2.resize(traffic_dict['mask'],(640,360)) - - mask = traffic_dict['mask'] - H, W = mask.shape[0:2] - #(640, 360) 720 1280 (720, 1280) - ####line361: (1920, 1080) 720 1280 (720, 1280) - - ###line361: [640, 360] 360 640 (360, 640) - - - - #print('###line361:',traffic_dict['modelSize'], H,W ,mask.shape) - - scaleH = traffic_dict['modelSize'][1] / H # 自适应调整缩放比例 - scaleW = traffic_dict['modelSize'][0] / W - traffic_dict['ZoomFactor'] = {'x': scaleH, 'y': scaleW} - new_hw = [int(H * scaleH), int(W * scaleW)] - - mask = cv2.resize(mask, (new_hw[1], new_hw[0])) - if len(mask.shape) == 3: - mask = mask[:, :, 0] - - t1 = time.time() - normVehicleBD = [] # 存储一副图像中合格vehicle的contours,合格vehicle,即:contours中的顶点数大于等于6 - imgRoad = mask.copy() - imgVehicle = mask.copy() - imgRoad[imgRoad == 2] = 0 # 将vehicle过滤掉,只包含背景和speedRoad - imgVehicle[imgVehicle == 1] = 0 # 将speedRoad过滤掉,只包含背景和vehicle - imgRoad = cv2.cvtColor(np.uint8(imgRoad), cv2.COLOR_RGB2BGR) # 道路 - imgVehicle = cv2.cvtColor(np.uint8(imgVehicle), cv2.COLOR_RGB2BGR) # 车辆 - - t2 = time.time() - img1 = cv2.cvtColor(imgRoad, cv2.COLOR_BGR2GRAY) - contours, hierarchy = cv2.findContours(img1, cv2.RETR_EXTERNAL, cv2.CHAIN_APPROX_NONE) - t3 = time.time() - - allRoadContent = [] # 存放所有的speedRoad信息,单个speedRoad的信息为:[cnt, speedRoadAngle, rect[1]] - vehicleBox = [] # 存储合格vehicle的box参数,合格vehicle,即:contours顶点个数大于等于6 - vehicleWH = [] # 存储合格vehicle的宽高 - normVehicle = [] # 存储合格vehicle的信息 - unnormVehicle = [] # 存储不合格vehicle的信息,不合格vehicle,即:contours顶点个数小于6 - normVehicleCOOR = [] # 存储合格vehicle的中心点坐标 - allRoadContent = storageRoad(contours, allRoadContent, traffic_dict) - t4 = time.time() - - # 开关。存储vehicle的信息时,可选择不同的函数 - if traffic_dict['vehicleFlag'] == True: - traffic_dict['det'], normVehicleBD, unnormVehicle, normVehicleCOOR = storageVehicle1(traffic_dict, normVehicleBD, normVehicle, unnormVehicle, normVehicleCOOR, imgVehicle) - #所有车辆的[cls,x0,y0,x1,y1,score] - else: - traffic_dict['det'], normVehicleBD, unnormVehicle, normVehicleCOOR = storageVehicle2(traffic_dict, normVehicleBD, normVehicle, unnormVehicle, normVehicleCOOR, imgVehicle) - t5 = time.time() - if len(normVehicleBD) != 0: - t6 = time.time() - vehicleBox, vehicleWH, traffic_dict['det'] = angleRoundness(normVehicleBD, vehicleBox, vehicleWH, allRoadContent, traffic_dict, normVehicleCOOR, imgVehicle) - t7 = time.time() - # 开关。计算vehicle之间的距离时,可选择不同的函数 - if traffic_dict['distanceFlag'] == True: - traffic_dict['det'] = vehicleDistance1(normVehicleCOOR, normVehicleBD, traffic_dict, vehicleWH) - else: - traffic_dict['det'] = vehicleDistance2(normVehicleCOOR, traffic_dict, vehicleWH) - t8 = time.time() - targetList = traffic_dict['det'] - # print("line393", targetList) - for i in range(len(targetList)): - targetList[i][9] = max(targetList[i][9]) - if len(unnormVehicle) != 0: - targetList = targetList + unnormVehicle - t9 = time.time() - # print("line462", targetList) # 目标对象list, [[cls, x0, y0, x1, y1, score, 角度, 长宽比, 最小距离, max([角度得分, 长宽比得分, 最小距离得分]), 类别], ...] - ruleJudge='angle-rundness-distance:%.1f'%( get_ms(t9,t6) ) - else: - targetList = unnormVehicle - ruleJudge = 'No angle-rundness-distance judging' - t10 = time.time() - time_infos = '---test---nothing---' - #time_infos = 'postTime:%.2f (分割时间:%.2f, findContours:%.2f, ruleJudge:%.2f, storageRoad:%.2f, storageVehicle:%.2f, angleRoundScore:%.2f, vehicleDistance:%.2f, mergeList:%.2f)' % ( - # get_ms(t10, t1), get_ms(t2, t1), get_ms(t3, t2), get_ms(t10, t3), get_ms(t4, t3), get_ms(t5, t4), get_ms(t7, t6), get_ms(t8, t7), get_ms(t9, t8)) - time_infos = 'postTime:%.2f , ( findContours:%.1f , carContourFilter:%.1f, %s )' %( get_ms(t10,t1), get_ms(t4,t1), get_ms(t5,t4),ruleJudge) - return targetList, time_infos -def tracfficAccidentMixFunction(preds,seg_pred_mulcls,pars): - tjime0=time.time() - roadIou = pars['roadIou'] if 'roadIou' in pars.keys() else 0.5 - preds = np.array(preds) - #area_factors= np.array([np.sum(seg_pred_mulcls[int(x[2]):int(x[4]), int(x[1]):int(x[3])] )*1.0/(1.0*(x[3]-x[1])*(x[4]-x[2])+0.00001) for x in preds] ) - area_factors= np.array([np.sum(seg_pred_mulcls[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 preds] )#2023.08.03修改数据格式 - water_flag = np.array(area_factors>roadIou) - #print('##line936:',preds ) - dets = preds[water_flag]##如果是水上目标,则需要与水的iou超过0.1;如果是岸坡目标,则直接保留。 - dets = dets.tolist() - - - - #label_info = get_label_info(pars['label_csv']) - imH,imW = seg_pred_mulcls.shape[0:2] - seg_pred = cv2.resize(seg_pred_mulcls,( pars['modelSize'][0] , pars['modelSize'] [1]) ) - mmH,mmW = seg_pred.shape[0:2] - - fx=mmW/imW;fy=mmH/imH - det_coords=[] - - det_coords_original=[] - for box in dets: - #b_0 = box[1:5];b_0.insert(0,box[0]);b_0.append(box[5] ) - b_0 = box[0:4];b_0.insert(0,box[5]);b_0.append(box[4]) - det_coords_original.append( box ) - if int(box[5]) != 1: continue - det_coords.append(b_0) - #print('##line957:',det_coords_original ) - - pars['ZoomFactor']={'x':mmW/imW ,'y':mmH/imH} - - #pars['mask']=seg_pred; - pars['mask']=seg_pred_mulcls; - - - pars['det']=deepcopy(det_coords) - #pars['label_info']=label_info - tlist = list(pars.keys()); tlist.sort() - - if len(det_coords)> 0: - #print('###line459:',pars['mask'].shape, pars['det']) - list8,time_infos = PostProcessing(pars) - #print('###line461:',list8 ) - Accident_results = np.array(list8,dtype=object) - acc_det=[] - #[1.0, 1692.0, 169.0, 1803.0, 221.0, 0.494875431060791, 30, 0.5, 3.0, 0.3, 0] - #[0 , 1 , 2 , 3 , 4 , 5 , 6, 7 , 8 , 9 , 10] - for bpoints in list8: - if bpoints[9]>pars['confThres']: - xyxy=bpoints[1:5];xyxy=[int(x) for x in xyxy] - - cls=9;conf=bpoints[9]; - box_acc = [*xyxy,conf,cls] - 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") - #print('###line475:',acc_det ) - #去掉被定为事故的车辆 - carCorslist = [ [ int(x[0]),int(x[1]), int(x[2]), int(x[3]) ] for x in det_coords_original ] - #print('##line81:',det_coords_original ) - accidentCarIndexs = [ carCorslist.index( [ int(x[0]),int(x[1]), int(x[2]), int(x[3]) ] ) for x in acc_det ] - accidentCarIndexsKeep = set(list(range(len(det_coords_original)))) - set(accidentCarIndexs) - det_coords_original_tmp = [ det_coords_original[x] for x in accidentCarIndexsKeep ] - det_coords_original = det_coords_original_tmp - #print('##line85:',det_coords_original ) - det_coords_original.extend(acc_det) - #4.0, 961.0, 275.0, 1047.0, 288.0, 0.26662659645080566, 0.0, 0.0 - #0 , 1 , 2 , 3 , 4 , 5 , 6 , 7 - #det_coords_original =[ [ *x[1:6], x[0],*x[6:8] ] for x in det_coords_original] - else: - time_infos=" no tracfficAccidentMix process" - - #p_result[2]= deepcopy(det_coords_original) - return deepcopy(det_coords_original),time_infos -def tracfficAccidentMixFunction_N(predList,pars): - preds,seg_pred_mulcls = predList[0:2] +# 设定开关,将最小外接矩形中心点间的距离作为vehicle之间的距离 +import numpy as np +import math, cv2, time +from copy import deepcopy + +def get_ms(time2, time1): + return (time2 - time1) * 1000.0 + + +def two_points_distance(x1, y1, x2, y2): + distance = math.sqrt((x1 - x2) ** 2 + (y1 - y2) ** 2) + return distance + + +# 保存正常vehicle和非正常vehicle的信息(当contours顶点数小于6时,无法拟合最小外接矩形,定义为非正常vehicle) +def saveVehicle1(traffic_dict, contours, normVehicleBD, normVehicle, count, i, unnormVehicle, normVehicleCOOR): + if len(contours) >= 6: + normVehicleBD.append(contours) + normVehicle.append(traffic_dict['det'][count]) + rect = cv2.minAreaRect(contours) + normVehicleCOOR.append(rect[0]) + else: + traffic_dict['det'][int(i / 2)] = traffic_dict['det'][int(i / 2)] + [0, 0.3, 999, -1, 3] + unnormVehicle.append(traffic_dict['det'][int(i / 2)]) + return normVehicleBD, normVehicle, unnormVehicle, normVehicleCOOR + + +# saveVehicle2和saveVehicle1有区别 +def saveVehicle2(traffic_dict, contours, normVehicleBD, normVehicle, count, i, unnormVehicle, normVehicleCOOR, centerCOOR): + if len(contours) >= 6: + normVehicleBD.append(contours) + normVehicle.append(traffic_dict['det'][count]) + normVehicleCOOR.append(centerCOOR) + else: + traffic_dict['det'][int(i / 2)] = traffic_dict['det'][int(i / 2)] + [0, 0.3, 999, -1, 3] + unnormVehicle.append(traffic_dict['det'][int(i / 2)]) + return normVehicleBD, normVehicle, unnormVehicle, normVehicleCOOR + + +# 对于不在道路上的vehicle,将输出信息补全 +def supplementInformation(traffic_dict, i, roundness, y_min, y_max, imgVehicle, rect): + score = -1 + traffic_dict['det'][i] = traffic_dict['det'][i] + [0, roundness, 999, [-1, -1, -1], 666] + if y_min > 0 and y_max < imgVehicle.shape[0] and roundness > traffic_dict['roundness']: # 过滤掉上下方被speedRoad的边界截断的vehicle + score = (min(rect[1]) - max(rect[1]) * traffic_dict['roundness']) / (max(rect[1]) * (1 - traffic_dict['roundness'])) + return score + + +# 判断交通事故类型 +def judgeAccidentType(traffic_dict, b): + if max(traffic_dict['det'][b][9]) == traffic_dict['det'][b][9][0] and traffic_dict['det'][b][9][0] != -1: + return 0 + elif max(traffic_dict['det'][b][9]) == traffic_dict['det'][b][9][1] and traffic_dict['det'][b][9][1] != -1: + return 1 + elif max(traffic_dict['det'][b][9]) == traffic_dict['det'][b][9][2] and traffic_dict['det'][b][9][2] != -1: + return 2 + else: + return 3 + + +# 计算距离得分 +def distanceScore(vehicleWH, index1, index2, smallestDistance, traffic_dict): + d1 = (min(vehicleWH[index1]) + min(vehicleWH[index2])) / 2 + d2 = min(min(vehicleWH[index1]), min(vehicleWH[index2])) + max(min(vehicleWH[index1]), min(vehicleWH[index2])) / 2 + if smallestDistance == d1: + score1 = 1 + traffic_dict['det'][index2][9][2] = score1 + traffic_dict['det'][index2][10] = judgeAccidentType(traffic_dict, index2) + elif smallestDistance < d2: + score1 = 1 - (smallestDistance - d1) / (d2 - d1) + if 0 < score1 < 1: + traffic_dict['det'][index2][9][2] = score1 + traffic_dict['det'][index2][10] = judgeAccidentType(traffic_dict, index2) + else: + traffic_dict['det'][index2][10] = judgeAccidentType(traffic_dict, index2) + else: + traffic_dict['det'][index2][10] = judgeAccidentType(traffic_dict, index2) + return traffic_dict['det'] + + +# 计算两个contours之间的最短距离 +def array_distance(arr1, arr2): + ''' + 计算两个数组中,每任意两个点之间L2距离 + arr1和arr2都必须是numpy数组 + 且维度分别是mx2,nx2 + 输出数组维度为mxn + ''' + m, _ = arr1.shape + n, _ = arr2.shape + arr1_power = np.power(arr1, 2) + arr1_power_sum = arr1_power[:, 0] + arr1_power[:, 1] # 第1区域,x与y的平方和 + arr1_power_sum = np.tile(arr1_power_sum, (n, 1)) # 将arr1_power_sum沿着y轴复制n倍,沿着x轴复制1倍,这里用于与arr2进行计算。 n x m 维度 + arr1_power_sum = arr1_power_sum.T # 将arr1_power_sum进行转置 + arr2_power = np.power(arr2, 2) + arr2_power_sum = arr2_power[:, 0] + arr2_power[:, 1] # 第2区域,x与y的平方和 + arr2_power_sum = np.tile(arr2_power_sum, (m, 1)) # 将arr1_power_sum沿着y轴复制m倍,沿着x轴复制1倍,这里用于与arr1进行计算。 m x n 维度 + dis = arr1_power_sum + arr2_power_sum - (2 * np.dot(arr1, arr2.T)) # np.dot(arr1, arr2.T)矩阵相乘,得到xy的值。 + dis = np.sqrt(dis) + return dis + + +# 存储所有道路的信息 +def storageRoad(contours, allRoadContent, traffic_dict): + speedRoadAngle = 0 + for cnt in contours: # 道路 + rect = cv2.minAreaRect(cnt) + if rect[1][0] * rect[1][1] > traffic_dict['RoadArea']: # 过滤掉面积小于阈值的speedRoad + if rect[1][0] <= rect[1][1]: + if rect[2] >= 0 and rect[2] < 90: + speedRoadAngle = rect[2] + 90 + elif rect[2] == 90: + speedRoadAngle = 0 + else: + if rect[2] >= 0 and rect[2] <= 90: + speedRoadAngle = rect[2] + allRoadContent.append([cnt, speedRoadAngle, rect[1]]) + return allRoadContent + + +# 存储所有vehicle的信息,方法1 +def storageVehicle1(traffic_dict, normVehicleBD, normVehicle, unnormVehicle, normVehicleCOOR, imgVehicle): + #输入: + # + #输出:traffic_dict['det'], normVehicleBD, unnormVehicle, normVehicleCOOR + # traffic_dict['det']:resize缩小之后的坐标,类别,得分.[cls,x0,y0,x1,y1,score] + + # normVehicleBD : 正常车辆的contours。(正常车辆指的是countrous定点数>=6) + # unnormVehicle : resize缩小之后的异常车辆坐标,类别,得分.[cls,x0,y0,x1,y1,score] + count = 0 + for i in range(0, len(traffic_dict['vehicleCOOR']), 2): + mask = np.zeros(imgVehicle.shape[:2], dtype="uint8") + x0 = int(traffic_dict['vehicleCOOR'][i][0] * traffic_dict['ZoomFactor']['y']) + y0 = int(traffic_dict['vehicleCOOR'][i][1] * traffic_dict['ZoomFactor']['x']) + x1 = int(traffic_dict['vehicleCOOR'][i + 1][0] * traffic_dict['ZoomFactor']['y']) + y1 = int(traffic_dict['vehicleCOOR'][i + 1][1] * traffic_dict['ZoomFactor']['x']) + cv2.rectangle(mask, (x0, y0), (x1, y1), 255, -1, lineType=cv2.LINE_AA) + imgVehicle_masked = cv2.bitwise_and(imgVehicle, imgVehicle, mask=mask) + img2 = cv2.cvtColor(imgVehicle_masked, cv2.COLOR_BGR2GRAY) + contours2, hierarchy2 = cv2.findContours(img2, cv2.RETR_EXTERNAL, cv2.CHAIN_APPROX_NONE) + if len(contours2) != 0: + if len(contours2) > 1: # 这里我通过比较同一检测框内各个contours对应的最小外接矩形的面积,来剔除那些存在干扰的contours,最终只保留一个contours + vehicleArea = [] # 存储vehicle的最小外接矩形的面积 + for j in range(len(contours2)): + rect = cv2.minAreaRect(contours2[j]) + vehicleArea.append(rect[1][0] * rect[1][1]) + maxAreaIndex = vehicleArea.index(max(vehicleArea)) + maxAreaContours = contours2[maxAreaIndex] + normVehicleBD, normVehicle, unnormVehicle, normVehicleCOOR = saveVehicle1(traffic_dict,maxAreaContours,normVehicleBD,normVehicle,count,i,unnormVehicle, normVehicleCOOR) + elif len(contours2) == 1: + normVehicleBD, normVehicle, unnormVehicle, normVehicleCOOR = saveVehicle1(traffic_dict,contours2[0],normVehicleBD,normVehicle,count,i,unnormVehicle, normVehicleCOOR) + else: + traffic_dict['det'][int(i / 2)] = traffic_dict['det'][int(i / 2)] + [0, 0.3, 999, -1, 3] + unnormVehicle.append(traffic_dict['det'][int(i / 2)]) + count += 1 + traffic_dict['det'] = normVehicle + return traffic_dict['det'], normVehicleBD, unnormVehicle, normVehicleCOOR + + +# 存储所有vehicle的信息,方法2 +def storageVehicle2(traffic_dict, normVehicleBD, normVehicle, unnormVehicle, normVehicleCOOR, imgVehicle): + img = cv2.cvtColor(imgVehicle, cv2.COLOR_BGR2GRAY) + count = 0 + for i in range(0, len(traffic_dict['vehicleCOOR']), 2): + row1 = int(traffic_dict['vehicleCOOR'][i][1] * traffic_dict['ZoomFactor']['x']) + row2 = int(traffic_dict['vehicleCOOR'][i + 1][1] * traffic_dict['ZoomFactor']['x']) + col1 = int(traffic_dict['vehicleCOOR'][i][0] * traffic_dict['ZoomFactor']['y']) + col2 = int(traffic_dict['vehicleCOOR'][i + 1][0] * traffic_dict['ZoomFactor']['y']) + + if row1 >= 2: + row1 = row1 - 2 + if row2 <= (traffic_dict['modelSize'][1] - 2): + row2 = row2 + 2 + if col1 >= 2: + col1 = col1 - 2 + if col2 <= (traffic_dict['modelSize'][0] - 2): + col2 = col2 + 2 + centerCOOR = (int((col1 + col2) / 2), int((row1 + row2) / 2)) + img1 = img[row1:row2, col1:col2] + up = np.zeros((20, (col2 - col1)), dtype='uint8') + left = np.zeros(((40 + row2 - row1), 20), dtype='uint8') + + img1 = np.concatenate((up, img1), axis=0) + img1 = np.concatenate((img1, up), axis=0) + + img1 = np.concatenate((left, img1), axis=1) + img2 = np.concatenate((img1, left), axis=1) + contours2, hierarchy = cv2.findContours(img2, cv2.RETR_EXTERNAL, cv2.CHAIN_APPROX_NONE) + if len(contours2) != 0: + if len(contours2) > 1: + vehicleArea = [] # 存储vehicle的最小外接矩形的面积 + for j in range(len(contours2)): + rect = cv2.minAreaRect(contours2[j]) + vehicleArea.append(rect[1][0] * rect[1][1]) + maxAreaIndex = vehicleArea.index(max(vehicleArea)) + maxAreaContours = contours2[maxAreaIndex] + normVehicleBD, normVehicle, unnormVehicle, normVehicleCOOR = saveVehicle2(traffic_dict,maxAreaContours,normVehicleBD,normVehicle,count,i,unnormVehicle,normVehicleCOOR,centerCOOR) + elif len(contours2) == 1: + normVehicleBD, normVehicle, unnormVehicle, normVehicleCOOR = saveVehicle2(traffic_dict,contours2[0],normVehicleBD,normVehicle,count,i,unnormVehicle,normVehicleCOOR,centerCOOR) + else: + traffic_dict['det'][int(i / 2)] = traffic_dict['det'][int(i / 2)] + [0, 0.3, 999, -1, 3] + unnormVehicle.append(traffic_dict['det'][int(i / 2)]) + count += 1 + traffic_dict['det'] = normVehicle + return traffic_dict['det'], normVehicleBD, unnormVehicle, normVehicleCOOR + + +# 计算角度和长宽比得分 +def angleRoundness(normVehicleBD, vehicleBox, vehicleWH, allRoadContent, traffic_dict, normVehicleCOOR, imgVehicle): + ##输出:vehicleBox, vehicleWH, traffic_dict['det'] + # vehicleBox--正常车辆通过contours得出的box,[ (x0,y0),(x1,y1),(x2,y2),(x3,y3)] + # vehicleWH--正常车辆通过contours得出的box,[ (w,h)] + # traffic_dict['det']--[[cls, x0, y0, x1, y1, score, 角度, 长宽比, 最小距离, max([角度得分, 长宽比得分, 最小距离得分]), 交通事故类别], ...] + for i in range(len(normVehicleBD)): + ellipse = cv2.fitEllipse(normVehicleBD[i]) + vehicleAngle = 0 + if ellipse[2] >= 0 and ellipse[2] < 90: + vehicleAngle = 90 + ellipse[2] + elif ellipse[2] >= 90 and ellipse[2] < 180: + vehicleAngle = ellipse[2] - 90 + elif ellipse[2] == 180: + vehicleAngle = 90 + rect = cv2.minAreaRect(normVehicleBD[i]) + box = cv2.boxPoints(rect).astype(np.int32) + center = normVehicleCOOR[i] + vehicleBox.append(box) + vehicleWH.append(rect[1]) + roundness = min(rect[1]) / max(rect[1]) + y_min = np.min(box[:, 1]) + y_max = np.max(box[:, 1]) + if len(allRoadContent) != 0: + for j in range(len(allRoadContent)): + flag = cv2.pointPolygonTest(allRoadContent[j][0], center, False) + if flag >= 0: + roadVehicleAngle = abs(vehicleAngle - allRoadContent[j][1]) + traffic_dict['det'][i] = traffic_dict['det'][i] + [roadVehicleAngle, roundness, 999, [-1, -1, -1], 666] + if y_min > 0 and y_max < imgVehicle.shape[0]: # 过滤掉上下方被speedRoad的边界截断的vehicle + if roadVehicleAngle >= traffic_dict['roadVehicleAngle']: # 当道路同水平方向的夹角与车辆同水平方向的夹角的差值在15°和75°之间时,需要将车辆框出来 + if roadVehicleAngle > 90: + score1 = float((180 - roadVehicleAngle) / 90) + else: + score1 = float(roadVehicleAngle / 90) + traffic_dict['det'][i][9][0] = score1 + if roundness > traffic_dict['roundness']: + score2 = (min(rect[1]) - max(rect[1]) * traffic_dict['roundness']) / (max(rect[1]) * (1 - traffic_dict['roundness'])) + traffic_dict['det'][i][9][1] = score2 + break + else: + j += 1 + if len(traffic_dict['det'][i]) == 6: + traffic_dict['det'][i][9][1] = supplementInformation(traffic_dict, i, roundness, y_min, y_max, imgVehicle, rect) + else: + traffic_dict['det'][i][9][1] = supplementInformation(traffic_dict, i, roundness, y_min, y_max, imgVehicle, rect) + i += 1 + return vehicleBox, vehicleWH, traffic_dict['det'] + + +# 对于某一vehicle,以该vehicle的最小外接矩形的中心点为圆心O1,划定半径范围,求O1与半径范围内的其他vehicle的中心点之间的距离 +def vehicleDistance1(normVehicleCOOR, normVehicleBD, traffic_dict, vehicleWH): + if len(normVehicleCOOR) > 1: + for b in range(len(normVehicleCOOR)): + contoursMinDistance = [] # 存储contours之间的最短距离 + tmp = normVehicleCOOR[b] + normVehicleCOOR[b] = normVehicleCOOR[0] + normVehicleCOOR[0] = tmp + targetContours = [] # 存储目标vehicle和中心点同目标车辆中心点之间的距离小于traffic_dict['radius']的vehicle的box + for c in range(1, len(normVehicleCOOR)): + if two_points_distance(normVehicleCOOR[0][0], normVehicleCOOR[0][1], normVehicleCOOR[c][0], normVehicleCOOR[c][1]) <= traffic_dict['radius']: + if normVehicleBD[b] not in targetContours: + targetContours.append(normVehicleBD[b]) + if c == b: + targetContours.append(normVehicleBD[0]) + else: + targetContours.append(normVehicleBD[c]) + if len(targetContours) != 0: + goalVehicleContour = np.squeeze(targetContours[0], 1) + for d in range(1, len(targetContours)): + elseVehicleContour = np.squeeze(targetContours[d], 1) + dist_arr = array_distance(goalVehicleContour, elseVehicleContour) + min_dist = dist_arr[dist_arr > 0].min() + contoursMinDistance.append(min_dist) + traffic_dict['det'][b][8] = min(contoursMinDistance) + if traffic_dict['det'][b][8] < min(vehicleWH[b]) * traffic_dict['vehicleFactor']: + score1 = 1 - traffic_dict['det'][b][8] / (min(vehicleWH[b]) * traffic_dict['vehicleFactor']) + traffic_dict['det'][b][9][2] = score1 + traffic_dict['det'][b][10] = judgeAccidentType(traffic_dict, b) + else: + traffic_dict['det'][b][8] = 999 + traffic_dict['det'][b][10] = judgeAccidentType(traffic_dict, b) + tmp = normVehicleCOOR[b] + normVehicleCOOR[b] = normVehicleCOOR[0] + normVehicleCOOR[0] = tmp + else: # 路上只有一辆车 + if max(traffic_dict['det'][0][9]) == traffic_dict['det'][0][9][0] and traffic_dict['det'][0][9][0] != -1: + traffic_dict['det'][0][10] = 0 + elif max(traffic_dict['det'][0][9]) == traffic_dict['det'][0][9][1] and traffic_dict['det'][0][9][1] != -1: + traffic_dict['det'][0][10] = 1 + else: + traffic_dict['det'][0][10] = 3 + return traffic_dict['det'] + + +# 计算vehicle的最小外接矩形中心点之间的距离和距离得分 +def vehicleDistance2(normVehicleCOOR, traffic_dict, vehicleWH): + if len(normVehicleCOOR) > 1: # 有多辆车 + for b in range(len(normVehicleCOOR)): + centerDistance = [] # 存储contours之间的最短距离 + tmp = normVehicleCOOR[b] + normVehicleCOOR[b] = normVehicleCOOR[0] + normVehicleCOOR[0] = tmp + for c in range(1, len(normVehicleCOOR)): + centerDistance.append(two_points_distance(normVehicleCOOR[0][0], normVehicleCOOR[0][1], normVehicleCOOR[c][0], normVehicleCOOR[c][1])) + smallestDistance = min(centerDistance) + index = centerDistance.index(smallestDistance) + traffic_dict['det'][b][8] = smallestDistance + if index == b - 1: # 序号0和b对应的vehicle + traffic_dict['det'] = distanceScore(vehicleWH, 0, b, smallestDistance, traffic_dict) + else: + traffic_dict['det'] = distanceScore(vehicleWH, index+1, b, smallestDistance, traffic_dict) + tmp = normVehicleCOOR[b] + normVehicleCOOR[b] = normVehicleCOOR[0] + normVehicleCOOR[0] = tmp + else: # 路上只有一辆车 + if max(traffic_dict['det'][0][9]) == traffic_dict['det'][0][9][0] and traffic_dict['det'][0][9][0] != -1: + traffic_dict['det'][0][10] = 0 + elif max(traffic_dict['det'][0][9]) == traffic_dict['det'][0][9][1] and traffic_dict['det'][0][9][1] != -1: + traffic_dict['det'][0][10] = 1 + else: + traffic_dict['det'][0][10] = 3 + return traffic_dict['det'] + + +def PostProcessing( traffic_dict): + """ + 对于字典traffic_dict中的各个键,说明如下: + RoadArea:speedRoad的最小外接矩形的面积 + roadVehicleAngle:判定发生交通事故的speedRoad与vehicle间的最小夹角 + vehicleCOOR:是一个列表,用于存储被检测出的vehicle的坐标(vehicle检测模型) + roundness:长宽比 ,vehicle的长与宽的比率,设置为0.7,若宽与长的比值大于0.7,则判定该vehicle发生交通事故 + ZoomFactor:存储的是图像在H和W方向上的缩放因子,其值小于1 + 'cls':类别号 + 'vehicleFactor':两辆车之间的安全距离被定义为:min(车辆1的宽,车辆2的宽) * vehicleFactor + 'radius':半径,以某一vehicle的最小外接矩形的中点为圆心,以radius为半径,划定范围,过滤车辆 + 'distanceFlag':开关。计算vehicle之间的距离时,可选择不同的函数 + 'vehicleFlag':开关。存储vehicle的信息时,可选择不同的函数 + 未发生交通事故时,得分为-1,”事故类型“为3 + 最终输出格式:[[cls, x0, y0, x1, y1, score, 角度, 长宽比, 最小距离, max([角度得分, 长宽比得分, 最小距离得分]), 交通事故类别], ...] + 交通事故类别:0表示角度,1表示长宽比,2表示最短距离,3表示未发生交通事故 + """ + + det_cors = [] + #print('###line338:', traffic_dict['det']) + for bb in traffic_dict['det']: + det_cors.append((int(bb[1]), int(bb[2]))) + det_cors.append((int(bb[3]), int(bb[4]))) + traffic_dict['vehicleCOOR'] = det_cors + + + #testImageArray = testImageArray[:, :, 0] + #H, W = testImageArray.shape[0:2] # sourceImage的分辨率为1080x1920 + + traffic_dict['modelSize']=[640,360] + #traffic_dict['mask'] = cv2.resize(traffic_dict['mask'],(640,360)) + + mask = traffic_dict['mask'] + H, W = mask.shape[0:2] + #(640, 360) 720 1280 (720, 1280) + ####line361: (1920, 1080) 720 1280 (720, 1280) + + ###line361: [640, 360] 360 640 (360, 640) + + + + #print('###line361:',traffic_dict['modelSize'], H,W ,mask.shape) + + scaleH = traffic_dict['modelSize'][1] / H # 自适应调整缩放比例 + scaleW = traffic_dict['modelSize'][0] / W + traffic_dict['ZoomFactor'] = {'x': scaleH, 'y': scaleW} + new_hw = [int(H * scaleH), int(W * scaleW)] + + mask = cv2.resize(mask, (new_hw[1], new_hw[0])) + if len(mask.shape) == 3: + mask = mask[:, :, 0] + + t1 = time.time() + normVehicleBD = [] # 存储一副图像中合格vehicle的contours,合格vehicle,即:contours中的顶点数大于等于6 + imgRoad = mask.copy() + imgVehicle = mask.copy() + imgRoad[imgRoad == 2] = 0 # 将vehicle过滤掉,只包含背景和speedRoad + imgVehicle[imgVehicle == 1] = 0 # 将speedRoad过滤掉,只包含背景和vehicle + imgRoad = cv2.cvtColor(np.uint8(imgRoad), cv2.COLOR_RGB2BGR) # 道路 + imgVehicle = cv2.cvtColor(np.uint8(imgVehicle), cv2.COLOR_RGB2BGR) # 车辆 + + t2 = time.time() + img1 = cv2.cvtColor(imgRoad, cv2.COLOR_BGR2GRAY) + contours, hierarchy = cv2.findContours(img1, cv2.RETR_EXTERNAL, cv2.CHAIN_APPROX_NONE) + t3 = time.time() + + allRoadContent = [] # 存放所有的speedRoad信息,单个speedRoad的信息为:[cnt, speedRoadAngle, rect[1]] + vehicleBox = [] # 存储合格vehicle的box参数,合格vehicle,即:contours顶点个数大于等于6 + vehicleWH = [] # 存储合格vehicle的宽高 + normVehicle = [] # 存储合格vehicle的信息 + unnormVehicle = [] # 存储不合格vehicle的信息,不合格vehicle,即:contours顶点个数小于6 + normVehicleCOOR = [] # 存储合格vehicle的中心点坐标 + allRoadContent = storageRoad(contours, allRoadContent, traffic_dict) + t4 = time.time() + + # 开关。存储vehicle的信息时,可选择不同的函数 + if traffic_dict['vehicleFlag'] == True: + traffic_dict['det'], normVehicleBD, unnormVehicle, normVehicleCOOR = storageVehicle1(traffic_dict, normVehicleBD, normVehicle, unnormVehicle, normVehicleCOOR, imgVehicle) + #所有车辆的[cls,x0,y0,x1,y1,score] + else: + traffic_dict['det'], normVehicleBD, unnormVehicle, normVehicleCOOR = storageVehicle2(traffic_dict, normVehicleBD, normVehicle, unnormVehicle, normVehicleCOOR, imgVehicle) + t5 = time.time() + if len(normVehicleBD) != 0: + t6 = time.time() + vehicleBox, vehicleWH, traffic_dict['det'] = angleRoundness(normVehicleBD, vehicleBox, vehicleWH, allRoadContent, traffic_dict, normVehicleCOOR, imgVehicle) + t7 = time.time() + # 开关。计算vehicle之间的距离时,可选择不同的函数 + if traffic_dict['distanceFlag'] == True: + traffic_dict['det'] = vehicleDistance1(normVehicleCOOR, normVehicleBD, traffic_dict, vehicleWH) + else: + traffic_dict['det'] = vehicleDistance2(normVehicleCOOR, traffic_dict, vehicleWH) + t8 = time.time() + targetList = traffic_dict['det'] + # print("line393", targetList) + for i in range(len(targetList)): + targetList[i][9] = max(targetList[i][9]) + if len(unnormVehicle) != 0: + targetList = targetList + unnormVehicle + t9 = time.time() + # print("line462", targetList) # 目标对象list, [[cls, x0, y0, x1, y1, score, 角度, 长宽比, 最小距离, max([角度得分, 长宽比得分, 最小距离得分]), 类别], ...] + ruleJudge='angle-rundness-distance:%.1f'%( get_ms(t9,t6) ) + else: + targetList = unnormVehicle + ruleJudge = 'No angle-rundness-distance judging' + t10 = time.time() + time_infos = '---test---nothing---' + #time_infos = 'postTime:%.2f (分割时间:%.2f, findContours:%.2f, ruleJudge:%.2f, storageRoad:%.2f, storageVehicle:%.2f, angleRoundScore:%.2f, vehicleDistance:%.2f, mergeList:%.2f)' % ( + # get_ms(t10, t1), get_ms(t2, t1), get_ms(t3, t2), get_ms(t10, t3), get_ms(t4, t3), get_ms(t5, t4), get_ms(t7, t6), get_ms(t8, t7), get_ms(t9, t8)) + time_infos = 'postTime:%.2f , ( findContours:%.1f , carContourFilter:%.1f, %s )' %( get_ms(t10,t1), get_ms(t4,t1), get_ms(t5,t4),ruleJudge) + return targetList, time_infos +def tracfficAccidentMixFunction(preds,seg_pred_mulcls,pars): + tjime0=time.time() + roadIou = pars['roadIou'] if 'roadIou' in pars.keys() else 0.5 + preds = np.array(preds) + #area_factors= np.array([np.sum(seg_pred_mulcls[int(x[2]):int(x[4]), int(x[1]):int(x[3])] )*1.0/(1.0*(x[3]-x[1])*(x[4]-x[2])+0.00001) for x in preds] ) + area_factors= np.array([np.sum(seg_pred_mulcls[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 preds] )#2023.08.03修改数据格式 + water_flag = np.array(area_factors>roadIou) + #print('##line936:',preds ) + dets = preds[water_flag]##如果是水上目标,则需要与水的iou超过0.1;如果是岸坡目标,则直接保留。 + dets = dets.tolist() + + + + #label_info = get_label_info(pars['label_csv']) + imH,imW = seg_pred_mulcls.shape[0:2] + seg_pred = cv2.resize(seg_pred_mulcls,( pars['modelSize'][0] , pars['modelSize'] [1]) ) + mmH,mmW = seg_pred.shape[0:2] + + fx=mmW/imW;fy=mmH/imH + det_coords=[] + + det_coords_original=[] + for box in dets: + #b_0 = box[1:5];b_0.insert(0,box[0]);b_0.append(box[5] ) + b_0 = box[0:4];b_0.insert(0,box[5]);b_0.append(box[4]) + det_coords_original.append( box ) + if int(box[5]) != pars['CarId'] or int(box[5]) != pars['CthcId']: continue + det_coords.append(b_0) + #print('##line957:',det_coords_original ) + + pars['ZoomFactor']={'x':mmW/imW ,'y':mmH/imH} + + #pars['mask']=seg_pred; + pars['mask']=seg_pred_mulcls; + + + pars['det']=deepcopy(det_coords) + #pars['label_info']=label_info + tlist = list(pars.keys()); tlist.sort() + + if len(det_coords)> 0: + #print('###line459:',pars['mask'].shape, pars['det']) + list8,time_infos = PostProcessing(pars) + #print('###line461:',list8 ) + Accident_results = np.array(list8,dtype=object) + acc_det=[] + #[1.0, 1692.0, 169.0, 1803.0, 221.0, 0.494875431060791, 30, 0.5, 3.0, 0.3, 0] + #[0 , 1 , 2 , 3 , 4 , 5 , 6, 7 , 8 , 9 , 10] + for bpoints in list8: + if bpoints[9]>pars['confThres']: + xyxy=bpoints[1:5];xyxy=[int(x) for x in xyxy] + + cls=pars['cls'];conf=bpoints[9]; + box_acc = [*xyxy,conf,cls] + 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") + #print('###line475:',acc_det ) + #去掉被定为事故的车辆 + carCorslist = [ [ int(x[0]),int(x[1]), int(x[2]), int(x[3]) ] for x in det_coords_original ] + #print('##line81:',det_coords_original ) + accidentCarIndexs = [ carCorslist.index( [ int(x[0]),int(x[1]), int(x[2]), int(x[3]) ] ) for x in acc_det ] + accidentCarIndexsKeep = set(list(range(len(det_coords_original)))) - set(accidentCarIndexs) + det_coords_original_tmp = [ det_coords_original[x] for x in accidentCarIndexsKeep ] + det_coords_original = det_coords_original_tmp + #print('##line85:',det_coords_original ) + det_coords_original.extend(acc_det) + #4.0, 961.0, 275.0, 1047.0, 288.0, 0.26662659645080566, 0.0, 0.0 + #0 , 1 , 2 , 3 , 4 , 5 , 6 , 7 + #det_coords_original =[ [ *x[1:6], x[0],*x[6:8] ] for x in det_coords_original] + else: + time_infos=" no tracfficAccidentMix process" + + #p_result[2]= deepcopy(det_coords_original) + return deepcopy(det_coords_original),time_infos +def tracfficAccidentMixFunction_N(predList,pars): + preds,seg_pred_mulcls = predList[0:2] return tracfficAccidentMixFunction(preds,seg_pred_mulcls,pars) \ No newline at end of file diff --git a/trackUtils/__pycache__/sort.cpython-38.pyc b/trackUtils/__pycache__/sort.cpython-38.pyc deleted file mode 100644 index 5d941fe..0000000 Binary files a/trackUtils/__pycache__/sort.cpython-38.pyc and /dev/null differ diff --git a/trackUtils/__pycache__/sort_obb.cpython-38.pyc b/trackUtils/__pycache__/sort_obb.cpython-38.pyc deleted file mode 100644 index 7455318..0000000 Binary files a/trackUtils/__pycache__/sort_obb.cpython-38.pyc and /dev/null differ diff --git a/utils/__pycache__/__init__.cpython-38.pyc b/utils/__pycache__/__init__.cpython-38.pyc deleted file mode 100644 index c647d7f..0000000 Binary files a/utils/__pycache__/__init__.cpython-38.pyc and /dev/null differ diff --git a/utils/__pycache__/autoanchor.cpython-38.pyc b/utils/__pycache__/autoanchor.cpython-38.pyc deleted file mode 100644 index 6a3c758..0000000 Binary files a/utils/__pycache__/autoanchor.cpython-38.pyc and /dev/null differ diff --git a/utils/__pycache__/datasets.cpython-38.pyc b/utils/__pycache__/datasets.cpython-38.pyc deleted file mode 100644 index 812be03..0000000 Binary files a/utils/__pycache__/datasets.cpython-38.pyc and /dev/null differ diff --git a/utils/__pycache__/general.cpython-38.pyc b/utils/__pycache__/general.cpython-38.pyc deleted file mode 100644 index 4cd9b55..0000000 Binary files a/utils/__pycache__/general.cpython-38.pyc and /dev/null differ diff --git a/utils/__pycache__/get_offline_url.cpython-38.pyc b/utils/__pycache__/get_offline_url.cpython-38.pyc deleted file mode 100644 index 844c185..0000000 Binary files a/utils/__pycache__/get_offline_url.cpython-38.pyc and /dev/null differ diff --git a/utils/__pycache__/google_utils.cpython-38.pyc b/utils/__pycache__/google_utils.cpython-38.pyc deleted file mode 100644 index 6bd33d8..0000000 Binary files a/utils/__pycache__/google_utils.cpython-38.pyc and /dev/null differ diff --git a/utils/__pycache__/loss.cpython-38.pyc b/utils/__pycache__/loss.cpython-38.pyc deleted file mode 100644 index ac552e4..0000000 Binary files a/utils/__pycache__/loss.cpython-38.pyc and /dev/null differ diff --git a/utils/__pycache__/metrics.cpython-38.pyc b/utils/__pycache__/metrics.cpython-38.pyc deleted file mode 100644 index a735691..0000000 Binary files a/utils/__pycache__/metrics.cpython-38.pyc and /dev/null differ diff --git a/utils/__pycache__/plots.cpython-38.pyc b/utils/__pycache__/plots.cpython-38.pyc deleted file mode 100644 index 2b1f570..0000000 Binary files a/utils/__pycache__/plots.cpython-38.pyc and /dev/null differ diff --git a/utils/__pycache__/torch_utils.cpython-38.pyc b/utils/__pycache__/torch_utils.cpython-38.pyc deleted file mode 100644 index f4b5c21..0000000 Binary files a/utils/__pycache__/torch_utils.cpython-38.pyc and /dev/null differ diff --git a/utilsK/__pycache__/GPUtils.cpython-38.pyc b/utilsK/__pycache__/GPUtils.cpython-38.pyc deleted file mode 100644 index 2c63946..0000000 Binary files a/utilsK/__pycache__/GPUtils.cpython-38.pyc and /dev/null differ diff --git a/utilsK/__pycache__/channel2postUtils.cpython-38.pyc b/utilsK/__pycache__/channel2postUtils.cpython-38.pyc deleted file mode 100644 index 5af6dc8..0000000 Binary files a/utilsK/__pycache__/channel2postUtils.cpython-38.pyc and /dev/null differ diff --git a/utilsK/__pycache__/crackUtils.cpython-38.pyc b/utilsK/__pycache__/crackUtils.cpython-38.pyc deleted file mode 100644 index 55c3865..0000000 Binary files a/utilsK/__pycache__/crackUtils.cpython-38.pyc and /dev/null differ diff --git a/utilsK/__pycache__/crowdGather.cpython-38.pyc b/utilsK/__pycache__/crowdGather.cpython-38.pyc deleted file mode 100644 index 0ee347b..0000000 Binary files a/utilsK/__pycache__/crowdGather.cpython-38.pyc and /dev/null differ diff --git a/utilsK/__pycache__/drownUtils.cpython-38.pyc b/utilsK/__pycache__/drownUtils.cpython-38.pyc deleted file mode 100644 index 82b8c9f..0000000 Binary files a/utilsK/__pycache__/drownUtils.cpython-38.pyc and /dev/null differ diff --git a/utilsK/__pycache__/illParkingUtils.cpython-38.pyc b/utilsK/__pycache__/illParkingUtils.cpython-38.pyc deleted file mode 100644 index 7e82b64..0000000 Binary files a/utilsK/__pycache__/illParkingUtils.cpython-38.pyc and /dev/null differ diff --git a/utilsK/__pycache__/jkmUtils.cpython-38.pyc b/utilsK/__pycache__/jkmUtils.cpython-38.pyc deleted file mode 100644 index f3352dd..0000000 Binary files a/utilsK/__pycache__/jkmUtils.cpython-38.pyc and /dev/null differ diff --git a/utilsK/__pycache__/maskUtils.cpython-38.pyc b/utilsK/__pycache__/maskUtils.cpython-38.pyc deleted file mode 100644 index f88b60a..0000000 Binary files a/utilsK/__pycache__/maskUtils.cpython-38.pyc and /dev/null differ diff --git a/utilsK/__pycache__/masterUtils.cpython-38.pyc b/utilsK/__pycache__/masterUtils.cpython-38.pyc deleted file mode 100644 index 3ccdc2e..0000000 Binary files a/utilsK/__pycache__/masterUtils.cpython-38.pyc and /dev/null differ diff --git a/utilsK/__pycache__/modelEval.cpython-38.pyc b/utilsK/__pycache__/modelEval.cpython-38.pyc deleted file mode 100644 index 720bfcb..0000000 Binary files a/utilsK/__pycache__/modelEval.cpython-38.pyc and /dev/null differ diff --git a/utilsK/__pycache__/noParkingUtils.cpython-38.pyc b/utilsK/__pycache__/noParkingUtils.cpython-38.pyc deleted file mode 100644 index 584825d..0000000 Binary files a/utilsK/__pycache__/noParkingUtils.cpython-38.pyc and /dev/null differ diff --git a/utilsK/__pycache__/ocrUtils.cpython-38.pyc b/utilsK/__pycache__/ocrUtils.cpython-38.pyc deleted file mode 100644 index 7ea784a..0000000 Binary files a/utilsK/__pycache__/ocrUtils.cpython-38.pyc and /dev/null differ diff --git a/utilsK/__pycache__/queRiver.cpython-38.pyc b/utilsK/__pycache__/queRiver.cpython-38.pyc deleted file mode 100644 index c412fce..0000000 Binary files a/utilsK/__pycache__/queRiver.cpython-38.pyc and /dev/null differ diff --git a/utilsK/__pycache__/sendUtils.cpython-38.pyc b/utilsK/__pycache__/sendUtils.cpython-38.pyc deleted file mode 100644 index 1724baa..0000000 Binary files a/utilsK/__pycache__/sendUtils.cpython-38.pyc and /dev/null differ diff --git a/utilsK/__pycache__/spillUtils.cpython-38.pyc b/utilsK/__pycache__/spillUtils.cpython-38.pyc deleted file mode 100644 index 937e846..0000000 Binary files a/utilsK/__pycache__/spillUtils.cpython-38.pyc and /dev/null differ diff --git a/utilsK/channel2postUtils.py b/utilsK/channel2postUtils.py index 3df461c..2cd98fc 100644 --- a/utilsK/channel2postUtils.py +++ b/utilsK/channel2postUtils.py @@ -26,7 +26,7 @@ def channel2_post_process(predsList,pars): ''' 后处理程序,将检测结果中未悬挂国旗的船只,其类别改为4,即'unflagged_ship' 最终类别汇总如下, - ['flag', 'buoy', 'shipname', 'ship','unflagged_ship']=[0,1,2,3,4] + ['flag', 'buoy', 'shipname', 'ship','unflagged_ship','uncover']=[0,1,2,3,4,5] 输入: preds 一张图像的检测结果,为嵌套列表,tensor,包括x_y_x_y_conf_class @@ -51,96 +51,54 @@ def channel2_post_process(predsList,pars): #jcq: 增加封仓 preds_uncover = [] + + # 1、处理未封仓 + preds = filter_detection_results(preds,pars) for i in range(len(preds)): - if preds[i][5]==pars['bigId']: #识别为船 + if preds[i][5]==pars['boatId']: #识别为船 preds_boat.append(preds[i]) - elif preds[i][5]==pars['smallId']: #识别为国旗 + elif preds[i][5]==pars['flagId']: #识别为国旗 preds_flag.append(preds[i]) # output_detection.append(preds[i]) - #jcq: - elif preds[i][5]==pars['uncoverId']: #识封仓 + elif preds[i][5]==pars['uncoverId']: #未封仓 preds_uncover.append(preds[i]) # output_detection.append(preds[i]) else: output_detection.append(preds[i]) # pass - + # return output_detection - - #jcq: 自动检测船只 - 0311 + #2、船尺寸与图像比较,其中长或宽有一个维度超过图像宽高平均值的1/3,启动国旗检测 #①if 判断:判断超过1/3的,则取出这些大船,进一步判断是否悬挂国旗 #不超过1/3的,则output_detection.append[] - - preds_boat_flag=[] - for i in range(len(preds_boat)): - length_bbx,width_bbx=get_rectangle_dimensions(preds_boat[i]) + + boat_uncover = preds_boat+preds_uncover + for i in range(len(boat_uncover)): + length_bbx,width_bbx=get_rectangle_dimensions(boat_uncover[i]) length_bbx, width_bbx=int(length_bbx),int(width_bbx) if length_bbx>(pars['imgSize'][0]+pars['imgSize'][1])* pars['hRation'] or width_bbx>(pars['imgSize'][0]+pars['imgSize'][1])*pars['wRation']: - preds_boat_flag.append(preds_boat[i]) - else: - output_detection.append(preds_boat[i]) - - - #②将大船的框与国旗检测结果的中心点坐标做比较。 - #若没有一个在,则输出此船未悬挂国旗(船舶类别名称改完未悬挂国旗就行,即将0、1、2、3中的0替换为4的类别) - # 未悬挂国旗的,则output_detection.append[xyxy_4_conf] - #若有国旗在,则不输出是否悬挂国旗,则output_detection.append[xyxy_0_conf] - - #jcq : 判断是否有国旗 - 具体判断方法使用交叉比 - for i in range(len(preds_boat_flag)): - preds_boat_flag_expand=expand_rect(preds_boat_flag[i],pars['recScale'],pars['imgSize']) #新增! - if point_in_rectangle(preds_flag,preds_boat_flag_expand)>=1: #新增后修改! - output_detection.append(preds_boat_flag[i]) - else: - temp_preds_boat_flag=preds_boat_flag[i] - temp_preds_boat_flag[5]=pars['newId'] #将类别标签改为4,即为未悬挂国旗的船只 - output_detection.append(temp_preds_boat_flag) - - - - - # jcq: 将大船的框与封仓检测结果的中心点坐标做比较。 -- 该步可以暂时不做,因为船只比封仓更容易检测出结果 - # 若未封仓,则输出此船未封仓(船舶类别名称改船只封仓,即将0、1、2、3中的3替换为未封仓的类别) - # 未封仓的,则output_detection.append[xyxy_4_conf] - # 若有国旗在,则不输出是否悬挂国旗,则output_detection.append[xyxy_0_conf] - - - preds_boat_uncover=[] #定义船只未封仓 - - for i in range(len(preds_boat)): - boat_boxes = [box for box in preds_boat] - uncover_boxes = [box for box in preds_uncover] + boat_uncover[i] = unflag(boat_uncover[i], preds_flag, pars) - for boat_box in boat_boxes: - if any( - - (uncover_box[0] >= boat_box[0] and - uncover_box[1] >= boat_box[1] and - uncover_box[2] <= boat_box[2] and - uncover_box[3] <= boat_box[3] ) - for uncover_box in uncover_boxes - ): - boat_uncover_box = boat_box.copy() - preds_boat_uncover.append(boat_uncover_box) - # else: - # output_detection.append(preds_boat[i]) - - - for i in range(len(preds_boat_uncover)): - - temp_preds_boat_uncover=preds_boat_uncover[i] - temp_preds_boat_uncover[5]=pars['uncoverId'] # - output_detection.append(temp_preds_boat_uncover) - - return output_detection + return output_detection + boat_uncover +def unflag(boat_uncover,preds_flag,pars): + + preds_boat_flag_expand = expand_rect(boat_uncover, pars['recScale'], pars['imgSize']) # 新增! + if not point_in_rectangle(preds_flag, preds_boat_flag_expand) >= 1: # 新增后修改! + if boat_uncover[5] == pars['uncoverId']: + + boat_uncover[5] = pars['unflagAndcoverId'] # 将类别标签改为6,未挂国旗且未封仓 + else: + boat_uncover[5] = pars['unflagId'] # 将类别标签改为4,即为未悬挂国旗的船只 + + return boat_uncover @@ -253,40 +211,31 @@ def expand_rect(preds_boat, recScale, imgSize): ###jcq : 增加封仓后处理函数 def filter_detection_results(results, par): - target_cls = par['target_cls'] - filter_cls = par['filter_cls'] + target_cls = par['target_cls'] # 船只 + filter_cls = par['filter_cls'] # 非封仓 # 分离处理与非处理的结果 non_process = [box for box in results if box[5] not in {target_cls, filter_cls}] to_process = [box for box in results if box[5] in {target_cls, filter_cls}] # 提取目标类别和过滤类别的检测框 - class_target = [box for box in to_process if box[5] == target_cls] - class_filter = [box for box in to_process if box[5] == filter_cls] + class_target = [box for box in to_process if box[5] == target_cls] # 船只 + class_filter = [box for box in to_process if box[5] == filter_cls] # 非封仓 - processed = [] # 处理过滤类别(映射条件) - for f_box in class_filter: + for i in range(len(class_target)): + t_box = class_target[i] if any( # 检查是否在任意目标框内部 - (f_box[0] >= t_box[0] and - f_box[1] >= t_box[1] and - f_box[2] <= t_box[2] and - f_box[3] <= t_box[3]) - for t_box in class_target + (t_box[0] <= f_box[0] and + t_box[1] <= f_box[1] and + t_box[2] >= f_box[2] and + t_box[3] >= f_box[3]) + for f_box in class_filter ): - new_box = f_box.copy() - new_box[5] = 5 # 映射类别4->5 - processed.append(new_box) - - # 保留所有目标类别检测框 - processed += class_target + class_target[i][5] = par['uncoverId'] # 映射类别4->5 # 合并结果(保留非处理类别) - return non_process + processed - - - - + return non_process + class_target def filter_detection_results_uncover(results, par): diff --git a/utilsK/cthcUtils.py b/utilsK/cthcUtils.py new file mode 100644 index 0000000..334d27f --- /dev/null +++ b/utilsK/cthcUtils.py @@ -0,0 +1,110 @@ +import numpy as np +import time, cv2 + + +def ms(t1, t0): + return (t1 - t0) * 1000.0 + + +def center_coordinate(boundbxs): + ''' + 输入:两个对角坐标xyxy + 输出:矩形框重点坐标xy + ''' + boundbxs_x1 = boundbxs[0] + boundbxs_y1 = boundbxs[1] + boundbxs_x2 = boundbxs[2] + boundbxs_y2 = boundbxs[3] + center_x = 0.5 * (boundbxs_x1 + boundbxs_x2) + center_y = 0.5 * (boundbxs_y1 + boundbxs_y2) + return center_x, center_y + + +def mixCthc_postprocess(preds, _mask_cv,pars=None): + '''考虑船上人过滤''' + '''输入:危化品的结果(类别+坐标)、原图、mask图像 + 过程:获得mask的轮廓,判断危化品是否在轮廓内。 + 在,则保留且绘制;不在,舍弃。 + 返回:最终绘制的结果图、最终危化品(坐标、类别、置信度), + ''' + '''1、最大分隔路面作为判断依据''' + # zoom_factor=4 #缩小因子设置为4,考虑到numpy中分别遍历xy进行缩放耗时大。 + # speedroad = _mask_cv.copy() + # speedroad = _mask_cv[speedroad==1] + # _mask_cv[0] = _mask_cv[1] + original_height = _mask_cv.shape[0] + original_width = _mask_cv.shape[1] + + zoom_factor = original_width / 480.0 + + zoom_height = int(original_height / zoom_factor) + zoom_width = int(original_width / zoom_factor) + + _mask_cv = cv2.resize(_mask_cv, (zoom_width, zoom_height)) # 缩小原图,宽在前,高在后 + t4 = time.time() + print('+' * 10, '_mask_cv shape信息', _mask_cv.shape) + img_gray = cv2.cvtColor(_mask_cv, cv2.COLOR_BGR2GRAY) if len(_mask_cv.shape) == 3 else _mask_cv # + t5 = time.time() + contours, thresh = cv2.threshold(img_gray, 0, 255, cv2.THRESH_BINARY + cv2.THRESH_OTSU) + + # 寻找轮廓(多边界) + contours, hierarchy = cv2.findContours(thresh, cv2.RETR_LIST, 2) + contour_info = [] + for c in contours: + contour_info.append(( + c, + cv2.isContourConvex(c), + cv2.contourArea(c), + )) + contour_info = sorted(contour_info, key=lambda c: c[2], reverse=True) + t6 = time.time() + + # print('+'*10,'路面分隔信息',len(contour_info)) + '''新增模块::如果路面为空,则返回原图、无危化品等。''' + if contour_info == []: + # final_img=_img_cv + final_Cthc_filterroad = [] + timeInfos = 0 + + return final_Cthc_filterroad, timeInfos + else: + # print(contour_info[0]) + max_contour = contour_info[0] + max_contour = max_contour[0] * zoom_factor # contours恢复原图尺寸 + max_contour = max_contour.astype(np.int32) + # print(max_contour) + t7 = time.time() + + '''2.1、preds中Cthc取出,car取出。''' + init_Cthc = [] + # init_car = [] + for i in range(len(preds)): + if preds[i][5] == 0: + init_Cthc.append(preds[i]) + # elif preds[i][5] == 3: + # init_car.append(preds[i]) + # person + + # points = max_contour.reshape((-1, 1, 2)) + # cv2.polylines(image, [points], isClosed=True, color=(0, 255, 0), thickness=2) + + '''3、preds中Cthc,通过1中路面过滤''' + init_Cthc_filterroad = init_Cthc + final_Cthc_filterroad = [] + for i in range(len(init_Cthc_filterroad)): + center_x, center_y = center_coordinate(init_Cthc_filterroad[i]) + # print('#'*20,'line176:',len(max_contour),np.array(max_contour).shape,(center_x, center_y)) + # 返回 1、-1 或 0,分别对应点在多边形内部、外部或边界上的情况 + flag = cv2.pointPolygonTest(max_contour, (int(center_x), int(center_y)), + False) # 若为False,会找点是否在内,外,或轮廓上(相应返回+1, -1, 0)。 + if flag == 1: + final_Cthc_filterroad.append(init_Cthc_filterroad[i]) + else: + pass + t9 = time.time() + + timeInfos = ' findMaxroad:%.1f releJudge:%.1f' % (ms(t6, t4), ms(t9, t6)) + + return final_Cthc_filterroad, timeInfos # 返回最终绘制的结果图、危化品(坐标、类别、置信度) + + diff --git a/utilsK/pannelpostUtils.py b/utilsK/pannelpostUtils.py new file mode 100644 index 0000000..1a08eb5 --- /dev/null +++ b/utilsK/pannelpostUtils.py @@ -0,0 +1,107 @@ +import cv2 +import numpy as np +import torch +# from loguru import logger + +def pannel_post_process(preds, pars): + # pars={'solar':0} + ''' + 将光伏板上覆盖物、裂缝识别出来 + ''' + # print(preds[0]) + # logger.info('\n分类结果返回:%s'%preds) + preds = torch.tensor(preds[0]) + preds = preds.tolist() + preds = [[*sublist[:-1], int(sublist[-1])] for sublist in preds] # 类别从浮点型转为整型 + # print(preds) + # 设置空的列表 + # 1、判断类别中哪些有太阳能板?取出太阳能板检测结果,并取出覆盖物、裂缝检测结果。 + preds_solar = [] + preds_others = [] + for i in range(len(preds)): + if preds[i][5] in pars['objs']: # 识别为光伏板 + preds_solar.append(preds[i]) + else: # 识别为裂缝、覆盖物 + preds_others.append(preds[i]) + + return point_in_rectangle(preds_others, preds_solar) + + +def center_coordinate(boundbxs): + ''' + 根据检测矩形框,得到其矩形长度和宽度 + 输入:两个对角坐标xyxy + 输出:矩形框重点坐标xy + ''' + boundbxs_x1 = boundbxs[0] + boundbxs_y1 = boundbxs[1] + boundbxs_x2 = boundbxs[2] + boundbxs_y2 = boundbxs[3] + center_x = 0.5 * (boundbxs_x1 + boundbxs_x2) + center_y = 0.5 * (boundbxs_y1 + boundbxs_y2) + return center_x, center_y + + +def fourcorner_coordinate(boundbxs): + ''' + 通过矩形框对角xyxy坐标,得到矩形框轮廓 + 输入:两个对角坐标xyxy + 输出:矩形框四个角点坐标,以contours顺序。 + ''' + boundbxs_x1 = boundbxs[0] + boundbxs_y1 = boundbxs[1] + boundbxs_x2 = boundbxs[2] + boundbxs_y2 = boundbxs[3] + wid = boundbxs_x2 - boundbxs_x1 + hei = boundbxs_y2 - boundbxs_y1 + boundbxs_x3 = boundbxs_x1 + wid + boundbxs_y3 = boundbxs_y1 + boundbxs_x4 = boundbxs_x1 + boundbxs_y4 = boundbxs_y1 + hei + contours_rec = [[boundbxs_x1, boundbxs_y1], [boundbxs_x3, boundbxs_y3], [boundbxs_x2, boundbxs_y2], + [boundbxs_x4, boundbxs_y4]] + return contours_rec + + +def point_in_rectangle(preds_others, preds_solar): + ''' + 遍历所有光伏板异常目标,并输出 + ''' + if not preds_solar: + return [[],''] + + preds = [] + for i in range(len(preds_others)): + for solar in preds_solar: + solar_contour = fourcorner_coordinate(solar) + solar_contour = np.array(solar_contour, dtype=np.float32) + center_x, center_y = center_coordinate(preds_others[i]) + # print(cv2.pointPolygonTest(solar_contour, (center_x, center_y), False)) + if cv2.pointPolygonTest(solar_contour, (center_x, center_y), False) == 1: + preds.append(preds_others[i]) + + # logger.info('\n分类结果返回:%s' % preds) + return [preds,''] + + +if __name__ == "__main__": + # 对应DJI_20230306140129_0001_Z_165.jpg检测结果 + # preds=[[6.49000e+02, 2.91000e+02, 1.07900e+03, 7.33000e+02, 9.08165e-01, 3.00000e+00], + # [8.11000e+02, 2.99000e+02, 1.31200e+03, 7.65000e+02, 8.61268e-01, 3.00000e+00], + # [7.05000e+02, 1.96000e+02, 7.19000e+02, 2.62000e+02, 5.66877e-01, 0.00000e+00]] + + # 对应DJI_20230306152702_0001_Z_562.jpg检测结果 + preds = [[7.62000e+02, 7.14000e+02, 1.82800e+03, 9.51000e+02, 9.00902e-01, 3.00000e+00], + [2.00000e+01, 3.45000e+02, 1.51300e+03, 6.71000e+02, 8.81440e-01, 3.00000e+00], + [8.35000e+02, 8.16000e+02, 8.53000e+02, 8.30000e+02, 7.07651e-01, 0.00000e+00], + [1.35600e+03, 4.56000e+02, 1.42800e+03, 4.94000e+02, 6.70549e-01, 2.00000e+00]] + print('before :\n ', preds) + # preds=torch.tensor(preds) #返回的预测结果 + imgwidth = 1920 + imgheight = 1680 + pars = {'imgSize': (imgwidth, imgheight), 'wRation': 1 / 6.0, 'hRation': 1 / 6.0, 'smallId': 0, 'bigId': 3, + 'newId': 4, 'recScale': 1.2} + # 'smallId':0(国旗),'bigId':3(船只),wRation和hRation表示判断的阈值条件,newId--新目标的id + # yyy = channel2_post_process([preds], pars) # 送入后处理函数 + # + # print('after :\n ', yyy) diff --git a/utilsK/spillUtils.py b/utilsK/spillUtils.py index e7d4c48..0fa8961 100644 --- a/utilsK/spillUtils.py +++ b/utilsK/spillUtils.py @@ -21,7 +21,7 @@ def center_coordinate(boundbxs): -def mixSpillage_postprocess(allModelPreds,pars=None): +def mixSpillage_postprocess(preds, _mask_cv,pars=None): '''考虑船上人过滤''' '''输入:抛洒物的结果(类别+坐标)、原图、mask图像 过程:获得mask的轮廓,判断抛洒物是否在轮廓内。 @@ -33,9 +33,6 @@ def mixSpillage_postprocess(allModelPreds,pars=None): # speedroad = _mask_cv.copy() # speedroad = _mask_cv[speedroad==1] # _mask_cv[0] = _mask_cv[1] - - preds = allModelPreds[0] - _mask_cv = allModelPreds[1] original_height = _mask_cv.shape[0] original_width = _mask_cv.shape[1] @@ -81,12 +78,12 @@ def mixSpillage_postprocess(allModelPreds,pars=None): '''2.1、preds中spillage取出,car取出。''' init_spillage = [] - init_car_per = [] + # init_car_per = [] for i in range(len(preds)): if preds[i][5] == 0: init_spillage.append(preds[i]) - else: - init_car_per.append(preds[i]) + # else: + # init_car_per.append(preds[i]) #print('-'*10,'车辆',len(init_car_per)) #print('+'*10,'抛洒物',len(init_spillage)) #print('+'*10,'路面分隔信息',len(max_contour)) @@ -113,6 +110,6 @@ def mixSpillage_postprocess(allModelPreds,pars=None): timeInfos = ' findMaxroad:%.1f releJudge:%.1f' % (ms(t6, t4), ms(t9, t6)) - return final_spillage_filterroad, timeInfos # 返回最终绘制的结果图、最终落水人员(坐标、类别、置信度) + return final_spillage_filterroad, timeInfos # 返回最终绘制的结果图、最高速搞萨物(坐标、类别、置信度) diff --git a/voduploadsdk/__pycache__/AliyunVodUploader.cpython-38.pyc b/voduploadsdk/__pycache__/AliyunVodUploader.cpython-38.pyc deleted file mode 100644 index 0022e16..0000000 Binary files a/voduploadsdk/__pycache__/AliyunVodUploader.cpython-38.pyc and /dev/null differ diff --git a/voduploadsdk/__pycache__/AliyunVodUtils.cpython-38.pyc b/voduploadsdk/__pycache__/AliyunVodUtils.cpython-38.pyc deleted file mode 100644 index 21a4b0a..0000000 Binary files a/voduploadsdk/__pycache__/AliyunVodUtils.cpython-38.pyc and /dev/null differ diff --git a/voduploadsdk/__pycache__/UploadAttachedMediaRequest.cpython-38.pyc b/voduploadsdk/__pycache__/UploadAttachedMediaRequest.cpython-38.pyc deleted file mode 100644 index 1ff2ce9..0000000 Binary files a/voduploadsdk/__pycache__/UploadAttachedMediaRequest.cpython-38.pyc and /dev/null differ diff --git a/voduploadsdk/__pycache__/UploadImageRequest.cpython-38.pyc b/voduploadsdk/__pycache__/UploadImageRequest.cpython-38.pyc deleted file mode 100644 index 47b84f9..0000000 Binary files a/voduploadsdk/__pycache__/UploadImageRequest.cpython-38.pyc and /dev/null differ diff --git a/voduploadsdk/__pycache__/UploadVideoRequest.cpython-38.pyc b/voduploadsdk/__pycache__/UploadVideoRequest.cpython-38.pyc deleted file mode 100644 index 5c7233a..0000000 Binary files a/voduploadsdk/__pycache__/UploadVideoRequest.cpython-38.pyc and /dev/null differ diff --git a/voduploadsdk/__pycache__/__init__.cpython-38.pyc b/voduploadsdk/__pycache__/__init__.cpython-38.pyc deleted file mode 100644 index 5de1595..0000000 Binary files a/voduploadsdk/__pycache__/__init__.cpython-38.pyc and /dev/null differ