使用OpenCV和Python从图像中提取形状

本文介绍了如何利用OpenCV和Python从图像中提取台球和台球桌边缘。通过将RGB图像转换为HSV格式,然后使用边缘检测技术,如Canny和Sobel函数,来识别和提取目标。通过寻找轮廓和最小外接矩形,可以检测到球的轮廓,并用OpenCV的`minEnclosingCircle()`函数绘制出统一大小的圆。对于桌子边缘,使用HSV方法获取边缘掩模,然后通过`HoughLines()`函数检测水平和垂直线,最终绘制出内边缘。
摘要由CSDN通过智能技术生成

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()”函数来获取提取的蒙版的可视化效果,如下所示。

  • 0
    点赞
  • 7
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值