Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/google-apps-script/5.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
不同图像的阈值设置不起作用(opencv和java)_Java_Opencv_Threshold - Fatal编程技术网

不同图像的阈值设置不起作用(opencv和java)

不同图像的阈值设置不起作用(opencv和java),java,opencv,threshold,Java,Opencv,Threshold,我试图在这张图片上做阈值处理,希望所有的东西都是黑色的,除了有字母的盒子。但是,当使用不同亮度的不同图片时,结果会有所不同 http://imgur.com/fWXnbjA (Picture 1 little bit darker than picture 2) http://imgur.com/WKCv0oF (Picture 2 more brightness) 阈值化后,结果如下所示: http://imgur.com/F4gw0Yh (Picture 1 after threshol

我试图在这张图片上做阈值处理,希望所有的东西都是黑色的,除了有字母的盒子。但是,当使用不同亮度的不同图片时,结果会有所不同

http://imgur.com/fWXnbjA (Picture 1 little bit darker than picture 2)

http://imgur.com/WKCv0oF (Picture 2 more brightness)
阈值化后,结果如下所示:

http://imgur.com/F4gw0Yh (Picture 1 after thresholding)

http://imgur.com/BEuIup2 (Picture 2 after thresholding)
Mat source = Highgui.imread("pbR2Z.jpg", Highgui.CV_LOAD_IMAGE_COLOR);
Mat destination = new Mat(source.rows(), source.cols(), source.type());
Imgproc.cvtColor(source, destination, Imgproc.COLOR_RGB2GRAY);


Core.normalize(destination, destination,0, 255, Core.NORM_MINMAX, CvType.CV_8U);
Mat destination2 = new Mat(source.rows(), source.cols(), source.type());


Imgproc.GaussianBlur(destination, destination2, new Size(3, 3), 1);
Mat destination3 = new Mat(source.rows(), source.cols(), source.type());

Imgproc.threshold(destination2, destination3, 223, 255, Imgproc.THRESH_BINARY);
如图1所示,阈值化后,由于图片的黑暗度更高,因此填充了所有内容。我的代码如下:

http://imgur.com/F4gw0Yh (Picture 1 after thresholding)

http://imgur.com/BEuIup2 (Picture 2 after thresholding)
Mat source = Highgui.imread("pbR2Z.jpg", Highgui.CV_LOAD_IMAGE_COLOR);
Mat destination = new Mat(source.rows(), source.cols(), source.type());
Imgproc.cvtColor(source, destination, Imgproc.COLOR_RGB2GRAY);


Core.normalize(destination, destination,0, 255, Core.NORM_MINMAX, CvType.CV_8U);
Mat destination2 = new Mat(source.rows(), source.cols(), source.type());


Imgproc.GaussianBlur(destination, destination2, new Size(3, 3), 1);
Mat destination3 = new Mat(source.rows(), source.cols(), source.type());

Imgproc.threshold(destination2, destination3, 223, 255, Imgproc.THRESH_BINARY);

你的问题是什么?对于不同的图像,我“希望所有的东西都是黑色的,除了带字母的盒子”。这些图像会有不同的亮度,看起来好像它不会一直工作。有时,由于图像质量的原因,阈值填充框中。我的图像质量会随着时间的推移而变化你可以使用THRESH_OTSU进行自动阈值设置,-但这将永远不会有“一刀切”的解决方案。哦,尝试equalizeHist()而不是normalize(),谢谢!他解决了这个问题!