如何检查前景是否被某些颜色包围?

时间:2019-03-21 02:06:55

标签: opencv object-detection

我想检查前轮是否被某种颜色包围(在这种情况下为绿色),或者是否被足够的某种颜色的像素包围。

我有图像并且是蒙版(以下是两个示例):
enter image description here enter image description here
enter image description here enter image description here

我颠倒了遮罩,将对象周围的图像转换为HSV颜色空间并通过绿色过滤:

Rect ballBBox = boundingRect(contour);
Mat ballMask(mask, ballBBox);
Mat ballImg(img, ballBBox);
Mat imgSurroundingBall;
Mat ballMaskInv;
bitwise_not(ballMask, ballMaskInv),
ballImg.copyTo(imgSurroundingBall, ballMaskInv);
Mat imgSurroundingBallHSV;
cvtColor(imgSurroundingBall, imgSurroundingBallHSV, CV_BGR2HSV);

Scalar greenLower = Scalar(35, 100, 20);
Scalar greenUpper = Scalar(70, 255, 255);
Mat areaAroundBall;
inRange(imgSurroundingBallHSV, greenLower, greenUpper, areaAroundBall);

,结果是:
enter image description here enter image description here
enter image description here enter image description here

以下是对象没有被绿色包围的示例:
enter image description here enter image description here enter image description here enter image description here
enter image description here enter image description here enter image description here enter image description here

我的想法之一是在拨号后找到类似于ballMaskareaAroundBall图像的轮廓。但是,由于我的工作量很大,而且找不到类似的人,因此效果不佳。

有什么想法吗?

0 个答案:

没有答案