我正在尝试对这张照片进行阈值处理,并希望一切都是黑色的,除了带字母的方框。但是,当具有不同亮度的不同图像时,结果会有所不同。
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)
由于图片有更多的黑暗,因此在阈值处理后可以看到图片1。我的代码如下:
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);