gpt4 book ai didi

opencv - 如何使用 OpenCV 检测图像中的色 block ?

转载 作者:太空宇宙 更新时间:2023-11-03 20:47:47 25 4
gpt4 key购买 nike

我正在尝试通过移动摄像头检测图片(黑白素描)在室内条件下是否着色。

enter image description here

我已经能够得到这个结果了

enter image description here

使用下面的代码

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);

我怎样才能成功地确定图像是否是彩色的。颜色可以是任何颜色,它有房间条件。请帮助我,因为我是初学者。

谢谢

最佳答案

HSV color-space 中处理彩色图像是一个很好的方向。我拆分了 channel ,发现 S channel 很棒。因为 S 是颜色的Saturation(饱和度)

enter image description here

然后用 100 的阈值对 S 进行阈值处理,你会得到这个。 enter image description here

脱粒后的二值图像中的彩色区域很容易分离。


正如@Mark 所建议的,我们可以使用自适应阈值而不是固定阈值。因此,在标志中添加 THRESH_OTSU

核心python代码如下:

##(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

enter image description here

相关回答:

  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 - 如何使用 OpenCV 检测图像中的色 block ?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/47342025/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com