Running matlab code from within Processing

Hi there, I would like to know if there is way to run a matlab code from within Processing... The code I am interested in using is: http://ceng.anadolu.edu.tr/cv/EDPF/
Which is C++ as far as I am aware.
I've heard of a thing called "javabuilder" for matlab, but im not sure how I could use it in this situation. Can it be done? Cheers

Tagged:

Answers

  • Do you have MATLAB separately installed on your system, and are your trying to invoke a MATLAB script from within your sketch, e.g. with exec()?

    MATLAB is proprietary, licensed software -- I don't believe that you can run it without MATLAB in any other environment, by design.

  • @jeremydouglass, hey thanks for the response....I ended up getting the c++ source code for this...though it still isnt going to help since there is no c++ mode in Processing.
    Ill ask in a different question, but here as well since its still a line segment detection code, how can I import https://github.com/anfractuosity/LSD
    into Processing? Where would I start?

  • edited March 2018

    If you want to do Processing-like coding in C++, here is always openFrameworks:

    If you are using a Java library instead, you can put it in a /code subfolder of your sketch -- or drag-and-drop onto the PDE window to import.

  • edited March 2018

    Cool yeah, I've been using Openframeworks as well, still prefer Processing though.
    Great, I should have figured that one out on my own lol, too easy.
    I think its working, though im not getting anything other than a grey box...is there something Im missing here?
    Its supposed to use the piet image.

  • We can mix ".pde" & ".java" files in the same folder together w/ the PDE (Processing's IDE).

  • I think its working, though im not getting anything other than a grey box...is there something Im missing here?

    There is no way for us to know what might be wrong unless you share an MCVE.

  • edited March 2018

    I literally just dragged and dropped all the java files from the github into a sketch in Processing: https://github.com/anfractuosity/LSD

    Basically what the code is supposed to do is to extract line segments from an image, so like a much simplified contour.
    The result look like this: http://iie.fing.edu.uy/~jirafa/lsd/technical-report-fig14.html

    I contacted the author, and he has told me for this he was using the "swing GUI kit" and that I would need to change it to use Processing's GUI calls.
    ...im assuming thats refering to the GUI.java ?

  • edited March 2018

    ... and he has told me for this he was using the "swing GUI kit"...

    So this library isn't compatible w/ Processing, b/c direct access to Swing conflicts w/ Processing's own Swing access.

    The library needs to be re-written so it calls Processing's API rather than Java's Swing direct access.

  • edited March 2018

    @GoToLoop
    Aw man, I figured.
    Ok...so I would be changing the GUI.java right?
    How can I call Processing's API instead of swing ?

    import javax.swing.*;
    import javax.imageio.ImageIO;
    import java.awt.image.BufferedImage;
    import java.io.File;
    import java.io.IOException;
    import java.util.HashSet;
    import java.awt.*;
    import java.awt.image.*;
    import javax.swing.*;
    
    
    
    public class GUI extends JFrame {
    
    
        GUI() {
            setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
    
    
            try {
                BufferedImage myPicture = ImageIO.read(new File("piet.jpg"));
                 Graphics2D g2d = myPicture.createGraphics();
                int x = myPicture.getWidth();
                int y = myPicture.getHeight();
    
                HashSet<Line> lines = new HashSet<Line>();
    
    
                double [] arr = myPicture.getData().getPixels(0,0,x,y,new double[x*y*3]);
    
                double [] arr2 = new double[x*y];
    
                System.out.println(arr.length);
                int c=0;
                for(int i = 0; i < arr.length-3; i+=3) {
                    double B = arr[i];
                    double G = arr[i+1];
                    double R = arr[i+2];
                    double level = R * 0.2126 + G * 0.7152 + B * 0.0722;
                    arr2[c++] = level;
                }
    
                LSD lsd = new LSD();
    
                double [] out = lsd.lsd(arr2,x,y);
    
                for(int i = 0; i < lsd.n_out; i++) {
                    for (int j = 0; j < 7; j++)
    
                    lines.add(new Line(out[7 * i + 0], out[7 * i + 1],
                            out[7 * i + 2], out[7 * i + 3]));
    
                }
    
                for ( Line l : lines) {
                    g2d.drawLine((int)l.x1,(int)l.y1,(int)l.x2,(int)l.y2);
                }
    
                JLabel picLabel = new JLabel(new ImageIcon(myPicture));
                add(picLabel);
    
    
            } catch (IOException e) {
    
            }
    
            setSize(800,800);
                setVisible(true);
        }
    
    
        public static void main(String [] args){
            new GUI();
    
        }
    
    
    }
    
  • public class GUI extends JFrame {

    Processing's JAVA2D renderer already got its own instance of JFrame.
    Look for past getFrame() posts: https://Forum.Processing.org/two/discussions/tagged?Tag=getframe()

  • Also you need to learn Processing's API in order to replace those Swing direct calls:
    https://Processing.org/reference/

  • Cool thanks, ill see what I can do.
    I did find something you did a bit back: https://forum.processing.org/two/discussion/12774/embedding-papplet-in-java-jframe

  • edited March 2018

    Im a bit lost. Can you tell me what exactly does this getJframe() do? Currently im trying to do PApplet...

Sign In or Register to comment.