Ask Your Question

Hinesh's profile - activity

2017-11-16 04:31:48 -0600 received badge  Famous Question (source)
2015-12-14 11:25:39 -0600 received badge  Notable Question (source)
2015-05-01 20:19:12 -0600 received badge  Popular Question (source)
2014-04-09 04:40:17 -0600 asked a question Create a jar file including an external library (OpenCV) in eclipse

I'm trying to create an executable jar of my application on a Mac, which uses functions from OpenCV. However when I try to create the jar in eclipse I get this error:

Exception in thread "main" java.lang.UnsatisfiedLinkError: no opencv_java248 in java.library.path
at java.lang.ClassLoader.loadLibrary(ClassLoader.java:1886)
at java.lang.Runtime.loadLibrary0(Runtime.java:849)
at java.lang.System.loadLibrary(System.java:1088)
at imageRegistration.ImageGUI.main(ImageGUI.java:643)

The error I think is because the there is a .dylib file that is linked to the OpenCV jar and is not being packaged with it.

I have found this, which seems to be the same issue I am having, but the solution doesn't work for me. This is what I have done:

public static void libLoad(){
    try{
    InputStream in = ImageGUI.class.getResourceAsStream("/lib/opencv-2.4.8 MAC/build/lib/libopencv_java248.dylib");
    File fileOut = File.createTempFile("lib", ".dylib");

    OutputStream out = FileUtils.openOutputStream(fileOut);
    IOUtils.copy(in, out);
    in.close();
    out.close();
    System.load(fileOut.toString());
    } catch(Exception e) {
        System.out.println("Failed to load opencv native library \n" + e);
    }
}

The error I get when I run this is:

Failed to load opencv native library 
java.lang.NullPointerException
2014-02-15 15:19:49 -0600 asked a question How to get the opencv stitching library for java?

I want to use the opencv stitching library, however they haven't ported the code to java yet. I heard you can use the c++ code in Java and call it using a custom java method. I have no idea how to do this.

Do I need another library to run the c++ code and then use that? or is it much simpler than that?

Ideally I would like to run it natively. Thanks

2014-02-13 17:35:46 -0600 commented question Image stitching module for Java

Do you have any information on how I can do this?

2014-02-13 17:34:57 -0600 received badge  Supporter (source)
2014-02-13 10:55:51 -0600 asked a question Converting BufferedImage to Mat in Java

I've tried this link and have the code below. My program imports images in a BufferedImage format and then displays it to the users. I'm using the matchingTemplate function in OpenCV which requires me to convert it to a Mat format.

The code works if I import the image -> convert it to Mat then save the image using imwrite. The program also allows the user to crop an image and then use the Template matching to compare it to another image. The issue come when I tried to convert the cropped image to Mat I need to convert it from Int to Byte using this code:

im = new BufferedImage(im.getWidth(), im.getHeight(),BufferedImage.TYPE_3BYTE_BGR);

This however results in a black image. But if I get rid of it it only works with imported images and not cropped. What is going on here? I'm certain it is something to do with the coversion process as I have tested the template matching function using read in images.

// Convert image to Mat
public Mat matify(BufferedImage im) {
    // Convert INT to BYTE
    //im = new BufferedImage(im.getWidth(), im.getHeight(),BufferedImage.TYPE_3BYTE_BGR);
    // Convert bufferedimage to byte array
    byte[] pixels = ((DataBufferByte) im.getRaster().getDataBuffer())
            .getData();

    // Create a Matrix the same size of image
    Mat image = new Mat(im.getHeight(), im.getWidth(), CvType.CV_8UC3);
    // Fill Matrix with image values
    image.put(0, 0, pixels);

    return image;

}