如何使用OpenCV检测图像中的彩色色块? [英] How to detect colored patches in an image using OpenCV?

查看:3534
本文介绍了如何使用OpenCV检测图像中的彩色色块?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我试图通过移动相机检测房间条件下的图片(黑白素描)是否有彩色。

I am trying to detect if the picture(black and white sketch) is colored or not in the room conditions by a mobile camera.

我能够得到这个结果

使用以下代码

Mat dest = new Mat (sections[i].rows(),sections[i].cols(),CvType.CV_8UC3);
Mat hsv_image = new Mat (sections[i].rows(),sections[i].cols(),CvType.CV_8UC3);

Imgproc.cvtColor (sections[i],hsv_image,Imgproc.COLOR_BGR2HSV);

List <Mat> rgb = new List<Mat> ();
Core.split (hsv_image, rgb);
Imgproc.equalizeHist (rgb [1], rgb [2]);
Core.merge (rgb, sections[i]);
Imgproc.cvtColor (sections[i], dest, Imgproc.COLOR_HSV2BGR);

Core.split (dest, rgb);

我如何成功找出图像是否有彩色。颜色可以是任何颜色,它有房间条件。请帮助我,因为我是初学者。

How can I sucessfully find out if the image is colored or not. The color can be any and it has room conditions. Please help me on this as I am beginner to it.

谢谢

推荐答案

要处理中的彩色图像,HSV色彩空间是个好方向。我拆分了频道,发现 S 频道很棒。因为 S 颜色的饱和度(饱和度)

To process the colorful image in HSV color-space is a good direction. And I split the channels and find the S channel is great. Because S is Saturation(饱和度) of color.

然后以阈值<$阈值 S c $ c> 100 ,你会得到这个。

Then threshold the S with thresh of 100, you will get this.

在脱粒的二进制图像中分离彩色区域很容易。

It will be easy to separate the colorful region in the threshed binary image.

正如@Mark建议的那样,我们可以使用除固定阈值之外的自适应阈值。因此,在标志中添加 THRESH_OTSU

As @Mark suggest, we can use adaptive thresh other than the fixed one. So, add THRESH_OTSU in the flags.

核心python代码如下所示:

Core python code is presented as follow:

##(1) read into  bgr-space
img = cv2.imread("test.png")

##(2) convert to hsv-space, then split the channels
hsv = cv2.cvtColor(img, cv2.COLOR_BGR2HSV)
h,s,v = cv2.split(hsv)

##(3) threshold the S channel using adaptive method(`THRESH_OTSU`)  
th, threshed = cv2.threshold(s, 100, 255, cv2.THRESH_OTSU|cv2.THRESH_BINARY)

##(4) print the thresh, and save the result
print("Thresh : {}".format(th))
cv2.imwrite("result.png", threshed)


## >>> Thresh : 85.0

相关回答:


  1. 检测图像中的彩色片段

  2. opencv android中的边缘检测

  3. OpenCV C ++ / Obj-C:检测一张纸/方形检测

  1. Detect Colored Segment in an image
  2. Edge detection in opencv android
  3. OpenCV C++/Obj-C: Detecting a sheet of paper / Square Detection

这篇关于如何使用OpenCV检测图像中的彩色色块?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆