我正在尝试将平滑过滤器应用于图像。但我得到了这个错误:
java.awt.image.ImagingOpException: Unable to convolve src image
at java.awt.image.ConvolveOp.filter(ConvolveOp.java:180)
at ocr.Resolution.smoothing(Resolution.java:102)
at ocr.Interface$ButtonListener.actionPerformed(Interface.java:332)
at javax.swing.AbstractButton.fireActionPerformed(AbstractButton.java:1995)
at javax.swing.AbstractButton$Handler.actionPerformed(AbstractButton.java:2318)
at javax.swing.DefaultButtonModel.fireActionPerformed(DefaultButtonModel.java:387)
at javax.swing.DefaultButtonModel.setPressed(DefaultButtonModel.java:242)
at javax.swing.plaf.basic.BasicButtonListener.mouseReleased(BasicButtonListener.java:236)
at java.awt.Component.processMouseEvent(Component.java:6038)
at javax.swing.JComponent.processMouseEvent(JComponent.java:3260)
at java.awt.Component.processEvent(Component.java:5803)
at java.awt.Container.processEvent(Container.java:2058)
at java.awt.Component.dispatchEventImpl(Component.java:4410)
at java.awt.Container.dispatchEventImpl(Container.java:2116)
at java.awt.Component.dispatchEvent(Component.java:4240)
at java.awt.LightweightDispatcher.retargetMouseEvent(Container.java:4322)
at java.awt.LightweightDispatcher.processMouseEvent(Container.java:3986)
at java.awt.LightweightDispatcher.dispatchEvent(Container.java:3916)
at java.awt.Container.dispatchEventImpl(Container.java:2102)
我已经研究过,但找不到任何确切的解决方案。要查看问题的根源,我将图像加载为图标。他们都还好。此问题的原因可能是图像稍后加载,因此无法应用过滤器吗?
此外,我还将应用细化算法和其他一些过滤器。你认为如果在处理而不是 Java 中做更好。感谢您的任何帮助。
filter = new float[] { 1.0f/121.0f, 2.0f/121.0f, 3.0f/121.0f, 2.0f/121.0f, 1.0f/121.0f,
2.0f/121.0f, 7.0f/121.0f, 11.0f/121.0f, 7.0f/121.0f, 2.0f/121.0f,
3.0f/121.0f, 11.0f/121.0f, 17.0f/121.0f, 11.0f/121.0f, 3.0f/121.0f,
2.0f/121.0f, 7.0f/121.0f, 11.0f/121.0f, 7.0f/121.0f, 2.0f/121.0f,
1.0f/121.0f, 2.0f/121.0f, 3.0f/121.0f, 2.0f/121.0f, 1.0f/121.0f};
kernelWidth = 5;
kernelHeight = 5;
BufferedImageOp bufOp ;
BufferedImage bufImg;
Image img;
img = Toolkit.getDefaultToolkit().getImage(Interface.picPath); //load image
ImageSize size = new ImageSize(img);// instance to get image dimensions
bufImg = new BufferedImage (size.getwidth(),size.getheight(),BufferedImage.TYPE_INT_RGB);
try {
bufImg = ImageIO.read(new File(Interface.picPath) );
} catch (IOException ex) {
Logger.getLogger(Resolution.class.getName()).log(Level.SEVERE, null, ex);
}
kernel = new Kernel( kernelWidth, kernelHeight, filter);
bufOp = new ConvolveOp(kernel);
bufImg = bufOp.filter(bufImg, null);