之前已经训练出自己的MASK-RCNN模型,并在单张图片上经行了测试,那么如何在摄像头中实时检测呢,今天就实现这个功能。其实方法很简单,主要就是获取摄像头的frame,然后对这个frame进行检测就行了。
import cv2
import numpy as np
from mrcnn.config import Config
class MouseConfig(Config):
"""Configuration for training on the toy dataset.
Derives from the base Config class and overrides some values.
"""
# Give the configuration a recognizable name
NAME = "mouse"
# We use a GPU with 12GB memory, which can fit two images.
# Adjust down if you use a smaller GPU.
IMAGES_PER_GPU = 1
# Number of classes (including background)
NUM_CLASSES = 1 + 1 # Background + balloon
# Number of training steps per epoch
STEPS_PER_EPOCH = 100
# Skip detections with < 90% confidence
DETECTION_MIN_CONFIDENCE = 0.9
def random_colors(N):
np.random.seed(1)
colors = [tuple(255 * np.random.r