Manipulating images
As part of a computer vision pipeline for a self-driving car, with or without deep learning, you might need to process the video stream to make other algorithms work better as part of a preprocessing step.
This section will provide you with a solid foundation to preprocess any video stream.
Flipping an image
OpenCV provides the flip()
method to flip an image, and it accepts two parameters:
- The image
- A number that can be 1 (horizontal flip), 0 (vertical flip), or -1 (both horizontal and vertical flip)
Let's see a sample code:
flipH = cv2.flip(img, 1)flipV = cv2.flip(img, 0)flip = cv2.flip(img, -1)
This will produce the following result:

Figure 1.4 – Original image, horizontally flipped, vertically flipped, and both
As you can see, the first image is our original image, which was flipped horizontally and vertically, and then both, horizontally and vertically together.