Segmenting a scene using the Fully Convolutional Network (FCN) model
In this recipe, you will learn how to perform semantic segmentation of an arbitrary image into 21 classes, such as person, car, and bird. This piece of functionality is useful when an understanding of a scene is required; for example, in augmented reality applications and for driver assistance. To know more visit https://arxiv.org/abs/1605.06211.
Getting ready
Before you proceed with this recipe, you need to install the OpenCV 3.x Python API package.
Download model weights from http://dl.caffe.berkeleyvision.org/fcn8s-heavy-pascal.caffemodel and save the file into the data folder.
How to do it...
You need to complete these steps:
- Import the modules:
import cv2 import numpy as np
- Import the
Caffe
model:
model = cv2.dnn.readNetFromCaffe('../data/fcn8s-heavy-pascal.prototxt', '../data/fcn8s-heavy-pascal.caffemodel')
- Load the image and perform inference:
frame = cv2.imread('../data/scenetext01.jpg') blob...