Merge pull request '修改了doc中用户界面设计部分' (#27) from hexuesong into develop

tanxiaolong
pbyhqr72x 3 years ago committed by 谈晓龙
commit 087664702b

@ -0,0 +1,45 @@
import PIL.Image
import numpy
import os
import shutil
def sum_right(path):
img = PIL.Image.open(path)
array = numpy.array(img)
num = array.sum(axis=0)
print(type(num))
res_left = 0
res_right = 0
for i in range(256,512):
res_right += num[i]
print(res_right)
if __name__ == '__main__':
dir2 = r"C:\Users\xinluo\PycharmProjects\pythonProject\Camera Roll"
dir1 = r"C:\Users\xinluo\PycharmProjects\pythonProject\Saved Pictures"
names = os.listdir(dir1)
n = len(names)
print("文件数量",n)
res = 0
average_5 = 25565356
average_25 = 26409377
average_5_right = 10006019
average_tmp = (average_25+average_5)//2
count = 0
show(os.path.join(dir1, "uni4F6C.png"))
for i in range(n):
#取图片
img = PIL.Image.open(os.path.join(dir1,names[i]))
file = os.path.join(dir1,names[i])
rmfile = os.path.join(dir2,names[i])
array = numpy.array(img)
num = array.sum(axis=0)
res_right = 0
for i in range(256, 512):
res_right += num[i]
average_5_right += res_right/n
if (res_right > average_5_right).all():
shutil.copyfile(file, rmfile)
os.remove(file)
count += 1
print(average_5_right)
print(count)

@ -0,0 +1,27 @@
# -*- coding: UTF-8 -*-
import argparse
import cv2
import os
# 使用方法命令行cd到脚本所在文件夹python picture.py -i "图片路径"
#便历图片,合格则保存,不合格则删除
def variance_of_laplacian(image):
# 使用拉普拉斯算子提取图像边缘信息,计算边缘的平均方差
return cv2.Laplacian(image, cv2.CV_64F).var()
def read_path(file_pathname):
#遍历该目录下的所有图片文件
for filename in os.listdir(file_pathname):
print(filename)
image = cv2.imread(file_pathname+'/'+filename)
# 取图片的灰度通道
gray = cv2.cvtColor(image, cv2.COLOR_BGR2GRAY)
fm = variance_of_laplacian(gray)
# 如果得分比阈值低,认为是模糊
if fm < 100.0:
os.remove(file_pathname+'/'+filename)
#read_path(r"C:\Users\xinluo\PycharmProjects\pythonProject\Saved Pictures")
#print(os.getcwd())

@ -0,0 +1,50 @@
import cv2
import argparse
import os
def parse_args():
"""
Parse input arguments
"""
parser = argparse.ArgumentParser(description='Process pic')
parser.add_argument('--input', help='video to process', dest='input', default=None, type=str)
parser.add_argument('--output', help='pic to store', dest='output', default=None, type=str)
# default为间隔多少帧截取一张图片
parser.add_argument('--skip_frame', dest='skip_frame', help='skip number of video', default=10, type=int)
# input为输入视频的路径 output为输出存放图片的路径
args = parser.parse_args(['--input', r'C:\Users\xinluo\PycharmProjects\pythonProject\1234.mp4', '--output', r'C:\Users\xinluo\PycharmProjects\pythonProject\Saved Pictures'])
return args
def process_video(i_video, o_video, num):
cap = cv2.VideoCapture(i_video)
num_frame = cap.get(cv2.CAP_PROP_FRAME_COUNT)
expand_name = '.jpg'
if not cap.isOpened():
print("Please check the path.")
cnt = 0
count = 0
while 1:
ret, frame = cap.read()
cnt += 1
# how
# many
# frame
# to
# cut
if cnt % num == 0:
count += 1
cv2.imwrite(os.path.join(o_video, str(count) + expand_name), frame)
if not ret:
break
if __name__ == '__main__':
args = parse_args()
if not os.path.exists(args.output):
os.makedirs(args.output)
print('Called with args:')
print(args)
process_video(args.input, args.output, args.skip_frame)

@ -0,0 +1,22 @@
import os
from PIL import Image, ImageFile
# ImageFile.LOAD_TRUNCATED_IMAGES = True #如果图片太大报错可以使用这个
def pixel():
b = 0
dir = r'C:\Users\xinluo\PycharmProjects\pythonProject\Camera Roll' # 需要处理的图片目录
files = os.listdir(dir) # 得到需要处理的所有图片
files.sort() # 对图片进行排序
for each_bmp in files: # 遍历图片,进行筛选
each_bmp_root = os.path.join(dir, each_bmp) # 得到每个图片路径
image = Image.open(each_bmp_root) # 打开每个图片
img = image.convert('RGB') # 转化成RGB其实图片大多都是RGB即使灰度图也不一定转RGB看需求
width = img.size[0] # 获取图像的宽和长
height = img.size[1]
if (width < 650) or (height < 650): # 判断图形尺寸有一条边小于600像素的直接删除
os.remove(each_bmp_root)
Loading…
Cancel
Save