diff --git a/README.md b/README.md
index 93c0e51204cf1488d64b117895f0ee9a0ce010e8..94947596b2f61ee57af01719c57571df5e01fa9b 100755
--- a/README.md
+++ b/README.md
@@ -1,7 +1,7 @@
![image](https://github.com/HypoX64/DeepMosaics/blob/master/hand.gif)
# DeepMosaics
You can use it to automatically remove the mosaics in images and videos, or add mosaics to them.
-This porject based on semantic segmentation and pix2pix.
+This porject based on ‘semantic segmentation’ and ‘Image-to-Image Translation’.
## Notice
@@ -9,10 +9,10 @@ The code do not include the part of training, I will finish it in my free time.
## Prerequisites
-- Linux, (I didn't try this code on Windows or Mac OS)
+- Linux, Mac OS, Windows
- Python 3.6+
-- ffmpeg
-- Pytorch 1.0+ [(Old version codes)](https://github.com/HypoX64/DeepMosaics/tree/Pytorch0.4)
+- [ffmpeg 3.4](http://ffmpeg.org/)
+- [Pytorch 1.0+](https://pytorch.org/) [(Old version codes)](https://github.com/HypoX64/DeepMosaics/tree/Pytorch0.4)
- CPU or NVIDIA GPU + CUDA CuDNN
## Getting Started
diff --git a/deepmosaic.py b/deepmosaic.py
index a02f46f10464208046c5084e078ea37dbb567aa8..d7202e3402cb69b4210c97739542096d291fa65b 100644
--- a/deepmosaic.py
+++ b/deepmosaic.py
@@ -21,7 +21,7 @@ if opt.mode == 'add':
path = opt.media_path
if util.is_img(path):
print('Add Mosaic:',path)
- img = cv2.imread(path)
+ img = impro.imread(path)
img = runmodel.add_mosaic_to_image(img,net,opt)
cv2.imwrite(os.path.join(opt.result_dir,os.path.basename(path)),img)
elif util.is_video(path):
@@ -34,7 +34,7 @@ if opt.mode == 'add':
for imagepath in imagepaths:
imagepath = os.path.join('./tmp/video2image',imagepath)
print('Add Mosaic:',imagepath)
- img = cv2.imread(imagepath)
+ img = impro.imread(imagepath)
img = runmodel.add_mosaic_to_image(img,net,opt)
cv2.imwrite(os.path.join('./tmp/addmosaic_image',
os.path.basename(imagepath)),img)
@@ -49,7 +49,7 @@ elif opt.mode == 'clean':
path = opt.media_path
if util.is_img(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)
img_result = img_origin.copy()
if size != 0 :
@@ -68,7 +68,7 @@ elif opt.mode == 'clean':
imagepaths.sort()
for imagepath in imagepaths:
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)
positions.append([x,y,size])
print('Find Positions:',imagepath)
@@ -79,7 +79,7 @@ elif opt.mode == 'clean':
for i,imagepath in enumerate(imagepaths,0):
imagepath=os.path.join('./tmp/video2image',imagepath)
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()
if size != 0:
img_mosaic = img_origin[y-size:y+size,x-size:x+size]
diff --git a/options.py b/options.py
index 6395579342b502e5907e0ec923a9c7bd362a8446..eec80ffd53a16bd4c08a3c081215a3ee13c63a44 100644
--- a/options.py
+++ b/options.py
@@ -25,8 +25,7 @@ class Options():
#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('--mosaic_position_model_path', type=str, default='./pretrained_models/mosaic_position.pth',
- help='name of model use to find mosaic position')
+ self.parser.add_argument('--mosaic_position_model_path', type=str, default='auto',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('--medfilt_num', type=int, default=11,help='medfilt window of mosaic movement in the video')
self.initialized = True
@@ -43,4 +42,9 @@ class Options():
elif 'resnet_9blocks' in self.opt.model_path:
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
\ No newline at end of file
diff --git a/util/image_processing.py b/util/image_processing.py
index 890b3d5e8a430d55e9618f55feb5c02ba733b68f..e4f5a1a185fa74b798f26d62ee06d61760e2259d 100755
--- a/util/image_processing.py
+++ b/util/image_processing.py
@@ -2,6 +2,11 @@ import cv2
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):
h, w = img.shape[:2]
if np.min((w,h)) ==size:
diff --git a/util/util.py b/util/util.py
index 2b0f511db85b682a77920d8695f462951ca6a99e..7ac2a9c23c6580a2ae260cdaf5ac3f4e37485d5f 100755
--- a/util/util.py
+++ b/util/util.py
@@ -29,11 +29,6 @@ def writelog(path,log):
f = open(path,'a+')
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):
if os.path.isdir('./tmp'):