update for bakeup
This commit is contained in:
Binary file not shown.
Binary file not shown.
Binary file not shown.
@ -24,6 +24,8 @@ class TrackAnnotator(Annotator):
|
||||
frame_index: 帧索引,从 1 开始计数
|
||||
cls:类别编号,从 0 开始计数,用作 names 的 key 值
|
||||
"""
|
||||
|
||||
if track.size==0: return
|
||||
|
||||
id, cls = track[0, 4], track[0, 6]
|
||||
if id >=0 and cls==0:
|
||||
@ -51,6 +53,8 @@ class TrackAnnotator(Annotator):
|
||||
"""
|
||||
绘制选定 track 的轨迹
|
||||
"""
|
||||
if track.size==0: return
|
||||
|
||||
x, y = int((track[0]+track[2])/2), int((track[1]+track[3])/2)
|
||||
|
||||
cv2.circle(self.im, (x, y), 6, color, 2)
|
||||
|
@ -94,19 +94,19 @@ def draw_all_trajectories(vts, edgeline, save_dir, file, draw5p=False):
|
||||
img1 = drawTrack(vts.tracks, img1)
|
||||
img2 = drawTrack(vts.Residual, img2)
|
||||
|
||||
img = np.concatenate((img1, img2), axis = 1)
|
||||
H, W = img.shape[:2]
|
||||
cv2.line(img, (int(W/2), 0), (int(W/2), H), (128, 255, 128), 2)
|
||||
imgcat = np.concatenate((img1, img2), axis = 1)
|
||||
H, W = imgcat.shape[:2]
|
||||
cv2.line(imgcat, (int(W/2), 0), (int(W/2), H), (128, 255, 128), 2)
|
||||
|
||||
|
||||
# imgpth = save_dir.joinpath(f"{file}_show.png")
|
||||
# cv2.imwrite(str(imgpth), img)
|
||||
|
||||
if not draw5p:
|
||||
return img
|
||||
return imgcat
|
||||
|
||||
''' tracks 5点轨迹'''
|
||||
trackpth = save_dir / Path("trajectory") / Path(f"{file}")
|
||||
trackpth = save_dir / Path("trajectory")
|
||||
if not trackpth.exists():
|
||||
trackpth.mkdir(parents=True, exist_ok=True)
|
||||
for track in vts.tracks:
|
||||
@ -114,19 +114,20 @@ def draw_all_trajectories(vts, edgeline, save_dir, file, draw5p=False):
|
||||
img = edgeline.copy()
|
||||
img = draw5points(track, img)
|
||||
|
||||
pth = trackpth.joinpath(f"{track.tid}.png")
|
||||
pth = trackpth.joinpath(f"{file}_{track.tid}.png")
|
||||
cv2.imwrite(str(pth), img)
|
||||
|
||||
for track in vts.merged_tracks:
|
||||
# if track.cls != 0:
|
||||
img = edgeline.copy()
|
||||
img = draw5points(track, img)
|
||||
# for track in vts.Residual:
|
||||
# # if track.cls != 0:
|
||||
# img = edgeline.copy()
|
||||
# img = draw5points(track, img)
|
||||
|
||||
pth = trackpth.joinpath(f"{track.tid}_.png")
|
||||
cv2.imwrite(str(pth), img)
|
||||
# pth = trackpth.joinpath(f"{file}_{track.tid}_.png")
|
||||
# cv2.imwrite(str(pth), img)
|
||||
|
||||
return imgcat
|
||||
|
||||
|
||||
|
||||
|
||||
# =============================================================================
|
||||
# '''3. moving tracks 中心轨迹'''
|
||||
# filename2 = f"{file}_show_r.png"
|
||||
@ -306,7 +307,7 @@ def draw5points(track, img):
|
||||
|
||||
|
||||
'''=============== 最小轨迹长度索引 ===================='''
|
||||
if track.imgBorder:
|
||||
if track.isBorder:
|
||||
idx = 0
|
||||
else:
|
||||
idx = trajlens.index(min(trajlens))
|
||||
|
@ -30,6 +30,8 @@ def find_samebox_in_array(arr, target):
|
||||
return i
|
||||
return -1
|
||||
|
||||
import warnings
|
||||
|
||||
|
||||
def extract_data(datapath):
|
||||
bboxes, ffeats = [], []
|
||||
@ -47,6 +49,17 @@ def extract_data(datapath):
|
||||
if line.find("CameraId")>=0:
|
||||
if len(boxes): bboxes.append(np.array(boxes))
|
||||
if len(feats): ffeats.append(np.array(feats))
|
||||
|
||||
# with warnings.catch_warnings(record=True) as w:
|
||||
# if len(boxes): bboxes.append(np.array(boxes))
|
||||
# if len(feats): ffeats.append(np.array(feats))
|
||||
# if w:
|
||||
# print(f"捕获到 {len(w)} 个警告:")
|
||||
# for warning in w:
|
||||
# print(f"警告类型: {warning.category}")
|
||||
# print(f"警告消息: {warning.message}")
|
||||
# print(f"警告发生的地方: {warning.filename}:{warning.lineno}")
|
||||
|
||||
if len(tboxes):
|
||||
trackerboxes = np.concatenate((trackerboxes, np.array(tboxes)))
|
||||
if len(tfeats):
|
||||
@ -56,16 +69,20 @@ def extract_data(datapath):
|
||||
|
||||
if line.find("box:") >= 0 and line.find("output_box:") < 0:
|
||||
box = line[line.find("box:") + 4:].strip()
|
||||
# if len(box)==6:
|
||||
boxes.append(str_to_float_arr(box))
|
||||
|
||||
if line.find("feat:") >= 0:
|
||||
feat = line[line.find("feat:") + 5:].strip()
|
||||
# if len(feat)==256:
|
||||
feats.append(str_to_float_arr(feat))
|
||||
|
||||
if line.find("output_box:") >= 0:
|
||||
box = str_to_float_arr(line[line.find("output_box:") + 11:].strip())
|
||||
tboxes.append(box) # 去掉'output_box:'并去除可能的空白字符
|
||||
index = find_samebox_in_array(boxes, box)
|
||||
|
||||
assert(len(boxes)==len(feats)), f"{datapath}, {datapath}, len(boxes)!=len(feats)"
|
||||
if index >= 0:
|
||||
# feat_f = str_to_float_arr(input_feats[index])
|
||||
feat_f = feats[index]
|
||||
@ -120,7 +137,7 @@ def extract_data(datapath):
|
||||
tracking_feat_dict[f"track_{tid}"]= {"feats": {}}
|
||||
tracking_feat_dict[f"track_{tid}"]["feats"].update({f"{fid}_{bid}": tracker_feat_dict[f"frame_{fid}"]["feats"][bid]})
|
||||
except Exception as e:
|
||||
print(f'Path: {datapath}, Error: {e}')
|
||||
print(f'Path: {datapath}, tracking_feat_dict can not be structured correcttly, Error: {e}')
|
||||
|
||||
return bboxes, ffeats, trackerboxes, tracker_feat_dict, trackingboxes, tracking_feat_dict
|
||||
|
||||
@ -142,6 +159,8 @@ def read_tracking_output(filepath):
|
||||
boxes.append(data)
|
||||
if data.size == 256:
|
||||
feats.append(data)
|
||||
|
||||
assert(len(feats)==len(boxes)), f"{filepath}, len(feats)!=len(boxes)"
|
||||
|
||||
return np.array(boxes), np.array(feats)
|
||||
|
||||
@ -166,16 +185,9 @@ def read_deletedBarcode_file(filePth):
|
||||
dict, barcode_list, similarity_list = {}, [], []
|
||||
continue
|
||||
|
||||
# print(line)
|
||||
try:
|
||||
label = line.split(':')[0]
|
||||
value = line.split(':')[1]
|
||||
except Exception as e:
|
||||
print(f'Error: {e}')
|
||||
|
||||
|
||||
|
||||
|
||||
if line.find(':')<0: continue
|
||||
label = line.split(':')[0]
|
||||
value = line.split(':')[1]
|
||||
|
||||
if label == 'SeqDir':
|
||||
dict['SeqDir'] = value
|
||||
|
@ -14,30 +14,38 @@ import cv2
|
||||
# import sys
|
||||
# from scipy.spatial.distance import cdist
|
||||
|
||||
|
||||
def video2imgs(videopath):
|
||||
# =============================================================================
|
||||
# videopath:视频文件地址,在该地址的 "/file_imgs/" 文件加下存储视频帧图像
|
||||
# =============================================================================
|
||||
|
||||
path, filename = os.path.split(videopath)
|
||||
file, ext = os.path.splitext(filename)
|
||||
|
||||
savepath = os.path.join(path, "{}_imgs".format(file))
|
||||
if not os.path.exists(savepath):
|
||||
os.makedirs(savepath)
|
||||
|
||||
cap = cv2.VideoCapture(videopath)
|
||||
VideoFormat = ['.mp4', '.avi']
|
||||
def video2imgs(videopath, savepath):
|
||||
k = 0
|
||||
while True:
|
||||
ret, frame = cap.read()
|
||||
if not ret:
|
||||
break
|
||||
|
||||
k += 1
|
||||
cv2.imwrite(os.path.join(savepath, "{}.png".format(k)), frame)
|
||||
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:
|
||||
break
|
||||
|
||||
def videosave(bboxes, videopath="100_1688009697927.mp4"):
|
||||
|
||||
@ -84,4 +92,15 @@ def videosave(bboxes, videopath="100_1688009697927.mp4"):
|
||||
break
|
||||
|
||||
vid_writer.release()
|
||||
cap.release()
|
||||
cap.release()
|
||||
|
||||
def main():
|
||||
videopath = r'C:\Users\ym\Desktop'
|
||||
savepath = r'C:\Users\ym\Desktop'
|
||||
video2imgs(videopath, savepath)
|
||||
|
||||
|
||||
|
||||
if __name__ == '__main__':
|
||||
main()
|
||||
|
Reference in New Issue
Block a user