bakeup
This commit is contained in:
Binary file not shown.
Binary file not shown.
@ -114,7 +114,7 @@ def draw_all_trajectories(vts, edgeline, save_dir, file, draw5p=False):
|
||||
img = edgeline.copy()
|
||||
img = draw5points(track, img)
|
||||
|
||||
pth = trackpth.joinpath(f"{file}_{track.tid}.png")
|
||||
pth = trackpth.joinpath(f"{file}_{track.tid}_.png")
|
||||
cv2.imwrite(str(pth), img)
|
||||
|
||||
# for track in vts.Residual:
|
||||
@ -307,11 +307,13 @@ def draw5points(track, img):
|
||||
|
||||
|
||||
'''=============== 最小轨迹长度索引 ===================='''
|
||||
if track.isBorder:
|
||||
trajlens = [int(t) for t in track.trajrects_wh]
|
||||
if track.isCornpoint:
|
||||
idx = 0
|
||||
else:
|
||||
idx = trajlens.index(min(trajlens))
|
||||
|
||||
|
||||
'''=============== PCA ===================='''
|
||||
if trajlens[idx] > 12:
|
||||
X = cornpoints[:, 2*idx:2*(idx+1)]
|
||||
|
@ -9,7 +9,8 @@ func: extract_data()
|
||||
import numpy as np
|
||||
import re
|
||||
import os
|
||||
|
||||
from collections import OrderedDict
|
||||
import matplotlib.pyplot as plt
|
||||
|
||||
|
||||
|
||||
@ -206,19 +207,130 @@ def read_deletedBarcode_file(filePth):
|
||||
return all_list
|
||||
|
||||
|
||||
def read_weight_timeConsuming(filePth):
|
||||
WeightDict, SensorDict, ProcessTimeDict = OrderedDict(), OrderedDict(), OrderedDict()
|
||||
|
||||
with open(filePth, 'r', encoding='utf-8') as f:
|
||||
lines = f.readlines()
|
||||
for i, line in enumerate(lines):
|
||||
line = line.strip()
|
||||
|
||||
if line.find(':') < 0: continue
|
||||
if line.find("Weight") >= 0:
|
||||
label = "Weight"
|
||||
continue
|
||||
if line.find("Sensor") >= 0:
|
||||
label = "Sensor"
|
||||
continue
|
||||
if line.find("processTime") >= 0:
|
||||
label = "ProcessTime"
|
||||
continue
|
||||
|
||||
keyword = line.split(':')[0]
|
||||
value = line.split(':')[1]
|
||||
|
||||
if label == "Weight":
|
||||
WeightDict[keyword] = float(value.strip(','))
|
||||
if label == "Sensor":
|
||||
SensorDict[keyword] = [float(s) for s in value.split(',') if len(s)]
|
||||
if label == "ProcessTime":
|
||||
ProcessTimeDict[keyword] = float(value.strip(','))
|
||||
|
||||
# print("Done!")
|
||||
return WeightDict, SensorDict, ProcessTimeDict
|
||||
|
||||
|
||||
def plot_sensor_curve(WeightDict, SensorDict, ProcessTimeDict):
|
||||
|
||||
wtime, wdata = [], []
|
||||
stime, sdata = [], []
|
||||
for key, value in WeightDict.items():
|
||||
wtime.append(int(key))
|
||||
wdata.append(value)
|
||||
|
||||
for key, value in SensorDict.items():
|
||||
if len(value) != 9: continue
|
||||
|
||||
stime.append(int(key))
|
||||
sdata.append(np.array(value))
|
||||
|
||||
static_range = []
|
||||
dynamic_range = []
|
||||
windth = 8
|
||||
nw = len(wdata)
|
||||
assert(nw) >= 8, "The num of weight data is less than 8!"
|
||||
|
||||
i1, i2 = 0, 7
|
||||
while i2 < nw:
|
||||
data = wdata[i1:(i2+1)]
|
||||
max(data) - min(data)
|
||||
|
||||
if i2<7:
|
||||
i1 = 0
|
||||
else:
|
||||
i1 = i2-windth
|
||||
|
||||
min_t = min(wtime + stime)
|
||||
wtime = [t-min_t for t in wtime]
|
||||
stime = [t-min_t for t in stime]
|
||||
|
||||
max_t = max(wtime + stime)
|
||||
|
||||
fig = plt.figure(figsize=(16, 12))
|
||||
gs = fig.add_gridspec(2, 1, left=0.1, right=0.9, bottom=0.1, top=0.9,
|
||||
wspace=0.05, hspace=0.15)
|
||||
# ax1, ax2 = axs
|
||||
|
||||
ax1 = fig.add_subplot(gs[0,0])
|
||||
ax2 = fig.add_subplot(gs[1,0])
|
||||
|
||||
ax1.plot(wtime, wdata, 'b--', linewidth=2 )
|
||||
for i in range(9):
|
||||
ydata = [s[i] for s in sdata]
|
||||
ax2.plot(stime, ydata, linewidth=2 )
|
||||
|
||||
ax1.grid(True), ax1.set_xlim(0, max_t), ax1.set_title('Weight')
|
||||
ax1.set_label("(Time: ms)")
|
||||
# ax1.legend()
|
||||
|
||||
ax2.grid(True), ax2.set_xlim(0, max_t), ax2.set_title('IMU')
|
||||
# ax2.legend()
|
||||
|
||||
plt.show()
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
def main(file_path):
|
||||
WeightDict, SensorDict, ProcessTimeDict = read_weight_timeConsuming(file_path)
|
||||
plot_sensor_curve(WeightDict, SensorDict, ProcessTimeDict)
|
||||
|
||||
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
files_path = 'D:/contrast/dataset/1_to_n/709/20240709-112658_6903148351833/'
|
||||
|
||||
# 遍历目录下的所有文件和目录
|
||||
files_path = r'\\192.168.1.28\share\测试_202406\0814\0814\20240814-102227-62264578-a720-4eb9-b95e-cb8be009aa98_null'
|
||||
k = 0
|
||||
for filename in os.listdir(files_path):
|
||||
filename = '1_track.data'
|
||||
filename = 'process.data'
|
||||
|
||||
file_path = os.path.join(files_path, filename)
|
||||
if os.path.isfile(file_path) and filename.find("track.data")>0:
|
||||
extract_data(file_path)
|
||||
|
||||
print("Done")
|
||||
|
||||
if os.path.isfile(file_path) and filename.find("process.data")>=0:
|
||||
main(file_path)
|
||||
|
||||
k += 1
|
||||
if k == 1:
|
||||
break
|
||||
|
||||
|
||||
|
||||
# print("Done")
|
||||
|
||||
|
||||
|
||||
|
35
tracking/utils/rename.py
Normal file
35
tracking/utils/rename.py
Normal file
@ -0,0 +1,35 @@
|
||||
# -*- coding: utf-8 -*-
|
||||
"""
|
||||
Created on Sat Jun 8 09:51:59 2024
|
||||
|
||||
@author: ym
|
||||
"""
|
||||
import os
|
||||
|
||||
def main():
|
||||
directory = r'D:\DetectTracking\runs\detect'
|
||||
directory = r'D:\DetectTracking\tracking\result\tracks'
|
||||
|
||||
suffix = '_'
|
||||
|
||||
for root, dirs, files in os.walk(directory):
|
||||
for name in dirs:
|
||||
old_name = os.path.join(root, name)
|
||||
new_name = os.path.join(root, f"{name}{suffix}")
|
||||
try:
|
||||
os.rename(old_name, new_name)
|
||||
except Exception as e:
|
||||
print(f"Failed to rename directory '{old_name}': {e}")
|
||||
|
||||
for name in files:
|
||||
old_name = os.path.join(root, name)
|
||||
file, ext = os.path.splitext(name)
|
||||
new_name = os.path.join(root, f"{file}{suffix}{ext}")
|
||||
try:
|
||||
os.rename(old_name, new_name)
|
||||
except Exception as e:
|
||||
print(f"Failed to rename file '{old_name}': {e}")
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
main()
|
@ -14,38 +14,23 @@ import cv2
|
||||
# import sys
|
||||
# from scipy.spatial.distance import cdist
|
||||
|
||||
VideoFormat = ['.mp4', '.avi']
|
||||
def video2imgs(videopath, savepath):
|
||||
k = 0
|
||||
have = False
|
||||
for filename in os.listdir(videopath):
|
||||
file, ext = os.path.splitext(filename)
|
||||
if ext not in VideoFormat:
|
||||
continue
|
||||
|
||||
basename = os.path.basename(videopath)
|
||||
imgbase = basename + '_' + file
|
||||
imgdir = os.path.join(savepath, imgbase)
|
||||
if not os.path.exists(imgdir):
|
||||
os.mkdir(imgdir)
|
||||
|
||||
video = os.path.join(videopath, filename)
|
||||
cap = cv2.VideoCapture(video)
|
||||
i = 0
|
||||
while True:
|
||||
ret, frame = cap.read()
|
||||
if not ret:
|
||||
break
|
||||
imgp = os.path.join(imgdir, file+f"_{i}.png")
|
||||
i += 1
|
||||
cv2.imwrite(imgp, frame)
|
||||
cap.release()
|
||||
|
||||
print(filename + f" haved resolved")
|
||||
|
||||
k+=1
|
||||
if k==1000:
|
||||
VideoFormat = ['.mp4', '.avi', '.ts']
|
||||
def video2imgs(videof, imgdir):
|
||||
cap = cv2.VideoCapture(videof)
|
||||
i = 0
|
||||
while True:
|
||||
ret, frame = cap.read()
|
||||
if not ret:
|
||||
break
|
||||
imgp = os.path.join(imgdir, f"{i}.png")
|
||||
i += 1
|
||||
cv2.imwrite(imgp, frame)
|
||||
|
||||
if i == 400:
|
||||
break
|
||||
cap.release()
|
||||
|
||||
print(os.path.basename(videof) + f" haved resolved")
|
||||
|
||||
def videosave(bboxes, videopath="100_1688009697927.mp4"):
|
||||
|
||||
@ -95,10 +80,30 @@ def videosave(bboxes, videopath="100_1688009697927.mp4"):
|
||||
cap.release()
|
||||
|
||||
def main():
|
||||
videopath = r'C:\Users\ym\Desktop'
|
||||
savepath = r'C:\Users\ym\Desktop'
|
||||
video2imgs(videopath, savepath)
|
||||
|
||||
videopath = r'\\192.168.1.28\share\测试_202406\0822\A_1724314806144'
|
||||
savepath = r'D:\badvideo'
|
||||
# video2imgs(videopath, savepath)
|
||||
k = 0
|
||||
for filename in os.listdir(videopath):
|
||||
filename = "20240822-163506_88e6409d-f19b-4e97-9f01-b3fde259cbff.ts"
|
||||
|
||||
file, ext = os.path.splitext(filename)
|
||||
if ext not in VideoFormat:
|
||||
continue
|
||||
|
||||
basename = os.path.basename(videopath)
|
||||
imgbase = basename + '-&-' + file
|
||||
imgdir = os.path.join(savepath, imgbase)
|
||||
if not os.path.exists(imgdir):
|
||||
os.mkdir(imgdir)
|
||||
|
||||
videof = os.path.join(videopath, filename)
|
||||
video2imgs(videof, imgdir)
|
||||
|
||||
k += 1
|
||||
if k == 1:
|
||||
break
|
||||
|
||||
|
||||
|
||||
if __name__ == '__main__':
|
||||
|
Reference in New Issue
Block a user