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论文详解

    Faster RCNN详解 Faster RCNN 是在Fast RCNN的基础上 xff0c 进一步改进 xff0c 解决select search 算法选择候选框速度太慢的问题 Faster R CNN Towards Real Tim
  • faster rcnn论文_Scene Graph Generation领域近年论文分析

    Scene Graph and Visual Relationship论文总结 2019 4 4 更新 2019 CVPR Learning to Compose Dynamic Tree Structures for Visual Con
  • 在py-faster-rcnn/lib里make时报错: unrecognized command line option ‘-Wdate-time’

    在py faster rcnn lib里make时报错 xff1a c 43 43 pthread shared Wl O1 Wl Bsymbolic functions Wl Bsymbolic functions Wl z relro
  • mask rcnn使用指南

    做姿态估计的小伙伴们肯定经常用检测器 xff0c 为了方便大家 xff0c 这里给出一个很方便的教程 让大家快速上手 xff0c 不用再纠结配置环境 xff01 欢迎加入我们的姿态估计群 xff1a 970029323 xff08 xff1
  • 【目标检测】Mask RCNN的训练数据集是什么?(含labelimg和labelme的讲解)

    文章目录 一 训练数据集 二 标注工具介绍 2 1 labelimg介绍 2 2 labelme介绍 2 3 两者的对比 三 制作数据案例 在看完何凯明大神的Mask RCNN的时候 突然想到了一个问题 那就是Mask RCNN的训练数据集
  • (三)目标检测之 R-CNN系列

    目标检测之 R CNN系列 前言 R CNN系列 一 R CNN https arxiv org abs 1311 2524 二 Fast R CNN https arxiv org abs 1504 08083 三 Faster R CN
  • python opencv cv2在图片中画mask掩码/掩膜

    python opencv cv2在图片中画mask掩膜 import cv2 import numpy as np from PIL import Image import matplotlib pyplot as plt mask th
  • 人工智能-目标识别:古典目标识别、R-CNN、SPP-NET、Fast-R-CNN、Faster-R-CNN、YOLO

    古典目标识别 第一部分 训练集构造 负样本 使用 select search ss 方法对区域进行融合 gt 计算每个候选区域域真实标记区域 GRadeonTruts GT 之间的重合 如果区域A与GT的重合度在20 50 之间 而且A与其
  • 深度学习之目标检测与目标识别

    一 目标识别分类及应用场景 目前可以将现有的基于深度学习的目标检测与识别算法大致分为以下三大类 基于区域建议的目标检测与识别算法 如R CNN Fast R CNN Faster R CNN 基于回归的目标检测与识别算法 如YOLO SSD
  • 根据两个图像之间的差异创建蒙版 (iPhone)

    如何检测两个图像之间的差异 创建不同区域的掩模 以便处理两个图像共有的区域 例如高斯模糊 EDIT 我目前正在使用此代码来获取像素的 RGBA 值 NSArray getRGBAsFromImage UIImage image atX in
  • 使用自定义 Painter 在 Flutter 中遮盖两个图像

    你好 谁能告诉我为什么这个掩蔽尝试的背景是黑色的 这一定很接近 但我就是无法消除背景 我看到其他人提到过saveLayer rect paint 是这里的关键 因为它将整个画布矩形推入遮罩操作 这个问题 无屏蔽操作 和this one 没有
  • 将子网掩码“/”符号转换为 Cisco 0.0.0.0 标准

    我已经搜索过寻求帮助 但找不到我的问题的答案 情况 我需要将 NN 子网掩码表示法 例如IPTABLES 转换为0 0 0 0 cisco 表示法 NN 是子掩码中 1 的数量 从最低八位位组到较高八位位组 每个八位位组都是 8 位整数 可
  • 为什么我的 jquery 输入掩码不起作用?

    我正在尝试使用 jQuery 输入掩码插件 jquery maskedinput 1 3 min js 并且我搜索了几个示例 解决方案 并且我的代码与其他工作示例完全相同 但它根本不会为我工作 请记住 我的代码现在只是测试这个插件 尝试让它
  • 带有蒙版的 svg 在 chrome 上看不到

    我正在尝试使用 React 动态创建的一些 svg 路径进行掩码 问题是生成的 html 代码无法立即在 Chrome 和 Safari 上正确呈现 调整浏览器窗口大小或从检查器中选中 取消选中样式属性时会出现正确的结果 我觉得问题出在其中
  • 在 Android 中使用 EditText 小部件屏蔽输入

    有没有办法可以为 Android 中的 EditText 控件指定输入掩码 我希望能够为社会安全号码指定类似 的内容 这将导致任何无效输入被自动拒绝 例如 我输入字母字符而不是数字 我意识到我可以添加 OnKeyListener 并手动检查
  • 在Android中绘画时如何遮盖一个简单的区域?

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

    我使用的 SDK 通过回调提供矩形 glsurfaceview 我希望能够以圆形布局渲染此视图 即 我想在圆形视图上显示视图 我尝试过使用屏蔽布局 例如使用可屏蔽布局https github com christophesmet andro
  • R光栅绘制图像,画一个圆并掩盖圆外的像素

    下面的代码绘制一个图像 然后在该图像上绘制圆圈 我想让该圆圈之外的所有像素都变成黑色 我怎么能这么做呢 library raster library plotrix r1 lt brick system file external rlog
  • 仅将布尔掩码应用于数据帧列的索引部分

    我有一个包含一些列的数据框 gt gt gt np random seed 0xFEE7 gt gt gt df pd DataFrame A np random randint 10 size 10 B np random randint
  • SpriteKit:如何使用混合模式在图层中打孔

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

随机推荐

  • 哈希表示例

    哈希表的意义在于高效查找 对于查找来说 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