Our inference script is quite simple. It will first prepare a drawing function, then load the model and connect it to the camera. Then, it will loop over the frames from the video stream. In the loop, for each frame of the stream, it will use the imported model to make an inference and the drawing function to display the results. Let's create a complete script using the following steps:
- First, we import the required modules:
import numpy as np
import cv2
import tensorflow.keras as K
In this code, besides importing NumPy and OpenCV, we have also imported Keras. We are going to use Keras to make predictions in this script; additionally, we will use it to create and train our models throughout the chapter.
- Then, we define a function to draw localization bounding boxes on a frame:
def draw_box(frame: np.ndarray, box: np.ndarray) -> np.ndarray...