AU标注辅助小程序

本文介绍了一款使用Python开发的自动标注辅助小程序,旨在提高工作效率,简化标注过程。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

人生苦短,我用python~

import cv2
import os
import matplotlib
import matplotlib.pyplot as plt
import numpy as np
import shutil
import csv


def check_landmark():
	os.system('cls')
	path = os.getcwd()
	path = 'dataset\\'

	student_id = input("please input the student id:\n")
	if student_id == 'q': return
	while 1:
		frame = input("please input the frame:\n")
		if frame == 'q': return
		im = cv2.imread(path + 'faces\\' + student_id + '\\' + frame + '.jpg')
		print(path + 'faces\\' + student_id + '\\' + frame + '.jpg')
		im = im[:, :, (2, 1, 0)]
		fig,ax = plt.subplots(figsize=(4, 4))
		ax.imshow(im, aspect = 'equal', extent = (0, 255, 255, 0))
		lm = np.loadtxt(path + 'landmarks\\' + student_id + '\\' + frame + '.txt', delimiter = ',')
		plt.plot(lm[:,0], lm[:,1], '*')
		plt.axis('off')
		#plt.tight_layout()
		#plt.draw()
		plt.show()

def remove_0_file_in_dataset():
	path = os.getcwd()
	path += '\\dataset\\'

	for dir in os.listdir(path):
		if dir == 'AU':
			continue
		if '0' in os.listdir(path + dir):
			path_of_0_file = path + dir + '\\0'
			shutil.rmtree(path_of_0_file)
			print(dir + " done")
		else:
			print(dir + " not exist")
	input()

def remove_specific_file():
	path = os.getcwd()
	path += '\\dataset\\'

	student_id = input("please input the student id:\n")
	if student_id == 'q': return
	while 1:
		frame = input("please input the frame:\n")
		if frame == 'q': return
		for dir in os.listdir(path):
			if dir == 'AU':
				continue
			if frame + '.jpg' in os.listdir(path + dir + '\\' + student_id + '\\'):
				path2rmv = path + dir + '\\' + student_id + '\\' + frame + '.jpg'
				os.remove(path2rmv)
				print('the file ' + path2rmv + " has been remove!")
			elif frame + '.txt' in os.listdir(path + dir + '\\' + student_id + '\\'):
				path2rmv = path + dir + '\\' + student_id + '\\' + frame + '.txt'
				os.remove(path2rmv)
				print('the file ' + path2rmv + " has been remove!")
			else:
				print("the file doesn't exist in " + path + dir + '\\' + student_id + '\\')
			
def check_reduntant_files():
	os.system('cls')
	pat_b = input("Please enter the path of your big folder: ")
	pat_s = input("Please enter the path to your small folder: ")
	root = os.getcwd()
	path_b = root + '\\dataset\\' + pat_b
	path_s = root + '\\dataset\\' + pat_s
	flag = True
	for f in os.listdir(path_b):
		ff = path_b + '\\' + f
		for name in os.listdir(ff):
			if os.path.exists(path_s + '\\' + f + '\\' + name)==False:
				print('Path:' + pat_b + '>>' + f + '>>' + name + 'is reduntant\n')
				flag = False
	if flag:
		print('The two folders are the same \n')
	input()

def calculate_the_files_number():
	os.system('cls')
	path = os.getcwd()
	path += '\\dataset\\'
	for f in os.listdir(path):
		sum = 0
		if f == 'AU':
			for ff in os.listdir(path + '\\' + f):
				csv_reader = csv.reader(open(path + '\\' + f + '\\' + ff, encoding='utf-8')) # encoding='utf-8' is required !!
				tmp = np.array(list(csv_reader)).shape[0] - 1
				sum += tmp
				print(os.path.splitext(ff)[0] + ':' + str(tmp), end = ' ')
		else:
			for ff in os.listdir(path + '\\' + f):
				if ff == '0':
					continue
				else:
					sum += len(os.listdir(path + '\\' + f + '\\' + ff))
					print(ff + ':' + str(len(os.listdir(path + '\\' + f + '\\' + ff))), end = ' ')
		print('%12s totally: '%f + str(sum))
	input()

if __name__ == '__main__':
	while True:
		os.system('cls')
		string1 = "----Welcome to the auxiliary system!----"
		print('\n')
		print(string1.center(80))
		print("     1. check landmark")
		print("     2. remove 0 file in dataset")
		print("     3. remove specific files")
		print("     4. check reduntant files")
		print("     5. calculate the files number")
		index = input("\nSelect your operation with corresponding number:")
		if index == '1':
			check_landmark()
		if index == '2':
			remove_0_file_in_dataset()
		if index == '3':
			remove_specific_file()
		if index == '4':
			check_reduntant_files()
		if index == '5':
			calculate_the_files_number()
		if index == 'q':
			quit()


评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值