Commit 2d99094f authored by 吴升宇's avatar 吴升宇

add skin detector

parent c85e0fde
# Copyright (c) Facebook, Inc. and its affiliates. All Rights Reserved.
import cv2
import torch
import skin_detector
from torchvision import transforms as T
from maskrcnn_benchmark.modeling.detector import build_detection_model
......@@ -175,12 +177,14 @@ class COCODemo(object):
result = image.copy()
if self.show_mask_heatmaps:
return self.create_mask_montage(result, top_predictions)
result = self.overlay_boxes(result, top_predictions)
# 添加方框
# result = self.overlay_boxes(result, top_predictions)
if self.cfg.MODEL.MASK_ON:
result = self.overlay_mask(result, top_predictions)
if self.cfg.MODEL.KEYPOINT_ON:
result = self.overlay_keypoints(result, top_predictions)
result = self.overlay_class_names(result, top_predictions)
# 添加tag
# result = self.overlay_class_names(result, top_predictions)
return result
......@@ -293,10 +297,26 @@ class COCODemo(object):
contours, hierarchy = cv2_util.findContours(
thresh, cv2.RETR_TREE, cv2.CHAIN_APPROX_SIMPLE
)
image = cv2.drawContours(image, contours, -1, color, 3)
composite = image
color = [0, 0, 0]
img = cv2.drawContours(image, contours, -1, color, 3)
# 把轮廓之外的颜色变为黑色
a, b, c = img.shape
for x in range(a):
for y in range(b):
if img[x, y].tolist() < [10, 10, 10]:
break
img[x, y] = [0, 0, 0]
for y in range(b - 1, 0, -1):
if img[x, y].tolist() < [10, 10, 10]:
break
img[x, y] = [0, 0, 0]
# 把图片皮肤颜色变为白色
img = skin_detector(img)
composite = img
return composite
def overlay_keypoints(self, image, predictions):
......
import os
from webcam import img_to_three_color_map
def main():
os.walk('../../fashionbase/images/dataset_0520/weiyi')
img_to_three_color_map(source_image, target_image)
if __name__ == '__main__':
main()
\ No newline at end of file
......@@ -5,10 +5,8 @@ import cv2
from maskrcnn_benchmark.config import cfg
from predictor import COCODemo
import time
def main():
def img_to_three_color_map(source_path, target_path):
parser = argparse.ArgumentParser(description="PyTorch Object Detection Webcam Demo")
parser.add_argument(
"--config-file",
......@@ -25,7 +23,7 @@ def main():
parser.add_argument(
"--min-image-size",
type=int,
default=224,
default=800,
help="Smallest size of the image to feed to the model. "
"Model was trained with 800, which gives best results",
)
......@@ -64,9 +62,9 @@ def main():
min_image_size=args.min_image_size,
)
img = cv2.imread()
img = cv2.imread(source_path)
composite = coco_demo.run_on_opencv_image(img)
cv2.imwrite('abc.jpg', composite)
cv2.imwrite(target_path, composite)
# cam = cv2.VideoCapture(0)
# while True:
# start_time = time.time()
......@@ -79,6 +77,3 @@ def main():
# cv2.destroyAllWindows()
if __name__ == "__main__":
main()
......@@ -29,14 +29,11 @@ ENV PATH=$CONDA_PREFIX/bin:$PATH
ENV CONDA_AUTO_UPDATE_CONDA=false
RUN conda install -y ipython
RUN pip install -i https://pypi.tuna.tsinghua.edu.cn/simple ninja yacs cython matplotlib opencv-python tqdm
RUN pip install ninja yacs cython matplotlib opencv-python tqdm
# Install PyTorch 1.0 Nightly
ARG CUDA
RUN conda config --add channels https://mirrors.ustc.edu.cn/anaconda/pkgs/main/ \
&& conda config --add channels https://mirrors.ustc.edu.cn/anaconda/pkgs/free/ \
&& conda config --set show_channel_urls yes \
&& conda install pytorch-nightly cudatoolkit=${CUDA} -c pytorch \
RUN conda install pytorch-nightly cudatoolkit=${CUDA} -c pytorch \
&& conda clean -ya
# Install TorchVision master
......
......@@ -3,3 +3,4 @@ yacs
cython
matplotlib
tqdm
git+ssh://git@git.wanmeizhensuo.com/wushengyu/skin_detector.git@master
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment