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. 简单的事件处理类Event

    class Event{ constructor(){ this.handlers=[] } on(type,fn){ //订阅事件 if(!this.handlers[type]){ this.ha ...

  2. python requests使用

    参考:http://cn.python-requests.org/zh_CN/latest/ 1.使用requests发送请求: >>> r = requests.get('http ...

  3. 【打CF,学算法——二星级】CF 520B Two Buttons

    [CF简单介绍] 提交链接:Two Buttons 题面: B. Two Buttons time limit per test 2 seconds memory limit per test 256 ...

  4. The 2014 ACM-ICPC Asia Mudanjiang Regional Contest(2014牡丹江区域赛)

    The 2014 ACM-ICPC Asia Mudanjiang Regional Contest 题目链接 没去现场.做的网络同步赛.感觉还能够,搞了6题 A:这是签到题,对于A堆除掉.假设没剩余 ...

  5. HDU 4249 A Famous Equation(数位DP)

    题目链接:点击打开链接 思路:用d[i][a][b][c][is]表示当前到了第i位, 三个数的i位各自是a,b,c, 是否有进位 , 的方法数. 细节參见代码: #include<cstdio ...

  6. hdu 4549 M斐波那契数列(矩阵高速幂,高速幂降幂)

    http://acm.hdu.edu.cn/showproblem.php?pid=4549 f[0] = a^1*b^0%p,f[1] = a^0*b^1%p,f[2] = a^1*b^1%p... ...

  7. Java遍历一个文件夹下的全部文件

    Java工具中为我们提供了一个用于管理文件系统的类,这个类就是File类,File类与其它流类不同的是,流类关心的是文件的内容.而File类关心的是磁盘上文件的存储. 一,File类有多个构造器,经常 ...

  8. android api level对应表(copy)

    Platform Version API Level VERSION_CODE Notes Android 4.4 19 KITKAT Platform Highlights Android 4.3 ...

  9. 9.23 NOIP模拟题(数学专练)

    数论基础 专题测试  命题人:清华大学 王赢绪 /* 水题 答案为C(n-k,m-1) 预处理阶乘和逆元,O(1)算答案 开始读错题了!!!朱一乐!!! */ #include<iostream ...

  10. codevs1574广义斐波那契数列

    1574 广义斐波那契数列  时间限制: 1 s  空间限制: 256000 KB  题目等级 : 钻石 Diamond     题目描述 Description 广义的斐波那契数列是指形如an=p* ...