Welcome to the first post in this series of blogs on extracting features from images using OpenCV and Python.
欢迎使用本系列博客的第一篇有关使用OpenCV和Python从图像中提取特征的文章。
Feature extraction from images and videos is a common problem in the field of Computer Vision. In this post, we will consider the task of identifying balls and table edges on a pool table.
从图像和视频中提取特征是计算机视觉领域的普遍问题。 在这篇文章中,我们将考虑识别台球桌上的球和桌子边缘的任务。
Consider the example image below from an online pool game.
考虑下面的在线撞球游戏示例图像。
Let's say we want to mark the positions of every ball in this image and also the four inner edges of the table. There are multiple ways in which this can be done and some methods work better than others for a given image. However, a useful approach is to try and separate out the contents of an image based on their color composition.
假设我们要标记此图像中每个球的位置以及桌子的四个内边缘。 有多种方法可以完成此操作,对于给定的图像,某些方法比其他方法效果更好。 但是,一种有用的方法是尝试根据图像的颜色成分来分离图像的内容。
For example, in the above image, we can see that the tabletop, the balls and the image background all have different colors.
例如,在上图中,我们可以看到桌面,球和图像背景都有不同的颜色。
Hence if we can separate out the colors in the image, we would be closer to solving our problem.
因此,如果我们可以分离出图像中的颜色,那么我们将更接近解决问题。
An easy way to do this is to convert the RBG image into HSV format and then find out the range of H, S and V values corresponding to the object of interest.
一种简单的方法是将RBG图像转换为HSV格式,然后找出与感兴趣对象相对应的H,S和V值的范围。
For details on this step refer to my blog (coming soon) on HSV based extraction.
有关此步骤的详细信息,请参阅我的博客(即将发布)有关基于HSV的提取。
Once we have the HSV color map for the table top, we can use the OpenCV “inRange()” function to obtain a visualization of the extracted mask as below.
一旦获得了桌面的HSV颜色图,就可以使用OpenCV“ inRange()”函数来获取提取的蒙版的可视化效果,如下所示。