Mastering OpenCV 4 with Python
上QQ阅读APP看书,第一时间看更新

Summary

In this chapter, we saw that working with images and files is a key element of computer vision projects. A common approach in this kind of project is to load some images first, perform some processing, and then output the processed images. In this chapter, we reviewed this flow. Additionally, in connection with video streams, both cv2.VideoCapture and cv2.VideoWriter were covered. We also looked at the cv2.VideoWriter class for video writing. Two key aspects were reviewed when writing video files—video codecs (for example, DIVX) and video file formats (for example, AVI). To work with video codecs, OpenCV provides FOURCC, a four-byte code. Typical codecs are DIVX, XVID, X264, and MJPG, while typical video file formats are AVI (*.avi), MP4 (*.mp4), QuickTime (*.mov), and Windows Media Video (*.wmv).

We also reviewed the concept of fps and how to calculate it in our programs. Additionally, we looked at how to get all the properties of the cv2.VideoCapture object and how to use them to load a video and output it backwards, showing the last frame of the video first. Finally, we saw how to cope with command-line arguments. Python uses sys.argv to handle command-line arguments. When our programs take complex parameters or multiple filenames, we should use Python's argparse library.

In the next chapter, we are going to learn how to draw basic and more advanced shapes using the OpenCV library. OpenCV provides functions to draw lines, circles, rectangles, ellipses, text, and polylines. In connection with computer vision projects, it is a common approach to draw basic shapes in the image in order to do the following:

  • Show some intermediate results of your algorithm (for example, bounding box of the detected objects)
  • Show the final results of your algorithm (for example, the class of the detected objects, such as cars, cats, or dogs)
  • Show some debugging information (for example, execution time)

Therefore, the next chapter can be of great help in connection with your computer vision algorithms.