update for bakeup
This commit is contained in:
@ -1,3 +1,15 @@
|
||||
# -*- coding: utf-8 -*-
|
||||
"""
|
||||
Created on Sat Jul ** 14:07:25 2024
|
||||
|
||||
现场测试精度、召回率分析程序,是 feat_select.py 的简化版,
|
||||
但支持循环计算,并输出总的pr曲线
|
||||
|
||||
@author: ym
|
||||
"""
|
||||
|
||||
|
||||
|
||||
import os.path
|
||||
import shutil
|
||||
|
||||
@ -10,41 +22,6 @@ sys.path.append(r"D:\DetectTracking")
|
||||
from tracking.utils.read_data import extract_data, read_deletedBarcode_file, read_tracking_output
|
||||
from tracking.utils.plotting import draw_tracking_boxes
|
||||
|
||||
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:
|
||||
break
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
def showHist(err, correct):
|
||||
@ -309,6 +286,24 @@ def save_tracking_imgpairs(pair, basepath, savepath):
|
||||
cv2.imwrite(imgpath, img)
|
||||
|
||||
|
||||
# def performance_evaluate(all_list, isshow=False):
|
||||
|
||||
# corrpairs, correct_barcode_list, correct_similarity, errpairs, err_barcode_list, err_similarity = [], [], [], [], [], []
|
||||
# for s_list in all_list:
|
||||
# seqdir = s_list['SeqDir'].strip()
|
||||
# delete = s_list['Deleted'].strip()
|
||||
# barcodes = [s.strip() for s in s_list['barcode']]
|
||||
# similarity = [float(s.strip()) for s in s_list['similarity']]
|
||||
|
||||
# if delete in barcodes[:1]:
|
||||
# corrpairs.append((seqdir, delete))
|
||||
# correct_barcode_list.append(delete)
|
||||
# correct_similarity.append(similarity[0])
|
||||
# else:
|
||||
# errpairs.append((seqdir, delete, barcodes[0]))
|
||||
# err_barcode_list.append(delete)
|
||||
# err_similarity.append(similarity[0])
|
||||
|
||||
def performance_evaluate(all_list, isshow=False):
|
||||
|
||||
corrpairs, correct_barcode_list, correct_similarity, errpairs, err_barcode_list, err_similarity = [], [], [], [], [], []
|
||||
@ -316,17 +311,32 @@ def performance_evaluate(all_list, isshow=False):
|
||||
seqdir = s_list['SeqDir'].strip()
|
||||
delete = s_list['Deleted'].strip()
|
||||
barcodes = [s.strip() for s in s_list['barcode']]
|
||||
similarity = [float(s.strip()) for s in s_list['similarity']]
|
||||
|
||||
if delete in barcodes[:1]:
|
||||
|
||||
|
||||
similarity_comp, similarity_front = [], []
|
||||
for simil in s_list['similarity']:
|
||||
ss = [float(s.strip()) for s in simil.split(',')]
|
||||
|
||||
similarity_comp.append(ss[0])
|
||||
if len(ss)==3:
|
||||
similarity_front.append(ss[2])
|
||||
|
||||
if len(similarity_front):
|
||||
similarity = [s for s in similarity_front]
|
||||
else:
|
||||
similarity = [s for s in similarity_comp]
|
||||
|
||||
|
||||
index = similarity.index(max(similarity))
|
||||
matched_barcode = barcodes[index]
|
||||
if matched_barcode == delete:
|
||||
corrpairs.append((seqdir, delete))
|
||||
correct_barcode_list.append(delete)
|
||||
correct_similarity.append(similarity[0])
|
||||
correct_similarity.append(max(similarity))
|
||||
else:
|
||||
errpairs.append((seqdir, delete, barcodes[0]))
|
||||
errpairs.append((seqdir, delete, matched_barcode))
|
||||
err_barcode_list.append(delete)
|
||||
err_similarity.append(similarity[0])
|
||||
|
||||
err_similarity.append(max(similarity))
|
||||
|
||||
'''3. 计算比对性能 '''
|
||||
if isshow:
|
||||
@ -335,6 +345,14 @@ def performance_evaluate(all_list, isshow=False):
|
||||
showHist(err_similarity, correct_similarity)
|
||||
|
||||
return errpairs, corrpairs, err_similarity, correct_similarity
|
||||
|
||||
|
||||
|
||||
return errpairs, corrpairs, err_similarity, correct_similarity
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
@ -370,12 +388,7 @@ def contrast_loop(fpath):
|
||||
|
||||
if os.path.isfile(fpath):
|
||||
fpath, filename = os.path.split(fpath)
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
BarLists, blists = {}, []
|
||||
for filename in os.listdir(fpath):
|
||||
file = os.path.splitext(filename)[0][15:]
|
||||
@ -385,9 +398,7 @@ def contrast_loop(fpath):
|
||||
|
||||
BarLists.update({file: blist})
|
||||
blists.extend(blist)
|
||||
|
||||
|
||||
|
||||
|
||||
BarLists.update({file: blist})
|
||||
BarLists.update({"Total": blists})
|
||||
for file, blist in BarLists.items():
|
||||
@ -406,8 +417,6 @@ def contrast_loop(fpath):
|
||||
# plt2.savefig(os.path.join(savepath, file+'_hist.png'))
|
||||
# plt.close()
|
||||
|
||||
|
||||
|
||||
def main():
|
||||
fpath = r'\\192.168.1.28\share\测试_202406\deletedBarcode\other'
|
||||
|
||||
@ -423,17 +432,12 @@ def main1():
|
||||
except Exception as e:
|
||||
print(f'Error Type: {e}')
|
||||
|
||||
def resolve_vidoes():
|
||||
videopath = r"\\192.168.1.28\share\测试_202406\0719\719_1\20240719-103533_"
|
||||
savepath = r"D:\contrast\result"
|
||||
|
||||
video2imgs(videopath, savepath)
|
||||
|
||||
|
||||
if __name__ == '__main__':
|
||||
main()
|
||||
|
||||
# main1()
|
||||
# resolve_vidoes()
|
||||
|
||||
|
||||
|
||||
|
Reference in New Issue
Block a user