我试图通过移动摄像头检测房间条件下的图片(黑白草图)是否是彩色的。
我已经能够得到这个结果
使用以下代码
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);
我怎样才能成功地找出图像是否是彩色的。颜色可以是任意的,并且有房间条件。请帮助我,因为我是初学者。
Thanks
处理彩色图像HSV color-space
是一个很好的方向。我分割频道并找到S
频道很棒。因为S
is Saturation(饱和度)
的颜色。
Then threshold the S
with thresh of 100
, you will get this.
可以很容易地分离脱粒后的二值图像中的彩色区域。
正如@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
相关回答:
- 检测图像中的彩色部分
- opencv android中的边缘检测
- OpenCV C++/Obj-C:检测一张纸/正方形检测
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)