File size: 2,033 Bytes
05f5e5a
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
import sys
import cv2
from run import process
import argparse
import os


def main():
    parser = argparse.ArgumentParser(description='DeepNude App CLI Version with no Watermark.')
    parser.add_argument('-i', "--input", help='Input image to process.', action="store", dest="input", required=True)
    parser.add_argument('-o', "--output", help='Output path to save result.', action="store", dest="output",
                        required=False, default="output.jpg")
    parser.add_argument('-g', "--use-gpu", help='Enable using CUDA gpu to speed up the process.', action="store_true",
                        dest="use_gpu", default=False)

    if not os.path.isdir("checkpoints"):
        print(
            "[-] Checkpoints folder not found, download it from Github repository, and extract files to 'checkpoints' folder.")
        sys.exit(1)
    arguments = parser.parse_args()

    print("[*] Processing: %s" % arguments.input)

    if (arguments.use_gpu):
        print("[*] Using CUDA gpu to speed up the process.")


    _process(arguments.input, arguments.output, arguments.use_gpu)


def _process(i_image, o_image, use_gpu):
    try:
        dress = cv2.imread(i_image)
        h = dress.shape[0]
        w = dress.shape[1]
        dress = cv2.resize(dress, (512, 512), interpolation=cv2.INTER_CUBIC)
        watermark = process(dress, use_gpu)
        watermark = cv2.resize(watermark, (w, h), interpolation=cv2.INTER_CUBIC)
        cv2.imwrite(o_image, watermark)
        print("[*] Image saved as: %s" % o_image)
    except Exception as ex:
        ex = str(ex)
        if "NoneType" in ex:
            print("[-] File %s not found" % i_image)
        elif "runtime error" in ex:
            print("[-] Error: CUDA Runtime not found, Disable the '--use-gpu' option!")
        else:
            print("[-] Error occured when trying to process the image: %s" % ex)
            with open("logs.txt", "a") as f:
                f.write("[-] Error: %s\n" % ex)
        sys.exit(1)


if __name__ == '__main__':
    main()