mask rcnn训练自己的数据集

2023-05-16

前言

最近迷上了mask rcnn,也是由于自己工作需要吧,特意研究了其源代码,并基于自己的数据进行训练~
本博客参考https://blog.csdn.net/disiwei1012/article/details/79928679#commentsedit

实验目的

这里写图片描述
这里写图片描述
这里写图片描述
这里写图片描述
哎~说多了都是泪,谁让我是工科生呢?只能检测工件了。。。做不了高大上的东西了,哈哈

主要参考及工具

基于Mask RCNN开源项目:https://github.com/matterport/Mask_RCNN
图片标记工具基于开源项目:https://github.com/wkentaro/labelme
训练工具:win10+GTX1060+cuda9.1+cudnn7+tensorflow-gpu-1.6.0+keras-2.1.6,140幅图像,一共3类,1小时左右

有关labelme的使用可以参考:https://blog.csdn.net/shwan_ma/article/details/77823281

有关mask-rcnn和Faster RCNN算法可以参考:
https://blog.csdn.net/linolzhang/article/details/71774168
https://blog.csdn.net/lk123400/article/details/54343550/

准备训练数据集

这是我简历的四个文件夹,下面一一道来~
这里写图片描述
1.pic
这里写图片描述
这是训练的图像,一共700幅

2.json
这里写图片描述
这是通过labelme处理训练图像后生成的文件

3.labelme_json
这里写图片描述
这里写图片描述
这个是处理.json文件后产生的数据,使用方法为labelme_json_to_dataset+空格+文件名称.json,这个前提是labelme要准确安装并激活。但是这样会产生一个问题,对多幅图像这样处理,太麻烦,在这里提供一个工具,可以直接在.json文件目录下转换所有的json文件,链接:json数据转换工具。

4.cv2_mask文件

由于labelme生成的掩码标签 label.png为16位存储,opencv默认读取8位,需要将16位转8位,可通过C++程序转化,代码请参考这篇博文:http://blog.csdn.net/l297969586/article/details/79154150
这里写图片描述
一团黑,不过不要怕,正常的~

源代码

运行该代码,需要安装pycocotools,在windows下安装该工具非常烦,有的可以轻松的安装成功,有的重装系统也很难成功,哎,都是坑~~关于Windows下安装pycocotools请参考:https://blog.csdn.net/chixia1785/article/details/80040172,https://blog.csdn.net/gxiaoyaya/article/details/78363391

测试的源代码

Github上开源的代码,是基于ipynb的,我直接把它转换成.py文件,首先做个测试,基于coco数据集上训练好的模型,可以调用摄像头~~~

import os
import sys
import random
import math
import numpy as np
import skimage.io
import matplotlib
import matplotlib.pyplot as plt
import cv2
import time
# Root directory of the project
ROOT_DIR = os.path.abspath("../")

# Import Mask RCNN
sys.path.append(ROOT_DIR)  # To find local version of the library
from mrcnn import utils
import mrcnn.model as modellib
from mrcnn import visualize
# Import COCO config
sys.path.append(os.path.join(ROOT_DIR, "samples/coco/"))  # To find local version
import coco


# Directory to save logs and trained model
MODEL_DIR = os.path.join(ROOT_DIR, "logs")

# Local path to trained weights file
COCO_MODEL_PATH = os.path.join(MODEL_DIR ,"mask_rcnn_coco.h5")
# Download COCO trained weights from Releases if needed
if not os.path.exists(COCO_MODEL_PATH):
    utils.download_trained_weights(COCO_MODEL_PATH)
    print("cuiwei***********************")

# Directory of images to run detection on
IMAGE_DIR = os.path.join(ROOT_DIR, "images")

class InferenceConfig(coco.CocoConfig):
    # Set batch size to 1 since we'll be running inference on
    # one image at a time. Batch size = GPU_COUNT * IMAGES_PER_GPU
    GPU_COUNT = 1
    IMAGES_PER_GPU = 1

config = InferenceConfig()
config.display()


# 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)

# COCO Class names
# Index of the class in the list is its ID. For example, to get ID of
# the teddy bear class, use: class_names.index('teddy bear')
class_names = ['BG', 'person', 'bicycle', 'car', 'motorcycle', 'airplane',
               'bus', 'train', 'truck', 'boat', 'traffic light',
               'fire hydrant', 'stop sign', 'parking meter', 'bench', 'bird',
               'cat', 'dog', 'horse', 'sheep', 'cow', 'elephant', 'bear',
               'zebra', 'giraffe', 'backpack', 'umbrella', 'handbag', 'tie',
               'suitcase', 'frisbee', 'skis', 'snowboard', 'sports ball',
               'kite', 'baseball bat', 'baseball glove', 'skateboard',
               'surfboard', 'tennis racket', 'bottle', 'wine glass', 'cup',
               'fork', 'knife', 'spoon', 'bowl', 'banana', 'apple',
               'sandwich', 'orange', 'broccoli', 'carrot', 'hot dog', 'pizza',
               'donut', 'cake', 'chair', 'couch', 'potted plant', 'bed',
               'dining table', 'toilet', 'tv', 'laptop', 'mouse', 'remote',
               'keyboard', 'cell phone', 'microwave', 'oven', 'toaster',
               'sink', 'refrigerator', 'book', 'clock', 'vase', 'scissors',
               'teddy bear', 'hair drier', 'toothbrush']
# Load a random image from the images folder
#file_names = next(os.walk(IMAGE_DIR))[2]
#image = skimage.io.imread(os.path.join(IMAGE_DIR, random.choice(file_names)))
cap = cv2.VideoCapture(0)

while(1):
    # get a frame
    ret, frame = cap.read()
    # show a frame
    start =time.clock()
    results = model.detect([frame], verbose=1)
    r = results[0]
    #cv2.imshow("capture", frame)
    visualize.display_instances(frame, r['rois'], r['masks'], r['class_ids'], 
                            class_names, r['scores'])
    end = time.clock()
    print(end-start)
    if cv2.waitKey(1) & 0xFF == ord('q'):
        break

cap.release()
cv2.destroyAllWindows() 

#image= cv2.imread("C:\\Users\\18301\\Desktop\\Mask_RCNN-master\\images\\9.jpg")
## Run detection
#
#results = model.detect([image], verbose=1)
#
#print(end-start)
## Visualize results
#r = results[0]
#visualize.display_instances(image, r['rois'], r['masks'], r['class_ids'], 
#                            class_names, r['scores'])

这里写图片描述
这里写图片描述
这里写图片描述
关于训练好的mask rcnn模型,可从此处下载:https://github.com/matterport/Mask_RCNN/releases,下载好后,配置路径即可

训练数据源代码

# -*- coding: utf-8 -*-

import os
import sys
import random
import math
import re
import time
import numpy as np
import cv2
import matplotlib
import matplotlib.pyplot as plt
import tensorflow as tf
from mrcnn.config import Config
#import utils
from mrcnn import model as modellib,utils
from mrcnn import visualize
import yaml
from mrcnn.model import log
from PIL import Image


#os.environ["CUDA_VISIBLE_DEVICES"] = "0"
# Root directory of the project
ROOT_DIR = os.getcwd()

#ROOT_DIR = os.path.abspath("../")
# Directory to save logs and trained model
MODEL_DIR = os.path.join(ROOT_DIR, "logs")

iter_num=0

# Local path to trained weights file
COCO_MODEL_PATH = os.path.join(ROOT_DIR, "mask_rcnn_coco.h5")
# Download COCO trained weights from Releases if needed
if not os.path.exists(COCO_MODEL_PATH):
    utils.download_trained_weights(COCO_MODEL_PATH)


class ShapesConfig(Config):
    """Configuration for training on the toy shapes dataset.
    Derives from the base Config class and overrides values specific
    to the toy shapes dataset.
    """
    # Give the configuration a recognizable name
    NAME = "shapes"

    # Train on 1 GPU and 8 images per GPU. We can put multiple images on each
    # GPU because the images are small. Batch size is 8 (GPUs * images/GPU).
    GPU_COUNT = 1
    IMAGES_PER_GPU = 2

    # Number of classes (including background)
    NUM_CLASSES = 1 + 3  # background + 3 shapes

    # Use small images for faster training. Set the limits of the small side
    # the large side, and that determines the image shape.
    IMAGE_MIN_DIM = 320
    IMAGE_MAX_DIM = 384

    # Use smaller anchors because our image and objects are small
    RPN_ANCHOR_SCALES = (8 * 6, 16 * 6, 32 * 6, 64 * 6, 128 * 6)  # anchor side in pixels

    # Reduce training ROIs per image because the images are small and have
    # few objects. Aim to allow ROI sampling to pick 33% positive ROIs.
    TRAIN_ROIS_PER_IMAGE = 100

    # Use a small epoch since the data is simple
    STEPS_PER_EPOCH = 100

    # use small validation steps since the epoch is small
    VALIDATION_STEPS = 50


config = ShapesConfig()
config.display()

class DrugDataset(utils.Dataset):
    # 得到该图中有多少个实例(物体)
    def get_obj_index(self, image):
        n = np.max(image)
        return n

    # 解析labelme中得到的yaml文件,从而得到mask每一层对应的实例标签
    def from_yaml_get_class(self, image_id):
        info = self.image_info[image_id]
        with open(info['yaml_path']) as f:
            temp = yaml.load(f.read())
            labels = temp['label_names']
            del labels[0]
        return labels

    # 重新写draw_mask
    def draw_mask(self, num_obj, mask, image,image_id):
        #print("draw_mask-->",image_id)
        #print("self.image_info",self.image_info)
        info = self.image_info[image_id]
        #print("info-->",info)
        #print("info[width]----->",info['width'],"-info[height]--->",info['height'])
        for index in range(num_obj):
            for i in range(info['width']):
                for j in range(info['height']):
                    #print("image_id-->",image_id,"-i--->",i,"-j--->",j)
                    #print("info[width]----->",info['width'],"-info[height]--->",info['height'])
                    at_pixel = image.getpixel((i, j))
                    if at_pixel == index + 1:
                        mask[j, i, index] = 1
        return mask

    # 重新写load_shapes,里面包含自己的类别,可以任意添加
    # 并在self.image_info信息中添加了path、mask_path 、yaml_path
    # yaml_pathdataset_root_path = "/tongue_dateset/"
    # img_floder = dataset_root_path + "rgb"
    # mask_floder = dataset_root_path + "mask"
    # dataset_root_path = "/tongue_dateset/"
    def load_shapes(self, count, img_floder, mask_floder, imglist, dataset_root_path):
        """Generate the requested number of synthetic images.
        count: number of images to generate.
        height, width: the size of the generated images.
        """
        # Add classes,可通过这种方式扩展多个物体
        self.add_class("shapes", 1, "tank") # 黑色素瘤
        self.add_class("shapes", 2, "triangle")
        self.add_class("shapes", 3, "white")
        for i in range(count):
            # 获取图片宽和高

            filestr = imglist[i].split(".")[0]
            #print(imglist[i],"-->",cv_img.shape[1],"--->",cv_img.shape[0])
            #print("id-->", i, " imglist[", i, "]-->", imglist[i],"filestr-->",filestr)
            #filestr = filestr.split("_")[1]
            mask_path = mask_floder + "/" + filestr + ".png"
            yaml_path = dataset_root_path + "labelme_json/" + filestr + "_json/info.yaml"
            print(dataset_root_path + "labelme_json/" + filestr + "_json/img.png")
            cv_img = cv2.imread(dataset_root_path + "labelme_json/" + filestr + "_json/img.png")

            self.add_image("shapes", image_id=i, path=img_floder + "/" + imglist[i],
                           width=cv_img.shape[1], height=cv_img.shape[0], mask_path=mask_path, yaml_path=yaml_path)

    # 重写load_mask
    def load_mask(self, image_id):
        """Generate instance masks for shapes of the given image ID.
        """
        global iter_num
        print("image_id",image_id)
        info = self.image_info[image_id]
        count = 1  # number of object
        img = Image.open(info['mask_path'])
        num_obj = self.get_obj_index(img)
        mask = np.zeros([info['height'], info['width'], num_obj], dtype=np.uint8)
        mask = self.draw_mask(num_obj, mask, img,image_id)
        occlusion = np.logical_not(mask[:, :, -1]).astype(np.uint8)
        for i in range(count - 2, -1, -1):
            mask[:, :, i] = mask[:, :, i] * occlusion

            occlusion = np.logical_and(occlusion, np.logical_not(mask[:, :, i]))
        labels = []
        labels = self.from_yaml_get_class(image_id)
        labels_form = []
        for i in range(len(labels)):
            if labels[i].find("tank") != -1:
                # print "box"
                labels_form.append("tank")
            elif labels[i].find("triangle")!=-1:
                #print "column"
                labels_form.append("triangle")
            elif labels[i].find("white")!=-1:
                #print "package"
                labels_form.append("white")
        class_ids = np.array([self.class_names.index(s) for s in labels_form])
        return mask, class_ids.astype(np.int32)

def get_ax(rows=1, cols=1, size=8):
    """Return a Matplotlib Axes array to be used in
    all visualizations in the notebook. Provide a
    central point to control graph sizes.

    Change the default size attribute to control the size
    of rendered images
    """
    _, ax = plt.subplots(rows, cols, figsize=(size * cols, size * rows))
    return ax

#基础设置
dataset_root_path="train_data/"
img_floder = dataset_root_path + "pic"
mask_floder = dataset_root_path + "cv2_mask"
#yaml_floder = dataset_root_path
imglist = os.listdir(img_floder)
count = len(imglist)

#train与val数据集准备
dataset_train = DrugDataset()
dataset_train.load_shapes(count, img_floder, mask_floder, imglist,dataset_root_path)
dataset_train.prepare()

#print("dataset_train-->",dataset_train._image_ids)

dataset_val = DrugDataset()
dataset_val.load_shapes(7, img_floder, mask_floder, imglist,dataset_root_path)
dataset_val.prepare()

#print("dataset_val-->",dataset_val._image_ids)

# Load and display random samples
#image_ids = np.random.choice(dataset_train.image_ids, 4)
#for image_id in image_ids:
#    image = dataset_train.load_image(image_id)
#    mask, class_ids = dataset_train.load_mask(image_id)
#    visualize.display_top_masks(image, mask, class_ids, dataset_train.class_names)

# Create model in training mode
model = modellib.MaskRCNN(mode="training", config=config,
                          model_dir=MODEL_DIR)

# Which weights to start with?
init_with = "coco"  # imagenet, coco, or last

if init_with == "imagenet":
    model.load_weights(model.get_imagenet_weights(), by_name=True)
elif init_with == "coco":
    # Load weights trained on MS COCO, but skip layers that
    # are different due to the different number of classes
    # See README for instructions to download the COCO weights
    model.load_weights(COCO_MODEL_PATH, by_name=True,
                       exclude=["mrcnn_class_logits", "mrcnn_bbox_fc",
                                "mrcnn_bbox", "mrcnn_mask"])
elif init_with == "last":
    # Load the last model you trained and continue training
    model.load_weights(model.find_last()[1], by_name=True)

# Train the head branches
# Passing layers="heads" freezes all layers except the head
# layers. You can also pass a regular expression to select
# which layers to train by name pattern.
model.train(dataset_train, dataset_val,
            learning_rate=config.LEARNING_RATE,
            epochs=20,
            layers='heads')



# Fine tune all layers
# Passing layers="all" trains all layers. You can also
# pass a regular expression to select which layers to
# train by name pattern.
model.train(dataset_train, dataset_val,
            learning_rate=config.LEARNING_RATE / 10,
            epochs=40,
            layers="all")

这里写图片描述

关于训练过程的参数设置,可在config.py文件中修改,根据自己的要求啦~官方也给出了修改建议:https://github.com/matterport/Mask_RCNN/wiki

可修改的主要有:

BACKBONE = “resnet50” ;这个是迁移学习调用的模型,分为resnet101和resnet50,电脑性能不是特别好的话,建议选择resnet50,这样网络更小,训练的更快。

model.train(…, layers=‘heads’, …) # Train heads branches (least memory)
model.train(…, layers=‘3+’, …) # Train resnet stage 3 and up
model.train(…, layers=‘4+’, …) # Train resnet stage 4 and up
model.train(…, layers=‘all’, …) # Train all layers (most memory)#这里是选择训练的层数,根据自己的要求选择

IMAGE_MIN_DIM = 800
IMAGE_MAX_DIM = 1024#设置训练时的图像大小,最终以IMAGE_MAX_DIM为准,如果电脑性能不是太好,建议调小

GPU_COUNT = 1
IMAGES_PER_GPU = 2#这个是对GPU的设置,如果显存不够,建议把2调成1(虽然batch_size为1并不利于收敛)

TRAIN_ROIS_PER_IMAGE = 200;可根据自己数据集的真实情况来设定

MAX_GT_INSTANCES = 100;设置图像中最多可检测出来的物体数量

数据集按照上述格式建立,然后配置好路径即可训练,在windows训练的时候有个问题,就是会出现训练时一直卡在epoch1,这个问题是因为keras在低版本中不支持多线程(在windows上),推荐keras2.1.6,这个亲测可以~

训练的模型会保存在logs文件夹下,.h5格式,训练好后直接调用即可

测试模型的代码

# -*- coding: utf-8 -*-
import os
import sys
import random
import math
import numpy as np
import skimage.io
import matplotlib
import matplotlib.pyplot as plt
import cv2
import time
from mrcnn.config import Config
from datetime import datetime 
# Root directory of the project
ROOT_DIR = os.getcwd()

# Import Mask RCNN
sys.path.append(ROOT_DIR)  # To find local version of the library
from mrcnn import utils
import mrcnn.model as modellib
from mrcnn import visualize
# Import COCO config
sys.path.append(os.path.join(ROOT_DIR, "samples/coco/"))  # To find local version
from samples.coco import coco


# Directory to save logs and trained model
MODEL_DIR = os.path.join(ROOT_DIR, "logs")

# Local path to trained weights file
COCO_MODEL_PATH = os.path.join(MODEL_DIR ,"mask_rcnn_coco.h5")
# Download COCO trained weights from Releases if needed
if not os.path.exists(COCO_MODEL_PATH):
    utils.download_trained_weights(COCO_MODEL_PATH)
    print("cuiwei***********************")

# Directory of images to run detection on
IMAGE_DIR = os.path.join(ROOT_DIR, "images")

class ShapesConfig(Config):
    """Configuration for training on the toy shapes dataset.
    Derives from the base Config class and overrides values specific
    to the toy shapes dataset.
    """
    # Give the configuration a recognizable name
    NAME = "shapes"

    # Train on 1 GPU and 8 images per GPU. We can put multiple images on each
    # GPU because the images are small. Batch size is 8 (GPUs * images/GPU).
    GPU_COUNT = 1
    IMAGES_PER_GPU = 1

    # Number of classes (including background)
    NUM_CLASSES = 1 + 3  # background + 3 shapes

    # Use small images for faster training. Set the limits of the small side
    # the large side, and that determines the image shape.
    IMAGE_MIN_DIM = 320
    IMAGE_MAX_DIM = 384

    # Use smaller anchors because our image and objects are small
    RPN_ANCHOR_SCALES = (8 * 6, 16 * 6, 32 * 6, 64 * 6, 128 * 6)  # anchor side in pixels

    # Reduce training ROIs per image because the images are small and have
    # few objects. Aim to allow ROI sampling to pick 33% positive ROIs.
    TRAIN_ROIS_PER_IMAGE =100

    # Use a small epoch since the data is simple
    STEPS_PER_EPOCH = 100

    # use small validation steps since the epoch is small
    VALIDATION_STEPS = 50

#import train_tongue
#class InferenceConfig(coco.CocoConfig):
class InferenceConfig(ShapesConfig):
    # Set batch size to 1 since we'll be running inference on
    # one image at a time. Batch size = GPU_COUNT * IMAGES_PER_GPU
    GPU_COUNT = 1
    IMAGES_PER_GPU = 1

config = InferenceConfig()

model = modellib.MaskRCNN(mode="inference", model_dir=MODEL_DIR, config=config)


# 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)

# COCO Class names
# Index of the class in the list is its ID. For example, to get ID of
# the teddy bear class, use: class_names.index('teddy bear')
class_names = ['BG', 'tank','triangle','white']
# Load a random image from the images folder
file_names = next(os.walk(IMAGE_DIR))[2]
image = skimage.io.imread(os.path.join(IMAGE_DIR, random.choice(file_names)))

a=datetime.now() 
# Run detection
results = model.detect([image], verbose=1)
b=datetime.now() 
# Visualize results
print("shijian",(b-a).seconds)
r = results[0]
visualize.display_instances(image, r['rois'], r['masks'], r['class_ids'], 
                            class_names, r['scores'])

这里写图片描述
这里写图片描述
当然,这里由于训练数据太少,效果不是特别好~~~工业上的图像不是太好获取。。。
那么如何把定位坐标和分割像素位置输出呢?其实都在visualize.py文件中,就是里面的display_instances函数。
这里写图片描述
这里写图片描述
最后的输出结果

其中,mask输出box区域内的每个像素为true还是false,依次遍历box里的行和列。
最后,该工程的源代码地址为:https://download.csdn.net/download/qq_29462849/10540423,其中train_test为训练代码,test_model为测试代码,配置好路径,即可直接运行~~~

最后欢迎加入3D视觉工坊,一起交流学习~

在这里插入图片描述

本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)

mask rcnn训练自己的数据集 的相关文章

  • Faster-RCNN解读材料优选

    先吐槽一下 xff0c 目前CSDN上的一些关于AI方面的文章都是靠为了蹭热度粗制滥造 骗人点进去 xff0c 其实什么有价值的内容也没有 xff0c 浪费大家时间 吐槽完毕 1 知乎 一文读懂Faster RCNN xff0c 通过此文能
  • CNN论文-Faster RCNN

    I Motivation FastR CNN中的Selective Search方法速度很慢 xff0c 制约了模型的效率 xff0c Selective Search的缺点有 xff1a 1 基于engineered low level
  • Detect-and-Track论文:3D Mask R-CNN Caffe2源代码解析——2.ResNet18_3D解析

    在上一篇博文中 xff0c 我们对Detect and Track论文源码中模型构建部分进行了代码梳理 xff0c 此篇博文我们对其采用的主干网络ResNet18进行详细分析 参考内容链接如下 xff1a Detect and Track论
  • darknet训练自己的数据集

    参考博客https blog csdn net lilai619 article details 79695109 系统环境 Ubuntu 16 04 xff0d xff11 xff0e 在制作数据时最好先将所有图片重新命名 xff0c 这
  • mask rcnn训练自己的数据集

    前言 最近迷上了mask rcnn xff0c 也是由于自己工作需要吧 xff0c 特意研究了其源代码 xff0c 并基于自己的数据进行训练 本博客参考https blog csdn net disiwei1012 article deta
  • 目标检测 实践

    文章目录 0 数据标注via 一 添加图片 二 定义标记类型 Attributes 三 标注 四 导出标注文件 1 模型 1 1 数据准备 1 2 模型训练 1 3 模型使用 1 4 改进方向 0 数据标注via via工具的界面如下图所示
  • Unity 交叉口蒙版

    有没有办法检测具有一定数量顶点的物体是否撞击平面 如果是这样 我想将其以二进制 黑 白 绘制到平面上或用它创建纹理 而且我也不关心这是否只能通过光线投射或一些棘手的物理操作 着色器 等来创建 我只是想知道什么数学算法可以创建这个 Here
  • 如何使用蒙版为圆形图像添加边框

    这是我的尝试 func round let width bounds width lt bounds height bounds width bounds height let mask CAShapeLayer mask path UIB
  • OpenGL ES:如何用颜色对纹理着色

    我有阿尔法纹理 我想用某种颜色给它着色 所以它会根据颜色 alpha 值进行着色 但整体不透明度将仅由纹理 alpha 定义 这与多重纹理类似 但使用颜色而不是第二个纹理 怎么做 更新 我尝试过设置纹理组合器 颜色着色得很好 但 alpha
  • 在视图上创建遮罩效果

    我想在 UIView 上创建遮罩效果以完成以下任务 我将在屏幕中显示一个密封的盒子 用户将能够触摸 刮擦 屏幕以显示该图像 UIView 后面的内容 类似于那些彩票 你应该刮掉结果顶部的一些封面材料 如果有人能指出我正确的方向那就太棒了 我
  • 为 ObjectBoundingBox 导出 SVG

    我对 SVG 的经验很少 我正在尝试保存来自 illustrator 的路径 以便它可以用作响应式剪贴蒙版 其大小相对于其父级 使用clipPathUnits objectBoundingBox 但是 Illustrator 似乎不允许我在
  • 在Android中绘画时如何遮盖一个简单的区域?

    下面是一个简化的描述 想象一下 我有一个 View 类 它可以绘制一面墙的图片 并且我想在绘制它时切出一个窗口 假设我扩展该 View 类并重写其dispatchDraw 方法来执行以下操作 首先绘制背景 如果有的话 可以通过窗户看到 接下
  • 具有圆角 xml 形状的蒙版布局

    我有这个 LinearLayout
  • Actionscript 3 和动态蒙版

    我有一个容器 MovieClip 用作我需要遮盖的内容区域 当我使用形状在此容器内创建蒙版时 我似乎无法与我在此处创建的其他容器的内容进行交互 例如按钮等 这就是我在代码中所做的 我省略了所有导入等 class MyContainer ex
  • pandas 面板中的布尔掩码

    我在以与 DataFrame 相同的方式屏蔽面板时遇到一些麻烦 我想做的事情感觉很简单 但我还没有找到查看文档和在线论坛的方法 我有一个简单的例子如下 import pandas import numpy as np import date
  • 在 CALayer 上进行过滤,但形状(不一定是不同的)矩形的并集除外

    我想申请一个CIFilter to a CALayer除了矩形的并集区域之外 我发布了我不起作用的代码 它的作用恰恰相反 即过滤器仅应用于矩形而不是外部 func refreshTheFrameWithEffect self layer m
  • ImageMagick - 向图像添加白色透明覆盖层

    我需要拍摄一张正常的图像 并添加白色透明覆盖层 使其看起来像这样 不要注意转换后图像上的文本或它是原始图像的裁剪版本这一事实 我需要简单地将顶部转换为完全相同的图像 只是使用白色透明的覆盖层 我还需要它是一个 cli 命令 更新答案 这更容
  • SpriteKit:如何使用混合模式在图层中打孔

    我有一个简单的场景 添加了一些元素 现在我想专注于一个带有遮罩的特定元素 在与我想要关注的元素相同的位置切割整个元素 与我们在某些游戏第一次启动时看到的显示某种教程非常相似 基本上我添加了一个全屏层alpha 0 7 因此用户仍然可以看到所
  • 使用 OpenCV 从轮廓获取掩模

    我想从我通过 cv findContours 计算的轮廓 它只存在 1 个轮廓 获取图像掩模 然而 虽然我的轮廓变量不为空 但我无法使用 cv drawContours 检索图像蒙版 我的目标图像始终为空 这是我的代码 img mosaic
  • Android 在画布上遮罩位图生成黑色空间

    我有一个蒙版位图 一半是红色 一半是透明的 如下所示https www dropbox com s 931ixef6myzusi0 s 2 png https www dropbox com s 931ixef6myzusi0 s 2 pn

随机推荐

  • 哈希表示例

    哈希表的意义在于高效查找 对于查找来说 xff0c 如果数据量特别大 xff0c 二分查找和哈希表算法十分有用了 二分查找前面已经讲过 xff0c 现来讲讲哈希表算法 就像输入数据数组下标返回数组元素一样 xff0c 这样的查找方式是最高效
  • RS-485通讯协议

    1 硬件层协议 通讯协议主要是实现两个设备之间的数据交换功能 xff0c 通讯协议分硬件层协议和软件层协议 硬件层协议决定数据如何传输问题 xff0c 比如要在设备1向设备2发送0x63 xff0c 0x63的二进制数为0110 0011
  • udp通讯中的connect()和bind()函数

    本文收录于微信公众号 LinuxOK xff0c ID为 xff1a Linux ok xff0c 关注公众号第一时间获取更多技术学习文章 udp是一个基于无连接的通讯协议 xff0c 通讯基本模型如下 可以看出 xff0c 不论是在客户端
  • c语言和c++的相互调用

    本文收录于微信公众号 LinuxOK xff0c ID为 xff1a Linux ok xff0c 关注公众号第一时间获取更多技术学习文章 在实际项目开发中 xff0c c和c 43 43 代码的相互调用是常见的 xff0c c 43 43
  • MSVC 版本号对应

    MSVC 43 43 14 0 MSC VER 61 61 1900 Visual Studio 2015 MSVC 43 43 12 0 MSC VER 61 61 1800 Visual Studio 2013 MSVC 43 43 1
  • SPI通讯协议介绍

    来到SPI通讯协议了 废话两句 xff0c SPI很重要 xff0c 这是我在学校时候听那些单片机开发工程师说的 出来实习 xff0c 到后来工作 xff0c 确实如此 xff0c SPI的使用很常见 xff0c 那么自然重要咯 SPI S
  • Qt多线程中的信号与槽

    1 Qt对象的依附性和事务循环 QThread继承自QObject xff0c 自然拥有发射信号 定义槽函数的能力 QThread默认声明了以下几个关键信号 信号只能声明不能定义 xff1a 1 线程开始运行时发射的信号 span clas
  • TCP/IP协议四层模型

    本文收录于微信公众号 LinuxOK xff0c ID为 xff1a Linux ok xff0c 关注公众号第一时间获取更多技术学习文章 接下来的学习重心会放在Linux网络编程这一块 xff0c 我的博客也会随之更新 参照的书籍有 Li
  • 常见的DoS攻击

    本文收录于微信公众号 LinuxOK xff0c ID为 xff1a Linux ok xff0c 关注公众号第一时间获取更多技术学习文章 拒绝服务攻击DoS Denial of Service xff1a 使系统过于忙碌而不能执行有用的业
  • stm32的can总线理解及应用——程序对应stm32f103系列

    CAN 是Controller Area Network 的缩写 xff08 以下称为CAN xff09 xff0c 是ISO国际标准化的串行通信协议 它的通信速度较快 xff0c 通信距离远 xff0c 最高1Mbps xff08 距离小
  • 多视图几何三维重建实战系列之MVSNet

    点击上方 计算机视觉工坊 xff0c 选择 星标 干货第一时间送达 1 概述 MVS是一种从具有一定重叠度的多视图视角中恢复场景的稠密结构的技术 xff0c 传统方法利用几何 光学一致性构造匹配代价 xff0c 进行匹配代价累积 xff0c
  • LiLi-OM: 走向高性能固态激光雷达惯性里程计和建图系统

    点击上方 计算机视觉工坊 xff0c 选择 星标 干货第一时间送达 编辑丨当SLAM遇见小王同学 声明 本文只是个人学习记录 xff0c 侵权可删 论文版权与著作权等全归原作者所有 xff0c 小王自觉遵守 中华人民共和国著作权法 与 伯尔
  • LITv2来袭 | 使用HiLo Attention实现高精度、快速度的变形金刚,下游任务均实时

    点击上方 计算机视觉工坊 xff0c 选择 星标 干货第一时间送达 作者丨ChaucerG 来源丨集智书童 近两年来 xff0c ViT 在计算机视觉领域的取得了很多重大的突破 它们的高效设计主要受计算复杂度的间接度量 xff08 即 FL
  • 问答|多重曝光相关论文有哪些?

  • ECCV 2022 | 清华&腾讯AI Lab提出REALY: 重新思考3D人脸重建的评估方法

    作者丨人脸人体重建 来源丨人脸人体重建 编辑丨极市平台 极市导读 本文围绕3D人脸重建的评估方式进行了重新的思考和探索 作者团队通过构建新数据集RELAY xff0c 囊括了更丰富以及更高质量的脸部区域信息 xff0c 并借助新的流程对先前
  • Arduino for ESP32-----ESP-NOW介绍及使用

    ESP NOW ESP NOW介绍ESP NOW支持以下特性ESP NOW技术也存在以下局限性获取ESP32的MAC地址ESP NOW单向通信 One way communication ESP32单板间的双向通信一对多通信 xff08 一
  • CLIP还能做分割任务?哥廷根大学提出一个使用文本和图像prompt,能同时作三个分割任务的模型CLIPSeg,榨干CLIP能力...

    点击上方 计算机视觉工坊 xff0c 选择 星标 干货第一时间送达 作者丨小马 来源丨我爱计算机视觉 本篇分享 CVPR 2022 论文 Image Segmentation Using Text and Image Prompts xff
  • Faster RCNN算法解析(附源代码,可以直接运行)

    一 前言知识 1 基于Region Proposal xff08 候选区域 xff09 的深度学习目标检测算法 Region Proposal xff08 候选区域 xff09 xff0c 就是预先找出图中目标可能出现的位置 xff0c 通
  • CycleGAN算法原理(附源代码,可直接运行)

    前言 CycleGAN是在今年三月底放在arxiv xff08 论文地址CycleGAN xff09 的一篇文章 xff0c 文章名为Learning to Discover Cross Domain Relations with Gene
  • mask rcnn训练自己的数据集

    前言 最近迷上了mask rcnn xff0c 也是由于自己工作需要吧 xff0c 特意研究了其源代码 xff0c 并基于自己的数据进行训练 本博客参考https blog csdn net disiwei1012 article deta