import cv2 as cv
import xml.etree.ElementTree as et
def show_bbox_and_landmark(name, num):
for i in range(163, num):
img = cv.imread('C:/Users/86188/Desktop/dataset/' + name + '/photo_enhancement/' + name + str(i) + '.jpg')
xml_path = 'C:/Users/86188/Desktop/dataset/' + name + '/label_enhancement/' + name + str(i) + '.xml'
xml_file = et.parse(xml_path)
root = xml_file.getroot()
obj = root.find('object')
#if obj.find('name').text != name:
# print('wrong')
# break
bnd = obj.find('bndbox')
xmin = int(bnd.find('xmin').text)
ymin = int(bnd.find('ymin').text)
xmax = int(bnd.find('xmax').text)
ymax = int(bnd.find('ymax').text)
# 画框
cv.rectangle(img, (xmin, ymin), (xmax, ymax), (0, 255, 0), 3)
print(i)
# 连线
# cv.line(img, (ldmark_list[8], ldmark_list[9]), (ldmark_list[10], ldmark_list[11]), (0, 0, 255), 2 , cv.LINE_AA)
# cv.line(img, (ldmark_list[10], ldmark_list[11]), (ldmark_list[12], ldmark_list[13]), (0, 0, 255), 2, cv.LINE_AA)
# cv.line(img, (ldmark_list[12], ldmark_list[13]), (ldmark_list[14], ldmark_list[15]), (0, 0, 255), 2, cv.LINE_AA)
# cv.line(img, (ldmark_list[14], ldmark_list[15]), (ldmark_list[8], ldmark_list[9]), (0, 0, 255), 2, cv.LINE_AA)
# 文字绘制: (目标,’内容’,(写入的坐标),字体,字体大小,颜色,字体粗细,线条类型)
font = cv.FONT_HERSHEY_SIMPLEX
cv.putText(img, '1', (xmin,ymin), font, 1, (0, 0, 255), 2, cv.LINE_AA)
cv.putText(img, '2', (xmax, ymax), font, 1, (0, 0, 255), 2, cv.LINE_AA)
cv.imshow('img', img)
cv.waitKey(50)
list_lingjian = ['6.8CA', 'bing', 'xiexing', 'yuanzhu', 'zhengfangti']
num_ = 324
k = 0
show_bbox_and_landmark(name=list_lingjian[k], num=num_)