Spaces:
				
			
			
	
			
			
		Runtime error
		
	
	
	
			
			
	
	
	
	
		
		
		Runtime error
		
	Create cartoon.py
Browse files- cartoon.py +28 -0
    	
        cartoon.py
    ADDED
    
    | @@ -0,0 +1,28 @@ | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | 
|  | |
| 1 | 
            +
            import os
         | 
| 2 | 
            +
            import argparse
         | 
| 3 | 
            +
            import cv2
         | 
| 4 | 
            +
            from utils import read_img, edge_detection, color_quantisation
         | 
| 5 | 
            +
             | 
| 6 | 
            +
            parser = argparse.ArgumentParser(description='Cartoonify Face Images')
         | 
| 7 | 
            +
            parser.add_argument('--input_path', default='./temp/image.jpg', type=str, help='Directory of input images or path of single image')
         | 
| 8 | 
            +
            parser.add_argument('--result_dir', default='./temp/', type=str, help='Directory for restored results')
         | 
| 9 | 
            +
             | 
| 10 | 
            +
             | 
| 11 | 
            +
            args = parser.parse_args()
         | 
| 12 | 
            +
            out_dir = args.result_dir
         | 
| 13 | 
            +
            os.makedirs(out_dir, exist_ok=True)
         | 
| 14 | 
            +
             | 
| 15 | 
            +
             | 
| 16 | 
            +
            img = read_img(args.input_path)
         | 
| 17 | 
            +
             | 
| 18 | 
            +
            line_wdt = 9
         | 
| 19 | 
            +
            blur_value=7
         | 
| 20 | 
            +
            totalcolours=9
         | 
| 21 | 
            +
             | 
| 22 | 
            +
            edgeImg = edge_detection(img, line_wdt,blur_value)
         | 
| 23 | 
            +
            img = color_quantisation(img, totalcolours)
         | 
| 24 | 
            +
            blurred = cv2.bilateralFilter(img, d=7,sigmaColor=200,sigmaSpace=200) 
         | 
| 25 | 
            +
            cartoon = cv2.bitwise_and(blurred,blurred,mask=edgeImg)
         | 
| 26 | 
            +
            # cv2.imwrite('cartoon.jpg', cartoon)
         | 
| 27 | 
            +
            out_path = os.path.join(out_dir, os.path.split(args.input_path)[-1])
         | 
| 28 | 
            +
            cv2.imwrite(out_path,cv2.cvtColor(cartoon, cv2.COLOR_RGB2BGR))
         |