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. apache2 ubuntu18.04 配置虚拟端口

    修改3个文件/etc/apache2/apache2.conf/etc/apache2/ports.conf/etc/apache2/sites-available/000-default.conf ...

  2. JavaScript使用正則表達式

    2.0 简单介绍 正則表達式是能够用来查找与给定模式匹配的文本的搜索模式.比如,在上一章中,我们在一个较长的字符串中查找子字符串Cookbook: var testValue = "This ...

  3. Spring的AOP特性

    一.AOP简介 AOP是Aspect-Oriented Programming的缩写,即面向切面编程.利用oop思想,可以很好的处理业务流程,但是不能把系统中某些特定的重复性行为封装到模块中.例如,在 ...

  4. LeetCode 69. Sqrt(x) (平方根)

    Implement int sqrt(int x). Compute and return the square root of x. x is guaranteed to be a non-nega ...

  5. POJ 1741 Tree 树形DP(分治)

    链接:id=1741">http://poj.org/problem?id=1741 题意:给出一棵树,节点数为N(N<=10000),给出N-1条边的两点和权值,给出数值k,问 ...

  6. caffe代码阅读10:Caffe中卷积的实现细节(涉及到BaseConvolutionLayer、ConvolutionLayer、im2col等)-2016.4.3

    一. 卷积层的作用简单介绍 卷积层是深度神经网络中的一个重要的层,该层实现了局部感受野.通过这样的局部感受野,能够有效地减少參数的数目. 我们将结合caffe来解说详细是怎样实现卷积层的前传和反传的. ...

  7. 【转】Android Fragment中使用SurfaceView切换时闪一下黑屏的解决办法

    重构了下之前自己的一个新闻客户端,全部使用了Fragment来进行页面切换,只有一个入口Activity作为程序的启动Activity,其中有一个界面需要调用摄像头识别二维码, 于是就会用到Surfa ...

  8. 【转载】Sybase数据库服务器端安装

    sybase数据库的安装分为服务器端和客户端,本文先介绍一下服务器端的安装. 1.和其他程序一样,双击setup.exe.   2.出现欢迎界面,直接点击next即可.   3.下面选择相应国家的协议 ...

  9. 【转载】Java中Comparable和Comparator比较

    [本文转自]http://www.cnblogs.com/skywang12345/p/3324788.html Comparable 简介 Comparable 是排序接口. 若一个类实现了Comp ...

  10. 洛谷P1731生日蛋糕(dfs+剪枝)

    P1731 生日蛋糕 题目背景 7月17日是Mr.W的生日,ACM-THU为此要制作一个体积为Nπ的M层 生日蛋糕,每层都是一个圆柱体. 设从下往上数第i(1<=i<=M)层蛋糕是半径为R ...