gpt4 book ai didi

java - adaptivethreshold 给出错误(opencv,java)

转载 作者:太空宇宙 更新时间:2023-11-03 22:13:51 24 4
gpt4 key购买 nike

我正在尝试对图像进行自适应阈值处理,但出现此错误:

OpenCV Error: Assertion failed (src.type() == CV_8UC1) in adaptiveThreshold

我似乎无法理解为什么,这是我的代码:

         Mat source = Highgui.imread("camera.jpg", 
Highgui.CV_LOAD_IMAGE_COLOR);

Mat destination = new Mat(source.rows(),source.cols(),source.type());

Imgproc.cvtColor(source, destination, Imgproc.COLOR_RGB2GRAY);

Highgui.imwrite("grayscale.jpg", destination);

Mat source2 = Highgui.imread("grayscale.jpg",
Highgui.CV_LOAD_IMAGE_COLOR);

Mat destination2 = new Mat(source.rows(),source.cols(),source.type());

Imgproc.adaptiveThreshold(source2, destination2, 255,
Imgproc.ADAPTIVE_THRESH_MEAN_C, Imgproc.THRESH_BINARY_INV, 15, 4);

最佳答案

对于 adaptiveThreshold source 应该是 8 位单 channel 图像,但是你正在加载 source2 作为颜色,

所以,换行

 Mat source2 = Highgui.imread("grayscale.jpg", Highgui.CV_LOAD_IMAGE_COLOR);

 Mat source2 = Highgui.imread("grayscale.jpg", Highgui.CV_LOAD_IMAGE_GRAYSCALE);

还有为什么要在adaptiveThreshold之前保存和加载destination图片,直接传给adaptiveThreshold()

关于java - adaptivethreshold 给出错误(opencv,java),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/23109389/

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