提交 6b747324 编写于 作者: H hypox64

Fixed an BUG that in Windows could not read Chinese path images.

上级 7474e4bd
![image](https://github.com/HypoX64/DeepMosaics/blob/master/hand.gif) ![image](https://github.com/HypoX64/DeepMosaics/blob/master/hand.gif)
# DeepMosaics # DeepMosaics
You can use it to automatically remove the mosaics in images and videos, or add mosaics to them.<br> You can use it to automatically remove the mosaics in images and videos, or add mosaics to them.<br>
This porject based on semantic segmentation and pix2pix. This porject based on ‘semantic segmentation’ and ‘Image-to-Image Translation’.
<br> <br>
## Notice ## Notice
...@@ -9,10 +9,10 @@ The code do not include the part of training, I will finish it in my free time. ...@@ -9,10 +9,10 @@ The code do not include the part of training, I will finish it in my free time.
<br> <br>
## Prerequisites ## Prerequisites
- Linux, (I didn't try this code on Windows or Mac OS) - Linux, Mac OS, Windows
- Python 3.6+ - Python 3.6+
- ffmpeg - [ffmpeg 3.4](http://ffmpeg.org/)
- Pytorch 1.0+ [(Old version codes)](https://github.com/HypoX64/DeepMosaics/tree/Pytorch0.4) - [Pytorch 1.0+](https://pytorch.org/) [(Old version codes)](https://github.com/HypoX64/DeepMosaics/tree/Pytorch0.4)
- CPU or NVIDIA GPU + CUDA CuDNN - CPU or NVIDIA GPU + CUDA CuDNN
## Getting Started ## Getting Started
......
...@@ -21,7 +21,7 @@ if opt.mode == 'add': ...@@ -21,7 +21,7 @@ if opt.mode == 'add':
path = opt.media_path path = opt.media_path
if util.is_img(path): if util.is_img(path):
print('Add Mosaic:',path) print('Add Mosaic:',path)
img = cv2.imread(path) img = impro.imread(path)
img = runmodel.add_mosaic_to_image(img,net,opt) img = runmodel.add_mosaic_to_image(img,net,opt)
cv2.imwrite(os.path.join(opt.result_dir,os.path.basename(path)),img) cv2.imwrite(os.path.join(opt.result_dir,os.path.basename(path)),img)
elif util.is_video(path): elif util.is_video(path):
...@@ -34,7 +34,7 @@ if opt.mode == 'add': ...@@ -34,7 +34,7 @@ if opt.mode == 'add':
for imagepath in imagepaths: for imagepath in imagepaths:
imagepath = os.path.join('./tmp/video2image',imagepath) imagepath = os.path.join('./tmp/video2image',imagepath)
print('Add Mosaic:',imagepath) print('Add Mosaic:',imagepath)
img = cv2.imread(imagepath) img = impro.imread(imagepath)
img = runmodel.add_mosaic_to_image(img,net,opt) img = runmodel.add_mosaic_to_image(img,net,opt)
cv2.imwrite(os.path.join('./tmp/addmosaic_image', cv2.imwrite(os.path.join('./tmp/addmosaic_image',
os.path.basename(imagepath)),img) os.path.basename(imagepath)),img)
...@@ -49,7 +49,7 @@ elif opt.mode == 'clean': ...@@ -49,7 +49,7 @@ elif opt.mode == 'clean':
path = opt.media_path path = opt.media_path
if util.is_img(path): if util.is_img(path):
print('Clean Mosaic:',path) print('Clean Mosaic:',path)
img_origin = cv2.imread(path) img_origin = impro.imread(path)
x,y,size = runmodel.get_mosaic_position(img_origin,net_mosaic_pos,opt) x,y,size = runmodel.get_mosaic_position(img_origin,net_mosaic_pos,opt)
img_result = img_origin.copy() img_result = img_origin.copy()
if size != 0 : if size != 0 :
...@@ -68,7 +68,7 @@ elif opt.mode == 'clean': ...@@ -68,7 +68,7 @@ elif opt.mode == 'clean':
imagepaths.sort() imagepaths.sort()
for imagepath in imagepaths: for imagepath in imagepaths:
imagepath=os.path.join('./tmp/video2image',imagepath) imagepath=os.path.join('./tmp/video2image',imagepath)
img_origin = cv2.imread(imagepath) img_origin = impro.imread(imagepath)
x,y,size = runmodel.get_mosaic_position(img_origin,net_mosaic_pos,opt) x,y,size = runmodel.get_mosaic_position(img_origin,net_mosaic_pos,opt)
positions.append([x,y,size]) positions.append([x,y,size])
print('Find Positions:',imagepath) print('Find Positions:',imagepath)
...@@ -79,7 +79,7 @@ elif opt.mode == 'clean': ...@@ -79,7 +79,7 @@ elif opt.mode == 'clean':
for i,imagepath in enumerate(imagepaths,0): for i,imagepath in enumerate(imagepaths,0):
imagepath=os.path.join('./tmp/video2image',imagepath) imagepath=os.path.join('./tmp/video2image',imagepath)
x,y,size = positions[i][0],positions[i][1],positions[i][2] x,y,size = positions[i][0],positions[i][1],positions[i][2]
img_origin = cv2.imread(imagepath) img_origin = impro.imread(imagepath)
img_result = img_origin.copy() img_result = img_origin.copy()
if size != 0: if size != 0:
img_mosaic = img_origin[y-size:y+size,x-size:x+size] img_mosaic = img_origin[y-size:y+size,x-size:x+size]
......
...@@ -25,8 +25,7 @@ class Options(): ...@@ -25,8 +25,7 @@ class Options():
#AddMosaic #AddMosaic
self.parser.add_argument('--netG', type=str, default='auto',help='select model to use for netG(clean mosaic) -> auto | unet_128 | resnet_9blocks') self.parser.add_argument('--netG', type=str, default='auto',help='select model to use for netG(clean mosaic) -> auto | unet_128 | resnet_9blocks')
self.parser.add_argument('--mosaic_position_model_path', type=str, default='./pretrained_models/mosaic_position.pth', self.parser.add_argument('--mosaic_position_model_path', type=str, default='auto',help='name of model use to find mosaic position')
help='name of model use to find mosaic position')
self.parser.add_argument('--no_feather', action='store_true', help='if true, no edge feather,but run faster') self.parser.add_argument('--no_feather', action='store_true', help='if true, no edge feather,but run faster')
self.parser.add_argument('--medfilt_num', type=int, default=11,help='medfilt window of mosaic movement in the video') self.parser.add_argument('--medfilt_num', type=int, default=11,help='medfilt window of mosaic movement in the video')
self.initialized = True self.initialized = True
...@@ -43,4 +42,9 @@ class Options(): ...@@ -43,4 +42,9 @@ class Options():
elif 'resnet_9blocks' in self.opt.model_path: elif 'resnet_9blocks' in self.opt.model_path:
self.opt.netG = 'resnet_9blocks' self.opt.netG = 'resnet_9blocks'
if self.opt.mosaic_position_model_path == 'auto':
_path = os.path.join(os.path.split(self.opt.model_path)[0],'mosaic_position.pth')
self.opt.mosaic_position_model_path = _path
print(self.opt.mosaic_position_model_path)
return self.opt return self.opt
\ No newline at end of file
...@@ -2,6 +2,11 @@ import cv2 ...@@ -2,6 +2,11 @@ import cv2
import numpy as np import numpy as np
# imread for chinese path in windows
def imread(file_path):
cv_img = cv2.imdecode(np.fromfile(file_path,dtype=np.uint8),-1)
return cv_img
def resize(img,size): def resize(img,size):
h, w = img.shape[:2] h, w = img.shape[:2]
if np.min((w,h)) ==size: if np.min((w,h)) ==size:
......
...@@ -29,11 +29,6 @@ def writelog(path,log): ...@@ -29,11 +29,6 @@ def writelog(path,log):
f = open(path,'a+') f = open(path,'a+')
f.write(log+'\n') f.write(log+'\n')
# def del_all(dir_path):
# files = Traversal(dir_path)
# for file in files:
# os.remove(file)
# os.removedirs(dir_path)
def clean_tempfiles(tmp_init=True): def clean_tempfiles(tmp_init=True):
if os.path.isdir('./tmp'): if os.path.isdir('./tmp'):
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册