UnsatisfiedLinkError: org.opencv.highgui.Highgui.imread when process the image

1.3k Views Asked by At

I have UnsatisfiedLinkError when tried to run the code. So I packed these two classes into a .jar

BrightnessPlugin

package brightness.copy;

import interfaces.IEnhancementOption;
import plugins.IEnhancementPlugin;
import window.EditImageWindow;  

public class BrightnessPlugin implements IEnhancementPlugin
{
    public EditImageWindow editWindow;

    @Override
    public String getName() 
    {
        return "Brightness";
    }

    @Override
    public IEnhancementOption getEnhacement(EditImageWindow editWindow) 
    {
        return new BrightnessEnhancement(editWindow);
    }  

}

Brightness Enhancement

package brightness.copy;

import org.eclipse.swt.events.SelectionEvent;
import org.eclipse.swt.graphics.ImageData;
import org.eclipse.swt.widgets.Composite;
import org.opencv.core.Core;
import org.opencv.core.Mat;
import org.opencv.highgui.Highgui;

import widget.edit.enhancement.AEnhancementOption;
import window.EditImageWindow;

public class BrightnessEnhancement extends AEnhancementOption 
{

public EditImageWindow editWindow;

public BrightnessEnhancement(Composite parent) 
{

    super(parent);
    this.editWindow = (EditImageWindow) parent;
}

@Override
public void initialize() 
{
    setEnhancementName("Brightness");
    this.getButton().addSelectionListener(this);
}

@Override
public void widgetSelected(SelectionEvent e) 
{
    double alpha = 1;
    double beta = 31;
    try{
         System.loadLibrary( Core.NATIVE_LIBRARY_NAME );
         Mat source =  Highgui.imread(editWindow.getImagePath(),Highgui.CV_LOAD_IMAGE_COLOR);
         Mat destination = new Mat(source.rows(),source.cols(),

         source.type());
         source.convertTo(destination, -1, alpha, beta);
         Highgui.imwrite("temp/brightness.jpg", destination);

         ImageData imgData = new ImageData("temp/brightness.jpg");  
         editWindow.setImageData(imgData);
         editWindow.getImageEditor().reCallPicture(imgData);
         editWindow.setEffect("brightness");
      }catch (Exception error) 
    {
         System.out.println("error: " + error.getMessage());
      }

}

@Override
public void widgetDefaultSelected(SelectionEvent e) {
    // TODO Auto-generated method stub
}

}

and then the error UnsatisfiedLinkError showed up, when I tried to implement the BrightnessEnhancement into a picture.

Here's the code to implement the enhancement:

Properties loadProp = new Properties();

    List<IEnhancementPlugin> plugins = PluginManager.getEnhancementPlugins();
    for (IEnhancementPlugin p : plugins)
    {   
        try {
            FileInputStream in = new FileInputStream("Plugins/Enhancement/" + p.getName()+ ".properties");
            loadProp.load(in);
            in.close();
            if(loadProp.getProperty("active").equals("true"))
            {
                addEnhancementOption(p.getEnhacement(this));
            }
        } catch (IOException e) {
            // TODO Auto-generated catch block
            e.printStackTrace();
        }
    }

And the error

 Exception in thread "main" java.lang.UnsatisfiedLinkError: org.opencv.highgui.Highgui.imread_0(Ljava/lang/String;I)J
        at org.opencv.highgui.Highgui.imread_0(Native Method)
        at org.opencv.highgui.Highgui.imread(Highgui.java:316)
        at brightness.copy.BrightnessEnhancement.widgetSelected(BrightnessEnhancement.java:39)
        at org.eclipse.swt.widgets.TypedListener.handleEvent(Unknown Source)
        at org.eclipse.swt.widgets.EventTable.sendEvent(Unknown Source)
        at org.eclipse.swt.widgets.Display.sendEvent(Unknown Source)
        at org.eclipse.swt.widgets.Widget.sendEvent(Unknown Source)
        at org.eclipse.swt.widgets.Display.runDeferredEvents(Unknown Source)
        at org.eclipse.swt.widgets.Display.readAndDispatch(Unknown Source)
        at window.AWindow.show(AWindow.java:22)
        at widget.listimage.ListImage.handleEvent(ListImage.java:74)
        at org.eclipse.swt.widgets.EventTable.sendEvent(Unknown Source)
        at org.eclipse.swt.widgets.Display.sendEvent(Unknown Source)
        at org.eclipse.swt.widgets.Widget.sendEvent(Unknown Source)
        at org.eclipse.swt.widgets.Display.runDeferredEvents(Unknown Source)
        at org.eclipse.swt.widgets.Display.readAndDispatch(Unknown Source)
        at window.AWindow.show(AWindow.java:22)
        at main.Main.main(Main.java:10)

The screenshot is here: https://i.stack.imgur.com/srhsV.jpg The error occurs when I pressed the button.

I've read for other posts and one solution said that to add the System.loadLibrary( Core.NATIVE_LIBRARY_NAME ); I've added the code but the problem still occured. I'll really appreciate if anyone has solution for this problem. Thank you!

P.S. 1. It works if I didn't put them into jar, but I need both of them can be loaded from a jar. 2. It also works when the package was on the project eventhough the function addEnhancement is loaded from .jar.

0

There are 0 best solutions below