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. bzoj——2982: combination

    2982: combination Time Limit: 1 Sec  Memory Limit: 128 MBSubmit: 611  Solved: 368[Submit][Status][Di ...

  2. 洛谷——P1255 数楼梯

    题目描述 楼梯有N阶,上楼可以一步上一阶,也可以一步上二阶. 编一个程序,计算共有多少种不同的走法. 输入输出格式 输入格式: 一个数字,楼梯数. 输出格式: 走的方式几种. 输入输出样例 输入样例# ...

  3. Container/Injection 为什么会出现容器的思路,以后会有什么的趋势,未来是怎样的

    一.为什么会出现容器的思路? 容器概念始于 1979 年提出的 UNIX chroot,它是一个 UNIX 操作系统的系统调用,将一个进程及其子进程的根目录改变到文件系统中的一个新位置,让这些进程只能 ...

  4. jconsole远程连接 jmx配置注意事项

    由于在测试程序时需要收集程序运行时的内存,CPU等消耗情况.选择了jconsole这个jdk自带工具来观察.为了不影响程序运行状态,用远程连接的方式来具体观察. 首先,程序是放在ubutun系统服务器 ...

  5. Cocos2d-html5入门之2048游戏

    一.介绍 Cocos2d-JS是Cocos2d-x的Javascript版本,它的前身是Cocos2d-html5.在3.0版本以前叫做Cocos2d-html5,从3.0版本开始叫做Cocos2d- ...

  6. LeetCode 1002. Find Common Characters (查找常用字符)

    题目标签:Array, Hash Table 题目给了我们一个string array A,让我们找到common characters. 建立一个26 size 的int common array, ...

  7. NoSql的易扩展性

    NoSql现在很火很时髦,大家言必称NoSql,仿佛关系型数据库已成陈旧落后的代名词. 但依我看,真正理解NoSql的还不多,在实际项目中用过的应该就更少了. 我也还不理解,更没怎么应用过,所以现在要 ...

  8. MySQL5.6 GTID方式,配置主从

    迁移数据到从库 数据导出: mysqldump -uroot -p111111 -h127. -P3306 -q --single-transaction -R -E --triggers --def ...

  9. 行政区划代码(SQL版本)2018年8月

    表结构:(新建好表字段即可直接copy insert SQL语句) SQL语句: INSERT INTO z_regioncode(regioncode,regionname,pcode) VALUE ...

  10. java普通代码块、静态代码块、默认构造方法的执行顺序

    package test; class Parent{ { System.out.println("父类普通代码块"); } static{ System.out.println( ...