OpenCV 4 Computer Vision Application Programming Cookbook(Fourth Edition)
上QQ阅读APP看书,第一时间看更新

Processing Color Images with Classes

Good computer vision programs begin with good programming practices. Building a bug-free application is just the beginning. What you really want is an application that you, and the programmers working with you, will be able to adapt and evolve easily as new requirements come in. This chapter will show you how to make the best use of some object-oriented programming principles in order to build good-quality software programs. In particular, we will introduce a few important design patterns that will help you build applications with components that are easy to test, maintain, and reuse.

Design patterns are a well-known concept in software engineering. Basically, a design pattern is a sound, reusable solution to a generic problem that occurs frequently in software designing. Many software patterns have been introduced and documented. Good programmers should build a working knowledge of these existing patterns.

This chapter also has a secondary objective. It will teach you how to play with image colors. The example used throughout this chapter will show you how to detect the pixels of a given color, and the last two recipes will explain how to work with different color spaces.

In this chapter, we will cover the following recipes:

  • Comparing colors using the strategy design pattern
  • Segmenting an image with the GrabCut algorithm
  • Converting color representations
  • Representing colors with hue, saturation, and brightness