Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
Hypo
Haystack
提交
8b8b9e0c
H
Haystack
项目概览
Hypo
/
Haystack
通知
0
Star
0
Fork
0
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
0
列表
看板
标记
里程碑
合并请求
0
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
H
Haystack
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
0
Issue
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
Pages
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
提交
Issue看板
前往新版Gitcode,体验更适合开发者的 AI 搜索 >>
提交
8b8b9e0c
编写于
1月 28, 2020
作者:
H
hypox64
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
change find_face model to cnn
上级
e199e83a
变更
7
隐藏空白更改
内联
并排
Showing
7 changed file
with
265 addition
and
36 deletion
+265
-36
.gitignore
.gitignore
+6
-0
CV/del_noface_image.py
CV/del_noface_image.py
+127
-0
CV/find_face.py
CV/find_face.py
+43
-28
CV/threshold_photo.py
CV/threshold_photo.py
+17
-0
Notes/linux.md
Notes/linux.md
+41
-2
Notes/python.md
Notes/python.md
+17
-1
System/monitor_linux.py
System/monitor_linux.py
+14
-5
未找到文件。
.gitignore
浏览文件 @
8b8b9e0c
...
...
@@ -127,3 +127,9 @@ dmypy.json
# Pyre type checker
.pyre/
# myrules
#all
__pycache__/
tmp/
output/
\ No newline at end of file
CV/del_noface_image.py
0 → 100644
浏览文件 @
8b8b9e0c
import
face_recognition
import
os
import
shutil
import
datetime
import
concurrent.futures
import
cv2
import
numpy
as
np
import
random
import
string
def
random_str
(
length
=
12
):
"""
Generate secret key from alpha and digit.
:param length: length of secret key.
:return: [length] long secret key.
"""
key
=
''
while
length
:
key
+=
random
.
choice
(
string
.
ascii_letters
+
string
.
digits
)
length
-=
1
return
key
def
get_bar
(
percent
,
num
=
25
):
# graphs = ' ▏▎▍▋▊▉'
percent
=
round
(
percent
)
bar
=
'['
for
i
in
range
(
num
):
if
i
<
round
(
percent
/
int
((
100
/
num
))):
bar
+=
'#'
else
:
bar
+=
'-'
bar
+=
']'
return
bar
def
lapulase
(
resImg
):
img2gray
=
cv2
.
cvtColor
(
resImg
,
cv2
.
COLOR_BGR2GRAY
)
# 将图片压缩为单通道的灰度图
res
=
cv2
.
Laplacian
(
img2gray
,
cv2
.
CV_64F
)
score
=
res
.
var
()
return
score
def
resize
(
img
,
size
):
h
,
w
=
img
.
shape
[:
2
]
if
min
(
h
,
w
)
==
size
:
return
img
if
w
>=
h
:
res
=
cv2
.
resize
(
img
,(
int
(
size
*
w
/
h
),
size
),
interpolation
=
cv2
.
INTER_LANCZOS4
)
else
:
res
=
cv2
.
resize
(
img
,(
size
,
int
(
size
*
h
/
w
)),
interpolation
=
cv2
.
INTER_LANCZOS4
)
return
res
def
Traversal
(
filedir
):
file_list
=
[]
for
root
,
dirs
,
files
in
os
.
walk
(
filedir
):
for
file
in
files
:
file_list
.
append
(
os
.
path
.
join
(
root
,
file
))
for
dir
in
dirs
:
Traversal
(
dir
)
return
file_list
def
is_img
(
ext
):
ext
=
ext
.
lower
()
if
ext
in
[
'.jpg'
,
'.png'
,
'.jpeg'
,
'.bmp'
]:
return
True
else
:
return
False
def
picture_select
(
file_list
):
imgpath_list
=
[]
for
pic
in
file_list
:
if
is_img
(
os
.
path
.
splitext
(
pic
)[
1
]):
imgpath_list
.
append
(
pic
)
return
imgpath_list
def
del_noface_image
(
input_path
):
try
:
image
=
cv2
.
imread
(
input_path
)
h
,
w
=
image
.
shape
[:
2
]
face_locations
=
face_recognition
.
face_locations
(
image
)
if
len
(
face_locations
)
>
0
and
lapulase
(
image
)
>
Del_Blur_Score
:
return
0
else
:
try
:
os
.
remove
(
input_path
)
return
1
except
Exception
as
e
:
return
0
except
Exception
as
e
:
try
:
os
.
remove
(
input_path
)
return
1
except
Exception
as
e
:
return
0
filedir
=
(
input
(
"filedir:"
).
strip
()).
replace
(
"'"
,
""
)
WORKERS
=
int
((
input
(
"cpu_workers(defult=4):"
).
strip
()).
replace
(
"'"
,
""
))
Del_Blur_Score
=
50
file_list
=
Traversal
(
filedir
)
imgpath_list
=
picture_select
(
file_list
)
random
.
shuffle
(
imgpath_list
)
all_length
=
len
(
imgpath_list
)
print
(
"Find picture:"
+
" "
+
str
(
all_length
))
print
(
'Begining......'
)
print
(
'Finished/del images % Bar Usedtime/Totaltime'
)
starttime
=
datetime
.
datetime
.
now
()
del_cnt
=
0
with
concurrent
.
futures
.
ProcessPoolExecutor
(
max_workers
=
WORKERS
)
as
executor
:
for
i
,
imgpath
,
count
in
zip
(
range
(
1
,
len
(
imgpath_list
)
+
1
),
imgpath_list
,
executor
.
map
(
del_noface_image
,
imgpath_list
)):
del_cnt
+=
count
if
i
%
100
==
0
:
endtime
=
datetime
.
datetime
.
now
()
used_time
=
(
endtime
-
starttime
).
seconds
percent
=
round
(
100
*
i
/
all_length
,
1
)
print
(
'
\r
'
,
''
,
str
(
i
)
+
'/'
+
str
(
del_cnt
)
+
' '
,
str
(
percent
)
+
'%'
+
get_bar
(
percent
,
30
),
' '
+
str
(
int
(
used_time
))
+
's/'
+
str
(
int
(
used_time
/
i
*
all_length
))
+
's'
,
end
=
" "
)
print
(
'
\n
Finished!'
,
'Finall del image:'
,
del_cnt
,
' Cost time:'
,(
datetime
.
datetime
.
now
()
-
starttime
).
seconds
,
's'
)
\ No newline at end of file
CV/find_face.py
浏览文件 @
8b8b9e0c
...
...
@@ -40,14 +40,14 @@ def lapulase(resImg):
score
=
res
.
var
()
return
score
def
resize
(
img
,
size
):
def
resize
(
img
,
size
,
interpolation
=
cv2
.
INTER_LINEAR
):
h
,
w
=
img
.
shape
[:
2
]
if
min
(
h
,
w
)
==
size
:
if
np
.
min
((
w
,
h
)
)
==
size
:
return
img
if
w
>=
h
:
res
=
cv2
.
resize
(
img
,(
int
(
size
*
w
/
h
),
size
),
interpolation
=
cv2
.
INTER_LANCZOS4
)
res
=
cv2
.
resize
(
img
,(
int
(
size
*
w
/
h
),
size
),
interpolation
=
interpolation
)
else
:
res
=
cv2
.
resize
(
img
,(
size
,
int
(
size
*
h
/
w
)),
interpolation
=
cv2
.
INTER_LANCZOS4
)
res
=
cv2
.
resize
(
img
,(
size
,
int
(
size
*
h
/
w
)),
interpolation
=
interpolation
)
return
res
def
Traversal
(
filedir
):
...
...
@@ -77,44 +77,56 @@ def find_save_resize_face(input_path):
try
:
filename
,
extension
=
os
.
path
.
splitext
(
os
.
path
.
split
(
input_path
)[
1
])
# image = face_recognition.load_image_file(input_path)
image
=
cv2
.
imread
(
input_path
)
h
,
w
=
image
.
shape
[:
2
]
#print(image.dtype)
# Find all the faces in the image and print
face_locations
=
face_recognition
.
face_locations
(
image
)
# print("found {} face(s) in this photograph.".format(len(face_locations)))
origin_image
=
cv2
.
imread
(
input_path
)
h
,
w
=
origin_image
.
shape
[:
2
]
mask
=
np
.
zeros
(
origin_image
.
shape
[:
2
],
dtype
=
"uint8"
)
rat
=
min
(
origin_image
.
shape
[:
2
])
/
LOADSIZE
image
=
resize
(
origin_image
,
LOADSIZE
,
interpolation
=
cv2
.
INTER_AREA
)
face_locations
=
face_recognition
.
face_locations
(
image
,
number_of_times_to_upsample
=
1
,
model
=
MODEL
)
count
=
0
mask_count
=
0
for
face_location
in
face_locations
:
# Print the location of each face in this image
top
,
right
,
bottom
,
left
=
face_location
#print("A face is located at pixel location Top: {}, Left: {}, Bottom: {}, Right: {}".format(top, left, bottom, right)
)
#
You can access the actual face itself like this:
top
,
right
,
bottom
,
left
=
int
(
top
*
rat
),
int
(
right
*
rat
),
int
(
bottom
*
rat
),
int
(
left
*
rat
)
#
EX
if
IS_random_EXTEND
:
ex
=
int
(((
EXTEND
-
1
+
0.2
*
random
.
random
())
*
(
bottom
-
top
))
/
2
)
else
:
ex
=
int
(((
EXTEND
-
1
)
*
(
bottom
-
top
))
/
2
)
# ex_face=int((1*(bottom-top))/2)
if
((
bottom
-
top
)
>
MINSIZE
)
and
0.95
<
abs
((
bottom
-
top
)
/
(
left
-
right
))
<
1.05
and
(
top
-
ex
)
>
0
and
(
bottom
+
ex
)
<
h
and
(
left
-
ex
)
>
0
and
(
right
+
ex
)
<
w
:
face
=
origin_image
[
top
-
ex
:
bottom
+
ex
,
left
-
ex
:
right
+
ex
]
face
=
cv2
.
resize
(
face
,
(
512
,
512
),
interpolation
=
cv2
.
INTER_LANCZOS4
)
# cv2.imwrite(os.path.join(outdir_face,outname+filename+'_'+str(count)+'.jpg'),face)
if
lapulase
(
face
)
>
Del_Blur_Score
:
#print(os.path.join(outdir_face,random_str()+'.jpg'))
cv2
.
imwrite
(
os
.
path
.
join
(
outdir_face
,
random_str
()
+
'.jpg'
),
face
)
count
=
count
+
1
#mask = cv2.rectangle(mask,(left-ex,top-ex),(right+ex,bottom+ex),255,-1)
#mask
# if count > 0:
# mask = resize(mask,256)
# origin_image = resize(origin_image,1024)
# cv2.imwrite(os.path.join(outdir_ori,outname+filename+'.jpg'),origin_image)
# cv2.imwrite(os.path.join(outdir_mask,outname+filename+'.png'),mask)
# print(output_path)
if
SAVE_MASK
:
try
:
if
MASK_TYPE
==
'contour'
:
_ex
=
int
((
bottom
-
top
)
*
0.5
)
face_get_landmark
=
origin_image
[
top
-
_ex
:
bottom
+
_ex
,
left
-
_ex
:
right
+
_ex
]
face_landmark
=
face_recognition
.
face_landmarks
(
face_get_landmark
)[
0
]
face_point
=
[]
face_point
=
face_point
+
face_landmark
[
'left_eyebrow'
]
+
face_landmark
[
'right_eyebrow'
]
+
face_landmark
[
'chin'
][::
-
1
]
face_point
=
np
.
array
(
face_point
)
+
np
.
array
([
left
-
_ex
,
top
-
_ex
])
face_point
[:
10
]
=
face_point
[:
10
]
-
np
.
array
([
0
,
int
((
bottom
-
top
)
*
HIGH_MASK
)])
mask
=
cv2
.
fillPoly
(
mask
,[
face_point
],(
255
))
elif
MASK_TYPE
==
'rect'
:
_ex
=
int
((
bottom
-
top
)
*
0.05
)
mask
=
cv2
.
rectangle
(
mask
,(
int
(
left
-
_ex
*
0.5
),
top
-
_ex
),(
int
(
right
+
_ex
*
0.5
),
bottom
+
_ex
),(
255
),
-
1
)
mask_count
+=
1
except
Exception
as
e
:
pass
if
SAVE_MASK
:
if
count
==
mask_count
and
count
>
0
:
mask
=
resize
(
mask
,
512
,
interpolation
=
cv2
.
INTER_AREA
)
origin_image
=
resize
(
origin_image
,
512
,
interpolation
=
cv2
.
INTER_AREA
)
cv2
.
imwrite
(
os
.
path
.
join
(
outdir_ori
,
outname
+
filename
+
'.jpg'
),
origin_image
)
cv2
.
imwrite
(
os
.
path
.
join
(
outdir_mask
,
outname
+
filename
+
'.png'
),
mask
)
return
count
except
Exception
as
e
:
...
...
@@ -129,10 +141,13 @@ WORKERS = int((input("cpu_workers(defult=4):").strip()).replace("'",""))
# EXTEND=1.4
EXTEND
=
1.6
Del_Blur_Score
=
50
Del_Blur_Score
=
20
# normal-> 20 | clear -> recommed
50
IS_random_EXTEND
=
False
# WORKERS = 4
# MINSIZE = 256
MODEL
=
'cnn'
# 'hog' | 'cnn'
SAVE_MASK
=
True
MASK_TYPE
=
'rect'
# rect | contour
HIGH_MASK
=
0.2
# more vertical mask
LOADSIZE
=
512
# load to this size and process
outdir
=
'./output/'
+
outname
...
...
CV/threshold_photo.py
0 → 100644
浏览文件 @
8b8b9e0c
import
numpy
import
cv2
import
os
img_dir
=
'/media/hypo/Hypo_U/桂林一调/理综'
out_dir
=
os
.
path
.
join
(
img_dir
,
'threshold'
)
THR
=
12
img_names
=
os
.
listdir
(
img_dir
)
if
not
os
.
path
.
isdir
(
out_dir
):
os
.
makedirs
(
out_dir
)
for
img_name
in
img_names
:
img
=
cv2
.
imread
(
os
.
path
.
join
(
img_dir
,
img_name
),
0
)
img
=
cv2
.
adaptiveThreshold
(
img
,
255
,
cv2
.
ADAPTIVE_THRESH_GAUSSIAN_C
,
cv2
.
THRESH_BINARY
,
21
,
THR
)
cv2
.
imwrite
(
os
.
path
.
join
(
out_dir
,
img_name
),
img
)
Notes/linux.md
浏览文件 @
8b8b9e0c
[toc]
[TOC]
### 安装显卡驱动
```
bash
#卸载旧的驱动
sudo
apt-get purge nvidia
*
sudo
apt-get autoremove
#这个命令有时候不用也可以
#
sudo
add-apt-repository ppa:graphics-drivers/ppa
sudo
apt update
ubuntu-drivers devices
sudo
apt
install
nvidia-430
```
### 挂载U盘
```
bash
root@lthpc:/home/hypo# fdisk
-l
...
...
@@ -8,12 +19,29 @@ Device Start End Sectors Size Type
root@lthpc:/home/hypo#
cd
/media
root@lthpc:/media#
mkdir
usb
root@lthpc:/media# mount
-t
ntfs-3g /dev/sdc1 /media/usb
#卸载挂载点
$
umount /dev/hda2
$
umount /usr
#参数可以是设备文件或安装点
```
### shell 中运行基本应用
```
bash
nautilus
#文件管理器
firefox
#火狐浏览器
```
### 批量杀死应用
```
bash
ps aux|grep python|grep
-v
grep
|cut
-c
9-15|xargs
kill
-15
# 管道符“|”用来隔开两个命令,管道符左边命令的输出会作为管道符右边命令的输入。下面说说用管道符联接起来的
#几个命令:
#“ps aux”是linux 里查看所有进程的命令。这时检索出的进程将作为下一条命令“grep python”的输入。
#“grep python”的输出结果是,所有含有关键字“python”的进程,这是python程序
#“grep -v grep”是在列出的进程中去除含有关键字“grep”的进程。
#“cut -c 9-15”是截取输入行的第9个字符到第15个字符,而这正好是进程号PID。
#“xargs kill -15”中的xargs命令是用来把前面命令的输出结果(PID)作为“kill -15”命令的参数,并执行该令。
#“kill -15”会正常退出指定进程,-9强行杀掉
```
### 常用系统命令
*
删除文件
```
bash
...
...
@@ -51,7 +79,7 @@ dpkg -L <package> #列出 <package> 安装的所有文件清单。同时请看 d
dpkg
-s
<package>
#显示已安装包裹的信息。同时请看 apt-cache 显示 Debian 存档中的包裹信息,以及 dpkg -I 来显示从一个 .deb 文件中提取的包裹信息。
dpkg-reconfigure <package>
#重新配制一个已经安装的包裹,如果它使用的是 debconf (debconf 为包裹安装提供了一个统一的配制界面)。
```
*
调整CPU性能模式
###
调整CPU性能模式
```
bash
sudo
apt-get
install
cpufrequtils
cpufreq-info
...
...
@@ -60,6 +88,16 @@ sudo cpufreq-set -g performance
sudo
apt-get
install
sysfsutils
sudo
gedit /sys/devices/system/cpu/cpu0/cpufreq/scaling_governor
```
### 添加或禁用开机启动项
```
bash
#禁用开机启动项
$
systemctl list-unit-files
--type
=
service|grep enabled
#查看开机启动的服务
$
sudo
systemctl disable apache2.service
#禁用掉该服务
#添加开机启动项
$
systemctl list-unit-files
--type
=
service|grep team
teamviewerd.service enabled
$
sudo
systemctl
enable
teamviewerd.service
```
### 压缩解压
```
bash
tar
xvf filename.tar
#.tar 解包
...
...
@@ -128,6 +166,7 @@ firefox &
```
bash
#压缩+解压流传输 把本地的文件复制到远程主机上
tar
-c
'./dir'
|pigz |ssh hypo@172.31.73.116
"gzip -d|tar -xC /home/hypo/MyProject"
tar
-c
'./DeepMosaics'
|pigz |ssh hypo@172.30.194.156
"gzip -d|tar -xC /media/hypo/Project/MyProject/DeepMosaics"
#把远程的文件复制到本地
scp root@www.test.com:/val/test/test.tar.gz /val/test/test.tar.gz
...
...
Notes/python.md
浏览文件 @
8b8b9e0c
[
toc
]
[
TOC
]
# Python
## base
### main
...
...
@@ -265,7 +265,23 @@ cv2.IMREAD_UNCHANGED:加载图像,包括alpha通道
您可以简单地分别传递整数1,0或-1,而不是这三个标志。
'''
```
### resize
```
python
#CV2.INTER_NEAREST 最邻近插值点法
#CV2.NTER_LINEAR 双线性插值法
#CV2.INTER_AREA 邻域像素再取样插补
#CV2.INTER_CUBIC 双立方插补,4*4大小的补点
#CV2.INTER_LANCZOS4 8x8像素邻域的Lanczos插值
#當我們縮小影像時,使用CV_INTER_AREA會有比較好的效果,當我們放大影像,CV_INTER_CUBIC會有最好的效果,但是計算花費時間較多,CV_INTER_LINEAR能在影像品質和花費時間上取得不錯的平衡。 CV_INTER_LANCZOS4 Lanczos插补,8*8大小的补点
```
### imshow
```
python
cv2
.
imshow
(
'image'
,
img
)
'''
...
...
System/monitor_linux.py
浏览文件 @
8b8b9e0c
...
...
@@ -38,7 +38,12 @@ def get_cpu_freq():
# Cpu freq
def
get_cpu_temp
():
temp_str
=
os
.
popen
(
'cat /sys/class/hwmon/hwmon0/device/hwmon/hwmon0/temp1_input'
).
read
()
if
os
.
path
.
isfile
(
'/sys/class/hwmon/hwmon0/device/hwmon/hwmon0/temp1_input'
):
temp_str
=
os
.
popen
(
'cat /sys/class/hwmon/hwmon0/device/hwmon/hwmon0/temp1_input'
).
read
()
elif
os
.
path
.
isfile
(
'/sys/class/hwmon/hwmon0/device/hwmon0/temp1_input'
):
temp_str
=
os
.
popen
(
'cat /sys/class/hwmon/hwmon0/device/hwmon0/temp1_input'
).
read
()
else
:
return
-
1
return
(
float
(
temp_str
)
/
1000
)
# Mem
...
...
@@ -71,9 +76,10 @@ def get_swap_use():
###############################################################
gpus_str
=
os
.
popen
(
'nvidia-smi -L'
).
read
()
gpus
=
[]
while
gpus_str
.
find
(
'
\n
'
)
!=
-
1
:
gpus
.
append
(
gpus_str
[
gpus_str
.
find
(
':'
)
+
2
:
gpus_str
.
find
(
'('
)
-
1
])
gpus_str
=
gpus_str
[
gpus_str
.
find
(
'
\n
'
)
+
1
:]
if
'communicate with the NVIDIA driver'
not
in
gpus_str
:
while
gpus_str
.
find
(
'
\n
'
)
!=
-
1
:
gpus
.
append
(
gpus_str
[
gpus_str
.
find
(
':'
)
+
2
:
gpus_str
.
find
(
'('
)
-
1
])
gpus_str
=
gpus_str
[
gpus_str
.
find
(
'
\n
'
)
+
1
:]
def
get_gpu_use
():
...
...
@@ -85,7 +91,10 @@ def get_gpu_use():
infos_str
=
infos_str
[:
infos_str
.
find
(
'
\n
'
)
+
1
]
infos_str
=
infos_str
.
split
()
#['|', '50%', '42C', 'P0', '19W', '/', '75W', '|', '929MiB', '/', '5050MiB', '|', '14%', 'Default', '|']
fan
=
int
(
infos_str
[
1
].
replace
(
'%'
,
''
))
# %
if
infos_str
[
1
].
replace
(
'%'
,
''
)
==
'N/A'
:
fan
=
-
1
else
:
fan
=
int
(
infos_str
[
1
].
replace
(
'%'
,
''
))
# %
temp
=
int
(
infos_str
[
2
].
replace
(
'C'
,
''
))
# C
if
infos_str
[
4
]
==
'N/A'
:
power_used
=
-
1
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录