In this section, we are going to write a software pipeline using the OpenCV and ENet models to perform semantic segmentation on videos. Let's get started:
- Import the necessary packages, such as numpy, imutils, and openCV:
import os
import time
import cv2
import imutils
import numpy as np
DEFAULT_FRAME = 1
WIDTH = 600
- Then, load the class label names:
class_labels = open('./enet-cityscapes/enet-classes.txt').read().strip().split("\n")
- We can load the files from disk if we are supplied with the color file; otherwise, we will need to create the RGB colors for each class:
if os.path.isfile('./enet-cityscapes/enet-colors.txt'):
CV_ENET_SHAPE_IMG_COLORS = open('./enet-cityscapes/enet-colors.txt').read().strip().split("\n")
CV_ENET_SHAPE_IMG_COLORS = [np.array(c.split(",")).astype("int") for c in CV_ENET_SHAPE_IMG_COLORS]
CV_ENET_SHAPE_IMG_COLORS = np.array(CV_ENET_SHAPE_IMG_COLORS...