栏目分类:
子分类:
返回
名师互学网用户登录
快速导航关闭
当前搜索
当前分类
子分类
实用工具
热门搜索
名师互学网 > IT > 软件开发 > 后端开发 > Python

【代码|个人记录】标定点判断

Python 更新时间: 发布时间: IT归档 最新发布 模块sitemap 名妆网 法律咨询 聚返吧 英语巴士网 伯小乐 网商动力

【代码|个人记录】标定点判断

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:判断字符串是否以指定的子字符串结尾(区分大小写)

 

转载请注明:文章转载自 www.mshxw.com
本文地址:https://www.mshxw.com/it/961300.html
我们一直用心在做
关于我们 文章归档 网站地图 联系我们

版权所有 (c)2021-2022 MSHXW.COM

ICP备案号:晋ICP备2021003244-6号