190 lines
4.5 KiB
Python
190 lines
4.5 KiB
Python
# -*- coding: utf-8 -*-
|
|
"""
|
|
Created on Sun Sep 29 08:59:21 2024
|
|
|
|
@author: ym
|
|
"""
|
|
import os
|
|
import cv2
|
|
import pickle
|
|
from pathlib import Path
|
|
from track_reid import parse_opt, yolo_resnet_tracker
|
|
|
|
from tracking.dotrack.dotracks_back import doBackTracks
|
|
from tracking.dotrack.dotracks_front import doFrontTracks
|
|
|
|
IMGFORMATS = '.bmp', '.jpeg', '.jpg', 'png', 'tif', 'tiff', 'webp', 'pfm'
|
|
VIDFORMATS = '.avi', '.gif', '.m4v', '.mkv', '.mov', '.mp4', '.ts', '.wmv'
|
|
|
|
std_feature_path = r"\\192.168.1.28\share\测试_202406\contrast\std_features_2192_ft32vsft16"
|
|
|
|
|
|
opt = parse_opt()
|
|
optdict = vars(opt)
|
|
|
|
|
|
|
|
|
|
|
|
def get_interbcd_inputenents():
|
|
bcdpath = r"\\192.168.1.28\share\测试_202406\contrast\std_barcodes_2192"
|
|
eventpath = r"\\192.168.1.28\share\测试_202406\0918"
|
|
|
|
barcodes = []
|
|
eventpaths = []
|
|
for featname in os.listdir(bcdpath):
|
|
barcode, ext = os.path.splitext(featname)
|
|
barcodes.append(barcode)
|
|
|
|
input_enents = []
|
|
for root, dirs, files in os.walk(eventpath):
|
|
input_enent = [os.path.join(root, d) for d in dirs if d.split('_')[-1] in barcodes]
|
|
|
|
input_enents.extend(input_enent)
|
|
|
|
|
|
return input_enents
|
|
|
|
|
|
|
|
def get_video_pairs(vpath):
|
|
vdieopath = []
|
|
for filename in os.listdir(vpath):
|
|
file, ext = os.path.splitext(filename)
|
|
if ext in VIDFORMATS:
|
|
vdieopath.append(os.path.join(vpath, filename))
|
|
return vdieopath
|
|
|
|
def pipeline(eventpath, stdfeat_path):
|
|
# eventpath = r"\\192.168.1.28\share\测试_202406\0918\images1\20240918-110822-1bc3902e-5a8e-4e23-8eca-fb3f02738551_6938314601726"
|
|
|
|
savepath = r"D:\contrast\detect"
|
|
|
|
optdict["project"] = savepath
|
|
|
|
eventname = os.path.basename(eventpath)
|
|
barcode = eventname.split('_')[-1]
|
|
|
|
|
|
vpaths = get_video_pairs(eventpath)
|
|
event_tracks = []
|
|
for vpath in vpaths:
|
|
|
|
'''事件结果文件夹'''
|
|
save_dir_event = Path(savepath) / Path(eventname)
|
|
save_dir_img = save_dir_event / Path(str(Path(vpath).stem))
|
|
if not save_dir_img.exists():
|
|
save_dir_img.mkdir(parents=True, exist_ok=True)
|
|
|
|
'''Yolo + Resnet + Tracker'''
|
|
optdict["source"] = vpath
|
|
optdict["save_dir"] = save_dir_img
|
|
optdict["nosave"] = False
|
|
|
|
tracksdict = yolo_resnet_tracker(**optdict)
|
|
|
|
bboxes = tracksdict['TrackBoxes']
|
|
|
|
bname = os.path.basename(vpath)
|
|
if bname.split('_')[0] == "0" or bname.find('back')>=0:
|
|
vts = doFrontTracks(bboxes, tracksdict)
|
|
vts.classify()
|
|
|
|
event_tracks.append(("back", vts))
|
|
|
|
if bname.split('_')[0] == "1" or bname.find('front')>=0:
|
|
vts = doBackTracks(bboxes, tracksdict)
|
|
vts.classify()
|
|
event_tracks.append(("front", vts))
|
|
|
|
|
|
for CamerType, vts in event_tracks:
|
|
if CamerType == 'back':
|
|
pass
|
|
if CamerType == 'front':
|
|
pass
|
|
|
|
'''前后摄轨迹选择'''
|
|
|
|
|
|
if stdfeat_path is not None:
|
|
with open(stdfeat_path, 'rb') as f:
|
|
featDict = pickle.load(f)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
def main():
|
|
bcdpath = r"\\192.168.1.28\share\测试_202406\contrast\std_barcodes_2192"
|
|
eventpath = r"\\192.168.1.28\share\测试_202406\0918\images1"
|
|
|
|
|
|
barcodes = []
|
|
input_enents = []
|
|
output_events = []
|
|
|
|
|
|
# input_enents = get_interbcd_inputenents()
|
|
# k = 0
|
|
# for event in input_enents:
|
|
# pipeline(event)
|
|
|
|
# k += 1
|
|
# if k ==1:
|
|
# break
|
|
|
|
|
|
'''1. 获得barcode标准特征集列表'''
|
|
for featname in os.listdir(bcdpath):
|
|
barcode, ext = os.path.splitext(featname)
|
|
if not barcode.isdigit() or len(barcode)<=8 or ext != ".pickle" :
|
|
continue
|
|
barcodes.append(barcode)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
for filename in os.listdir(eventpath):
|
|
bcd = filename.split('_')[-1]
|
|
|
|
event_path = os.path.join(eventpath, filename)
|
|
stdfeat_path = None
|
|
if bcd in barcodes:
|
|
stdfeat_path = os.path.join(bcdpath, f"{bcd}.pickle")
|
|
|
|
input_enents.append((event_path, stdfeat_path))
|
|
|
|
|
|
|
|
|
|
for eventpath, stdfeat_path in input_enents:
|
|
pipeline(eventpath, stdfeat_path)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if __name__ == "__main__":
|
|
main() |