File size: 4,641 Bytes
a20719a
21a2ce4
92ed922
 
 
 
5b57797
1faff06
59a8279
92ed922
 
26a4e14
05c9c18
 
 
 
 
160b451
 
 
942386d
160b451
 
 
 
 
 
 
91bffdb
0abb0d9
06ad9aa
 
0abb0d9
 
 
 
 
 
 
05c9c18
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
326b92b
05c9c18
 
 
 
 
 
 
 
 
 
160b451
 
06ad9aa
160b451
 
942386d
 
995d48a
942386d
07a00fa
942386d
160b451
 
942386d
160b451
8c5fb4a
160b451
bb1d671
8c5fb4a
160b451
 
07a00fa
942386d
1306203
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
import streamlit as st
import os.path
os.system("mkdir _input")
os.system("mkdir _output")
os.system("mkdir _outputf")
os.system("ls")
if not os.path.isfile("./_input/imagem-0001.png"):
    os.system("ffmpeg -i vivi.mp4   -compression_level 10 -pred mixed -pix_fmt rgb24 -sws_flags +accurate_rnd+full_chroma_int -s 1080x1920 -r 0.12 ./_input/imagem-%4d.png")

os.system("ls ./_input") 

os.system("pip install git+https://github.com/TencentARC/GFPGAN.git")
import cv2
import glob
import numpy as np
from basicsr.utils import imwrite
from gfpgan import GFPGANer
#os.system("pip freeze")
#os.system("wget https://github.com/TencentARC/GFPGAN/releases/download/v0.2.0/GFPGANCleanv1-NoCE-C2.pth -P .")
import random

from PIL import Image
import torch
# torch.hub.download_url_to_file('https://upload.wikimedia.org/wikipedia/commons/thumb/a/ab/Abraham_Lincoln_O-77_matte_collodion_print.jpg/1024px-Abraham_Lincoln_O-77_matte_collodion_print.jpg', 'lincoln.jpg')
# torch.hub.download_url_to_file('https://upload.wikimedia.org/wikipedia/commons/5/50/Albert_Einstein_%28Nobel%29.png', 'einstein.png')
# torch.hub.download_url_to_file('https://upload.wikimedia.org/wikipedia/commons/thumb/9/9d/Thomas_Edison2.jpg/1024px-Thomas_Edison2.jpg', 'edison.jpg')
# torch.hub.download_url_to_file('https://upload.wikimedia.org/wikipedia/commons/thumb/a/a9/Henry_Ford_1888.jpg/1024px-Henry_Ford_1888.jpg', 'Henry.jpg')
# torch.hub.download_url_to_file('https://upload.wikimedia.org/wikipedia/commons/thumb/0/06/Frida_Kahlo%2C_by_Guillermo_Kahlo.jpg/800px-Frida_Kahlo%2C_by_Guillermo_Kahlo.jpg', 'Frida.jpg')

# set up GFPGAN restorer
bg_upsampler = None
print(f"Is CUDA available: {torch.cuda.is_available()}")
restorer = GFPGANer(
    model_path='GFPGANv1.3.pth',
    upscale=2,
    arch='clean',
    channel_multiplier=2,
    bg_upsampler=bg_upsampler)

img_list = sorted(glob.glob(os.path.join("./_input", '*')))

for img_path in img_list:
        # read image
        img_name = os.path.basename(img_path)
        print(f'Processing {img_name} ...')
        basename, ext = os.path.splitext(img_name)
        input_img = cv2.imread(img_path, cv2.IMREAD_COLOR)

        # restore faces and background if necessary
        cropped_faces, restored_faces, restored_img = restorer.enhance(
            input_img,
            has_aligned='store_true',
            only_center_face='store_true',
            paste_back=True,
            weight=0.5)

        # save faces
        for idx, (cropped_face, restored_face) in enumerate(zip(cropped_faces, restored_faces)):
            # save cropped face
            save_crop_path = os.path.join("_output", 'cropped_faces', f'{basename}_{idx:02d}.png')
            imwrite(cropped_face, save_crop_path)
            # save restored face
            if None is not None:
                save_face_name = f'{basename}_{idx:04d}_{args.suffix}.png'
            else:
                save_face_name = f'{basename}_{idx:04d}.png'
            save_restore_path = os.path.join("_output", 'restored_faces', save_face_name)
            imwrite(restored_face, save_restore_path)
            # save comparison image
            cmp_img = np.concatenate((cropped_face, restored_face), axis=1)
            imwrite(cmp_img, os.path.join("_output", 'cmp', f'{basename}_{idx:04d}.png'))

        # save restored img
        if restored_img is not None:
            print('encontrou**************')          
            if args.ext == 'auto':
                extension = ext[1:]
            else:
                extension = args.ext

            if None is not None:
                save_restore_path = os.path.join("_output", 'restored_imgs', f'{basename}_{args.suffix}.{extension}')
            else:
                save_restore_path = os.path.join("_output", 'restored_imgs', f'{basename}.{extension}')
            imwrite(restored_img, save_restore_path)






def inference():
    os.system("ls ./_output")
    os.system("ls ./_output/cmp")
    input_img = cv2.imread("./_output/cmp/imagem-0011_0000.png" , cv2.IMREAD_COLOR)
    st.image(input_img)
    
    #return Image.fromarray(restored_faces[0][:,:,::-1])
    

title = "Melhoria de imagens"

os.system("ls")
description = "Sistema para automação。"

article = "<p style='text-align: center'><a href='https://huggingface.co/spaces/akhaliq/GFPGAN/' target='_blank'>clone from akhaliq@huggingface with little change</a> | <a href='https://github.com/TencentARC/GFPGAN' target='_blank'>GFPGAN Github Repo</a></p><center><img src='https://visitor-badge.glitch.me/badge?page_id=akhaliq_GFPGAN' alt='visitor badge'></center>"
st.button('Comparacao',on_click=inference)