MaskRCNN用于检测路标,作为更详细的目标检测,用以得到更精准的额路标位置,路标的几何中心点,用于构建更为精准的拓扑地图,减少构图误差。

抠图工具已经完成,把框抠出来,用0值表示背景。

python代码:

def mainex():

    #initDir();
# Root directory of the project
ROOT_DIR = os.getcwd() # Directory to save logs and trained model
MODEL_DIR = os.path.join(ROOT_DIR, "logs") # Path to trained weights file
# Download this file and place in the root of your
# project (See README file for details)
#COCO_MODEL_PATH = os.path.join(ROOT_DIR, "mask_rcnn_coco.h5")
COCO_MODEL_PATH= "D:/Works/PyProj/MaskRCNN-tensor/data/model/mask_rcnn_coco.h5"; # Directory of images to run detection on
#IMAGE_DIR = os.path.join(ROOT_DIR, "images");
IMAGE_DIR = "data/MedSeaTest/"; config = InferenceConfig()
config.display(); # 3.
# Create model object in inference mode.
model = modellib.MaskRCNN(mode="inference", model_dir=MODEL_DIR, config=config) # Load weights trained on MS-COCO
model.load_weights(COCO_MODEL_PATH, by_name=True); # 4
class_names= init_classname(); IMAGE_DIR = "D:/DataSet/PicStyleTest/Medsea3/deskfilter/";
proDir(model, class_names, IMAGE_DIR);

处理目录:

def proDir( model,class_names,IMAGE_DIR ):
# Load a random image from the images folder
print(IMAGE_DIR); extention =".jpg";
filelist =traverseFolder( IMAGE_DIR , extention);#traverse( IMAGE_DIR , extention);# for file in filelist:
print("Is processing: ");print(file);
image = skimage.io.imread( file ); # Run detection
results = model.detect([image], verbose=1); # Visualize results
#r = results[0];
fileName = file; getAllLabelMask(fileName, image, results[0], class_names)

def getAllLabelMask(fileName,image, maskResult,class_names ):
"""
boxes: [num_instance, (y1, x1, y2, x2, class_id)] in image coordinates.
masks: [num_instances, height, width]
class_ids: [num_instances]
class_names: list of class names of the dataset
scores: (optional) confidence scores for each box
figsize: (optional) the size of the image.
"""
boxes = maskResult['rois'];
masks = maskResult['masks'];
scores = maskResult['scores'];
class_ids = maskResult['class_ids']; # Number of instances
N = boxes.shape[0];
if not( N<1 or boxes.shape[0] == masks.shape[-1] == class_ids.shape[0]):
return row = image.shape[1];
col = image.shape[0];
for i in range(N):
# Bounding box
if not np.any(boxes[i]):
continue;
y1, x1, y2, x2 = boxes[i]; # Label
class_id = class_ids[i];
score = scores[i] if scores is not None else None
label = class_names[class_id]; # Mask
mask = masks[:, :, i];
masked_image = np.zeros((col, row, 3), dtype=np.uint8);
masked_image = apply_maskX(masked_image, mask); #frontImage = np.zeros( (col, row), dtype=np.uint8 );
frontImage = image.copy();
for m in range(row):
for n in range(col):
if(masked_image[n, m, 0]<254):
#frontImage[n, m] = 255;
frontImage[n,m,0] =0;
frontImage[n, m, 1] = 0;
frontImage[n, m, 2] = 0;
#roiMask = masked_image[y1:y2, x1:x2];
roiImg = frontImage[y1:y2, x1:x2];
roiImg = cv2.cvtColor(roiImg, cv2.COLOR_BGR2RGB); fileMask = fileName[0: len(fileName)-4];
fileMask = fileMask +"."+ str(i)+"."+label+"."+"Mask.png"; cv2.imwrite(fileMask, roiImg);

结果:

MaskRCNN路标:TensorFlow版本用于抠图的更多相关文章

  1. Detectron-MaskRCnn: 用于抠图的FCNN

    市面上暂时还没有找到可以在消费机显卡上实时运行的MaskRCnn,TensorFlow即使是C++版本训练在coco数据集上的模型也是慢的要死,最后不堪忍受,只能放弃. 经历了一些列fuckingDo ...

  2. 查看已安装tensorflow版本

    http://blog.csdn.net/u011961856/article/details/76861052 由于tensorflow版本不同,可能一些函数的调用也有变换,这时候可能需要查看ten ...

  3. Deep Photo的TensorFlow版本

    Prisma这个应用,你可能很熟悉.这是一个能将不同的绘画风格,迁移到照片中,形成不同艺术风格的图片. 2017年4月,美国康奈尔大学和Adobe的一个研究团队在arvix上通过论文“Deep Pho ...

  4. 机器学习&深度学习基础(tensorflow版本实现的算法概述0)

    tensorflow集成和实现了各种机器学习基础的算法,可以直接调用. 代码集:https://github.com/ageron/handson-ml 监督学习 1)决策树(Decision Tre ...

  5. 用anaconda安装最新的TensorFlow版本

    Google发布了TensorFlow1.4正式版 在anaconad搜索依旧是1.2的版本,通过一番查阅,找到了方法 1,打开anaconda-prompt 2,激活你要安装的环境 activate ...

  6. Anaconda多版本Python管理以及TensorFlow版本的选择安装

    Anaconda是一个集成python及包管理的软件,记得最早使用时在2014年,那时候网上还没有什么资料,需要同时使用py2和py3的时候,当时的做法是同时安装Anaconda2和Anaconda3 ...

  7. 查看已安装tensorflow版本以及安装路径

    查看版本: import tensorflow as tf tf.__version__ 查看安装路径: tf.__path__

  8. TensorFlow 版本问题

    TensorFlow各个版本均可以在GitHub上下载,之前下载配置的是0.5.0版本,运行的时候,出现很多问题,什么模块缺失attribute,函数参数问题等,修改起来让人抓狂,后来索性下载使用0. ...

  9. windows tensorflow 版本与升级

    tensorflow 的版本在 1.1.0/1.2.0 之后 api 迎来重大变化,有必要将版本升级到最新的 1.1.0 以上. 1. 使用 upgrade CPU:pip3 install –upg ...

随机推荐

  1. NOIP2014 提高组合集

    NOIP 2014 提高组 合集 D1 T1 生活大爆炸版石头剪刀布 首先,先将两个人的猜拳序列都变得不小于n.然后逐个模拟.胜败什么的看表就行了. #include <iostream> ...

  2. 51Nod——T 1631 小鲨鱼在51nod小学

    https://www.51nod.com/onlineJudge/questionCode.html#!problemId=1631 基准时间限制:1 秒 空间限制:131072 KB 分值: 20 ...

  3. SiteMesh2-sitemesh.xml的其它映射器的用法

    在sitemesh.xml中做常用的三个映射器,总结如下: 映射器元素的顺序确定优先级.良好的应用程序应使用以下顺序, Parameter query = ParameterDecoratorMapp ...

  4. KonBoot – 只要5K映象文件轻易绕过您的WindowsXP/VISTA/7系统的密码

    http://pannisec.diandian.com/?tag=konBoot 这个东西是我昨晚点击了QQ弹窗的那个SOSO问题后,有人问我如何破解Windows登陆密码,且不可以用net命令创建 ...

  5. 1.3-动态路由协议RIP①

    Dynamic Routing Protocol:动态路由协议 现代IP网络中,主要的动态路由协议: AD/管理距离: 1:DV/距离向量协议:RIP(120)/IGRP(100) 2:LS/链路状态 ...

  6. leetcode_Product of Array Except Self

    描写叙述: Given an array of n integers where n > 1, nums, return an array output such that output[i]  ...

  7. Codeforces 196 D. The Next Good String

    D. The Next Good String time limit per test 2 seconds memory limit per test 256 megabytes input stan ...

  8. leetcode笔记:Jump Game

    一. 题目描写叙述 Given an array of non-negative integers, you are initially positioned at the first index o ...

  9. luogu2346 四子连棋

    题目大意 在一个4*4的棋盘上摆放了14颗棋子,其中有7颗白色棋子,7颗黑色棋子,有两个空白地带,任何一颗黑白棋子都可以向上下左右四个方向移动到相邻的空格,这叫行棋一步,黑白双方交替走棋,任意一方可以 ...

  10. abstract (C# Reference)

    https://msdn.microsoft.com/en-us/library/sf985hc5.aspx The abstract modifier indicates that the thin ...