0.0.1a
This commit is contained in:
@@ -1,3 +1,10 @@
|
|||||||
|
# Test files
|
||||||
|
|
||||||
|
data/vids/*
|
||||||
|
data/screen/*
|
||||||
|
data/json/*
|
||||||
|
data/*.*
|
||||||
|
|
||||||
# Byte-compiled / optimized / DLL files
|
# Byte-compiled / optimized / DLL files
|
||||||
__pycache__/
|
__pycache__/
|
||||||
*.py[cod]
|
*.py[cod]
|
||||||
|
|||||||
Binary file not shown.
@@ -0,0 +1,11 @@
|
|||||||
|
<html>
|
||||||
|
<head>
|
||||||
|
<title>{file_name}</title>
|
||||||
|
</head>
|
||||||
|
<h2>{file_name}</h2><br>
|
||||||
|
<h3>{resolution}</h3><br>
|
||||||
|
<h3>{duration}</h3><br>
|
||||||
|
<video height="50%" src="{file_vid}" controls></video><br>
|
||||||
|
<hr>
|
||||||
|
{frame_info}
|
||||||
|
</html>
|
||||||
@@ -0,0 +1,6 @@
|
|||||||
|
<div>
|
||||||
|
<p>{file_name}</p>
|
||||||
|
<img src="{file_name}" alt="{file_name}" height="50%"><br>
|
||||||
|
<p>{info_res}</p>
|
||||||
|
</div>
|
||||||
|
<hr>
|
||||||
@@ -0,0 +1,30 @@
|
|||||||
|
import json
|
||||||
|
|
||||||
|
|
||||||
|
def create(file_name):
|
||||||
|
datas = json.load(open("data/json/"+file_name+".json", "r", encoding='utf-8'))
|
||||||
|
text_no_format = open("data/templates/index.html", "r").read()
|
||||||
|
text_f_no_format = open("data/templates/one_frame.html", "r").read()
|
||||||
|
list_frame_id = datas["frames"].keys()
|
||||||
|
text_f_format = ""
|
||||||
|
for ii in list_frame_id:
|
||||||
|
res_info=""
|
||||||
|
for dd in datas["frames"][ii].keys():
|
||||||
|
if dd == "file":
|
||||||
|
pass
|
||||||
|
else:
|
||||||
|
res_add = dd + " : " +str(round(datas["frames"][ii][dd]*100, 2))+"<br>"
|
||||||
|
res_info += res_add
|
||||||
|
text_add = text_f_no_format.format(
|
||||||
|
file_name=datas["frames"][ii]["file"],
|
||||||
|
info_res=res_info
|
||||||
|
)
|
||||||
|
text_f_format += text_add
|
||||||
|
text_format = text_no_format.format(
|
||||||
|
file_name=file_name,
|
||||||
|
resolution=str(round(datas["height"]))+"x"+str(round(datas["width"])),
|
||||||
|
duration=str(round(datas["duration"], 2))+" s.",
|
||||||
|
file_vid="vids/"+file_name,
|
||||||
|
frame_info=text_f_format
|
||||||
|
)
|
||||||
|
open("data/"+file_name+".html", "w").write(text_format)
|
||||||
@@ -0,0 +1,48 @@
|
|||||||
|
import PIL.Image as Image
|
||||||
|
from nsfw_detector import predict
|
||||||
|
import cv2
|
||||||
|
import os
|
||||||
|
import json
|
||||||
|
import html_create
|
||||||
|
|
||||||
|
def save_frame(screen_folder, secs, vid):
|
||||||
|
save_name = screen_folder + "/" + str(secs) + ".jpg"
|
||||||
|
fps = vid.get(cv2.CAP_PROP_FPS)
|
||||||
|
vid.set(cv2.CAP_PROP_POS_FRAMES, fps*secs)
|
||||||
|
ret, frame = vid.read()
|
||||||
|
cv2.imwrite(save_name, frame)
|
||||||
|
return save_name
|
||||||
|
|
||||||
|
model = predict.load_model('./data/model/nsfw_mobilenet2.224x224.h5')
|
||||||
|
file_path = "./data/vids/5.mp4"
|
||||||
|
vid = cv2.VideoCapture( file_path )
|
||||||
|
height = vid.get(cv2.CAP_PROP_FRAME_HEIGHT)
|
||||||
|
width = vid.get(cv2.CAP_PROP_FRAME_WIDTH)
|
||||||
|
fps = vid.get(cv2.CAP_PROP_FPS)
|
||||||
|
totalNoFrames = vid.get(cv2.CAP_PROP_FRAME_COUNT)
|
||||||
|
durationInSeconds = float(totalNoFrames) / float(fps)
|
||||||
|
datas = {"height":height, "width":width, "duration":durationInSeconds}
|
||||||
|
print(height, width, durationInSeconds)
|
||||||
|
screen_folder = "data/screen/" + file_path.split("/")[-1]
|
||||||
|
try:
|
||||||
|
if not os.path.exists(screen_folder):
|
||||||
|
os.makedirs(screen_folder)
|
||||||
|
except OSError:
|
||||||
|
print('Error: Creating directory of data')
|
||||||
|
save_frame(screen_folder, 1, vid)
|
||||||
|
current_sec = 1
|
||||||
|
datas_frames = {}
|
||||||
|
while True:
|
||||||
|
if current_sec < durationInSeconds:
|
||||||
|
file_name = save_frame(screen_folder, current_sec, vid)
|
||||||
|
image = Image.open(file_name)
|
||||||
|
data_res = predict.classify(model, file_name)
|
||||||
|
data_one = data_res[list(data_res.keys())[0]]
|
||||||
|
data_one["file"] = file_name.replace("data/", "", 1)
|
||||||
|
datas_frames[str(current_sec)] = data_one
|
||||||
|
else:
|
||||||
|
break
|
||||||
|
current_sec += 5
|
||||||
|
datas["frames"] = datas_frames
|
||||||
|
json.dump(datas, open("data/json/"+file_path.split("/")[-1]+".json", "w", encoding='utf-8'), ensure_ascii=False, indent=4)
|
||||||
|
html_create.create(file_path.split("/")[-1])
|
||||||
Reference in New Issue
Block a user