import csv import os import cv2 path_1 = "完整" list_name = os.listdir(path_1) for n in list_name: if n[-3:] == 'csv': csvpath = path_1 + '/' + n +'/merge_L.csv' imgpath = "merge3/" 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) imgpath = "/merge6/"+m_split[0]+".jpg" image = cv2.imread(imgpath) w=int(m_split[4]) h=int(m_split[5]) first_point = (int(m_split[2]),int(m_split[3])) last_point = (int(m_split[2])+w,int(m_split[3])+h) if int(m_split[7])==0: cv2.rectangle(image, first_point, last_point, (153,36,255),2) //生成边框 text = "{}:{}".format(int(m_split[7]), int(m_split[1])) cv2.putText(image, text, (int(m_split[2]), int(m_split[3]) - 5), cv2.FONT_HERSHEY_COMPLEX, fontScale=0.5,color=(0,0,0), thickness=1) //在边框上面加备注 cv2.imwrite(imgpath,image) count = count + 1 else: continue break;
python生成边框,圈出重点。
最新推荐文章于 2023-03-03 17:46:43 发布