1、4×17点个数判断
import os
import json
def get_number(root='image1'):
"""获取数字编号"""
files = os.listdir(root)
numbers = []
for file in files:
numbers.append(file.split('.')[0].split('_')[-1])
return numbers
def json_filelist(jsonpath):
"""获取json文件路径"""
jsons_path = []
json_list = os.listdir(jsonpath)
for json in json_list:
if json.endswith('.json'):#对文件格式进行判断
jsons_path.append(os.path.join(jsonpath, json))
return jsons_path
def check_points(json_path):
with open(json_path, 'r', encoding='utf-8') as f:
load_dict = json.load(f)
if len(load_dict['shapes']) == 68:
# print(json_path,'true')
pass
else:
print(json_path, 'false')
if __name__ == '__main__':
numbers = get_number()
print(numbers)
# ap_json = json_filelist('ap_json')
lat_json = json_filelist('jason1')
# print(ap_json)
print(len(lat_json))
# for ap in ap_json:
# check_points(ap)
for lat in lat_json:
check_points(lat)
【过程记录】:
1、报错:FileNotFoundError: [Errno 2] No such file or directory: 'j' 检索目录
解决: 首先是放在同一目录下,所以路径没问题,是主程序中lat_jason变量使用不合理
2、因为jason中混入了一个zip,遂加一个文件格式判断:if json.endswith('.json')
endswith:判断字符串是否以指定的子字符串结尾(区分大小写)