Java + OpenCv Max external


    Feb 18 2014 | 10:19 pm
    Hi I need help to use opencv inside an mxj object... I compiled the new Opencv 2.4.8 moved the .jar file into the jar directory of max and moved the .dylib in usr/lib/java
    my code is this: import com.cycling74.max.*; import org.opencv.core.Core; import org.opencv.core.CvType; import org.opencv.core.Mat; import org.opencv.core.Scalar;
    public class MaxTest extends MaxObject {
    static{ System.loadLibrary(Core.NATIVE_LIBRARY_NAME); }
    private static final String[] INLET_ASSIST = new String[]{ "inlet 1 help" }; private static final String[] OUTLET_ASSIST = new String[]{ "outlet 1 help" };
    public MaxTest(Atom[] args) { declareInlets(new int[]{DataTypes.ALL}); declareOutlets(new int[]{DataTypes.ALL});
    setInletAssist(INLET_ASSIST); setOutletAssist(OUTLET_ASSIST);
    post("La versione di OpenCV caricata è la: " + Core.VERSION); post("La versione della Java Virtual Machine è: " + System.getProperty("java.version")); post("Il library path è: " + System.getProperty("java.library.path"));
    }
    public void bang() { outlet(0, "OK!"); post(System.getProperty("java.library.path")); System.loadLibrary(Core.NATIVE_LIBRARY_NAME);
    Mat m = new Mat(5, 10, CvType.CV_8UC1, new Scalar(0)); post("OpenCV Mat: " + m); Mat mr1 = m.row(1); mr1.setTo(new Scalar(1)); Mat mc5 = m.col(5); mc5.setTo(new Scalar(5)); post("OpenCV Mat data:\n" + m.dump()); }
    }
    I get this in the max window: MXJ System CLASSPATH: /Applications/Max 6.1/Cycling '74/java/lib/ffmpeg-1.2-macosx-x86_64.jar /Applications/Max 6.1/Cycling '74/java/lib/jitter.jar /Applications/Max 6.1/Cycling '74/java/lib/jode-1.1.2-pre-embedded.jar /Applications/Max 6.1/Cycling '74/java/lib/jython-standalone-2.5.2.jar /Applications/Max 6.1/Cycling '74/java/lib/log4j-1.2.16.jar /Applications/Max 6.1/Cycling '74/java/lib/max.jar /Applications/Max 6.1/Cycling '74/java/lib/net.loadbang.jython-1.2.1.jar /Applications/Max 6.1/Cycling '74/java/lib/net.loadbang.lib-1.8.0.jar /Applications/Max 6.1/Cycling '74/java/lib/net.loadbang.scripting-1.1.0.jar /Applications/Max 6.1/Cycling '74/java/lib/opencv-248.jar MXJClassloader CLASSPATH: /Applications/Max 6.1/Cycling '74/java/classes/ /Volumes/SSD/Applications/Max 6.1/packages/TapTools/java-classes Jitter initialized Jitter Java support installed La versione di OpenCV caricata è la: 2.4.8.0 La versione della Java Virtual Machine è: 1.6.0_65 Il library path è: .:/Library/Java/Extensions:/System/Library/Java/Extensions:/usr/lib/java print: OK! .:/Library/Java/Extensions:/System/Library/Java/Extensions:/usr/lib/java java.lang.UnsatisfiedLinkError: org.opencv.core.Mat.n_Mat(IIIDDDD)J at org.opencv.core.Mat.n_Mat(Native Method) at org.opencv.core.Mat.(Mat.java:541) at MaxTest.bang(MaxTest.java:43)
    I tried and gogooled for very long time, can anyone help me? Thanks

    • Feb 27 2014 | 5:04 pm
      I'm guessing a version mismatch between your code and the actual loaded version of OpenCV. The UnsatisfiedLinkError might be a change in the arguments to n_Mat (you're calling with 3 x int and 4 * double).
    • Mar 31 2014 | 5:09 pm
      Thanks Nick, I tested the same code in an Eclipse project and it works, I get errors only inside max...
    • Mar 11 2015 | 2:54 pm
      Any news on this?
    • Nov 08 2015 | 6:15 pm
      I've got the same error with OpenCV 3.0.0, Max7, Win 7 32bit :( anyone?
    • Sep 15 2017 | 12:07 am
      I tried again today and it seems I sovled my problem, I use Max 7 64 bit under Windows 7 64 bit, I used the right dll x64 and the JRE 1.7:
      Version OpenCV : 3.0.0 Version JVM : 1.7.0_79
      If it can help