我是靠谱客的博主 友好麦片,最近开发中收集的这篇文章主要介绍【Python脚本】手动过滤图片数据样本的自动化操作,觉得挺不错的,现在分享给大家,希望可以做个参考。

概述

可以通过键盘快速操作

import cv2
import os
import argparse
import numpy as np 
from tqdm import tqdm
import shutil
import random
import glob
import json
import sys
import tty
import termios

def parse_arg():
    """
    Parse command line input parameters
    """
    parser = argparse.ArgumentParser(description="Calculate the accuracy of license plate recognition")
    parser.add_argument("--input_image_paths", type=str, default="/home/yangbinchao/桌面/雄研/draw_test_data_image/draw",help=" File path to be processed ")
    args = parser.parse_args()
    print()
    print(f"args = {args}")
    print()
    return args

def readchar():
    fd = sys.stdin.fileno()
    old_settings = termios.tcgetattr(fd)
    try:
        tty.setraw(sys.stdin.fileno())
        ch = sys.stdin.read(1)
    finally:
        termios.tcsetattr(fd, termios.TCSADRAIN, old_settings)
    return ch

def readkey(getchar_fn=None):
    getchar = getchar_fn or readchar
    c1 = getchar()
    if ord(c1) != 0x1b:
        return c1
    c2 = getchar()
    if ord(c2) != 0x5b:
        return c1
    c3 = getchar()
    return chr(0x10 + ord(c3) - 65)

def wait_key(img_path):  # wait the key is put down
    while True:
        key=readkey()
        if key=='z':  # save the path 
            print('save the image path list',img_path)
            #miss_label_list.append(img_path)
            with open( './miss_label_list.json',  'a+',  encoding='utf-8') as f:  # 车牌对应的颜色标签
                f.write(json.dumps(img_path,ensure_ascii=False,indent=1)+',')
            break
        if key=='x':  
            print('save the image path list',img_path)
            #lack_vehicle_list.append(img_path)
            with open( './lack_vehicle_list.json',  'a+',  encoding='utf-8') as f:  # 车牌对应的颜色标签
                f.write(json.dumps(img_path,ensure_ascii=False,indent=1)+',')
            break
        if key=='a':
            print('ignore the image path list',img_path)
            break
        if key=='q':
            return key
            break

def read_img(img_path,image_dir):
    image_path = os.path.join( image_dir, img_path)
    img = cv2.imread(image_path) 
    img = cv2.resize(img,(1000,500))
    cv2.imshow(img_path, img) 
    while cv2.waitKey(2500) != 27:# loop time is 3000 if not get ESC
        if cv2.getWindowProperty('img_path' ,cv2.WND_PROP_VISIBLE) <= 0:
            break
    cv2.destroyAllWindows() 

def main(args):

    for img_path in tqdm(os.listdir(args.input_image_paths)):
        read_img(img_path, image_dir=args.input_image_paths)
        key_value = wait_key(img_path)
        if(key_value == 'q'):
            print('nthe save image path list is {}'.format(miss_label_list))
            print('nthe save image path list is {}'.format(lack_vehicle_list))
            exit()
    print('nthe save image path list is {}'.format(miss_label_list))
    print('nthe save image path list is {}'.format(lack_vehicle_list))

if __name__ == "__main__":
    args = parse_arg()
    miss_label_list = []
    lack_vehicle_list = []
    main(args)

        
    

最后

以上就是友好麦片为你收集整理的【Python脚本】手动过滤图片数据样本的自动化操作的全部内容,希望文章能够帮你解决【Python脚本】手动过滤图片数据样本的自动化操作所遇到的程序开发问题。

如果觉得靠谱客网站的内容还不错,欢迎将靠谱客网站推荐给程序员好友。

本图文内容来源于网友提供,作为学习参考使用,或来自网络收集整理,版权属于原作者所有。
点赞(32)

评论列表共有 0 条评论

立即
投稿
返回
顶部