Administrator
发布于 2026-05-17 / 1 阅读
0

python

--- title: python date: 2022-01-16 15:04:50 tags: --- \`\`\`python # xml 读取 import csv import os import sys import numpy as np import copy import shutil import pandas as pd from collections import Counter from shutil import copyfile import cv2 path = os.getcwd() print(path) path_1 = path + '/' + 'data_error_0813' list_name = os.listdir(path_1) for n in list_name: if n\[-3:\] == 'csv': csvpath = path_1 + '/' + n imgpath = path_1 + '/' + n\[:-3\] + 'JPG' print(imgpath) if not os.path.exists(imgpath): print("nothing") filehand = open(csvpath,'r') csvlist = filehand.readlines() mark = \[\] image = \[\] count = 1 for m in csvlist\[1:\]: m_split = m.split(',') xy = \[m_split\[2\], m_split\[3\]\] mark.append(xy) image = cv2.imread(imgpath) print("type:",type(image)) first_point = (int(m_split\[2\])-50,int(m_split\[3\])-50) last_point = (int(m_split\[2\])+50,int(m_split\[3\])+50) cv2.rectangle(image, first_point, last_point, (0,255,0),2) cv2.imwrite(imgpath,image) print("标记次数",count) count = count + 1 else: continue print(mark) import glob import xml.etree.ElementTree as ET def load_dataset(path): dataset = \[\] for xml_file in glob.glob("{}/\*xml".format(path)): try: tree = ET.parse(xml_file) except Exception as e: print(xml_file) height = int(tree.findtext("./size/height")) width = int(tree.findtext("./size/width")) for obj in tree.iter("object"): xmin = int(obj.findtext("bndbox/xmin")) / width ymin = int(obj.findtext("bndbox/ymin")) / height xmax = int(obj.findtext("bndbox/xmax")) / width ymax = int(obj.findtext("bndbox/ymax")) / height if (xmax - xmin)\>0 and (ymax - ymin) \>0: dataset.append(\[xmax - xmin, ymax - ymin\]) return np.array(dataset) \`\`\` \`\`\`python #plt 画图 import matplotlib.pyplot as plt from matplotlib.pyplot import MultipleLocator import random font={'family':'serif','weight':'normal','size':16} font2={'family':'serif','weight':'normal','size':10} # 定义坐标(x,y) x = \[\] y = \[\] for i in range(10): data_x = sorted(\[random.random() for _ in range(100)\]) data_y = \[-num\*num+1-i/10 for num in data_x\] y.append(data_y) x.append(data_x) plt.rcParams\['savefig.dpi'\] = 600 #图片像素 # plt.rcParams\['figure.dpi'\] = 600 #分辨率 # 右上显示刻度 plt.gca().tick_params(top=True,labeltop=False,labelright = False) plt.gca().tick_params(right=True,labeltop=False,labelright = False) # 刻度线朝内 plt.tick_params(direction='in') # 画线 plt.plot(x\[0\],y\[0\],'-r',label="\[0.696\] first") plt.plot(x\[1\],y\[1\],'-g',label="\[0.691\] second") plt.plot(x\[2\],y\[2\],'-b',label="\[0.6877\] third") plt.plot(x\[3\],y\[3\],'-k',label="\[0.6877\] fourth") plt.plot(x\[4\],y\[4\],'-m',label="\[0.6877\] fifth") plt.plot(x\[5\],y\[5\],'or',label="\[0.6877\] sixth") plt.plot(x\[6\],y\[6\],'og',label="\[0.6877\] seventh") plt.plot(x\[7\],y\[7\],'ob',label="\[0.6877\] eighth") plt.plot(x\[8\],y\[8\],'ok',label="\[0.6877\] ninth") plt.plot(x\[9\],y\[9\],'om',label="\[0.6877\] tenth") # 刻度间隔 plt.gca().xaxis.set_major_locator(MultipleLocator(0.1)) plt.gca().yaxis.set_major_locator(MultipleLocator(0.1)) # x,y坐标开始值 plt.xlim(\[0,1\]) plt.ylim(\[0,1\]) # 标题与x,y plt.ylabel('Success rate',fontdict=font) plt.xlabel('Overlap threshold',fontdict=font) plt.title("Success plots of OPE on OTB2015",fontdict=font) legend = plt.legend( loc=3, # 图例大致位置,左上,左下,右上,右下等等 edgecolor='black', # 图例边框颜色 bbox_to_anchor=(0,0), # 图例位置偏移 prop = font2 ) \[line.set_linewidth(4) for line in legend.get_lines()\] plt.grid(True,color="whitesmoke") # plt.show() plt.savefig("acc.png") # 字符 描述 # '-' 实线样式 # '--' 短横线样式 # '-.' 点划线样式 # ':' 虚线样式 # '.' 点标记 # ',' 像素标记 # 'o' 圆标记 # 'v' 倒三角标记 # '\^' 正三角标记 # '\<' 左三角标记 # '\>' 右三角标记 # '1' 下箭头标记 # '2' 上箭头标记 # '3' 左箭头标记 # '4' 右箭头标记 # 's' 正方形标记 # 'p' 五边形标记 # '\*' 星形标记 # 'h' 六边形标记 1 # 'H' 六边形标记 2 # '+' 加号标记 # 'x' X 标记 # 'D' 菱形标记 # 'd' 窄菱形标记 # '\|' 竖直线标记 # '_' 水平线标记 # # # # 以下是颜色的缩写: # # 字符 颜色 # 'b' 蓝色 # 'g' 绿色 # 'r' 红色 # 'c' 青色 # 'm' 品红色 # 'y' 黄色 # 'k' 黑色 # 'w' 白色 \`\`\`