Thursday, June 17, 2010

Weekly Report 7

This week I tried to integrate the image processing module to the project, after testing the surf method in-depth. Since image processing should be as fast as possible, I implemented it in c++ using opencv library. But I implemented various parts of the server side in java for the sake of simplicity. Therefore, I had two options during integration process:
  1. using java native api
  2. calling the c++ program as a process
First I tried to use native api. After being successful on a simple hello world program I tried to link dll's of opencv and compile the c++ code with native api. But there were so much dependencies on various dll's and it was hard for me to manage integration with native api. Then I decided to use a java process. The resulting code is as follows:




import java.io.InputStream;
import java.io.OutputStream;
import java.io.BufferedReader;
import java.io.InputStreamReader;

 class cpp_to_java {
     private static void prnt()
     {
        try
        {
            String[] prg = new String[3];
            prg[0] = new String("C:\\Documents and Settings\\cigdem.METU-GR0VQRPB9H\\My Documents\\Visual Studio 2005\\Projects\\deneme\\debug\\deneme.exe " );
            prg[1] = new String("C:\\a.png");
            prg[2] = new String("C:\\b.png");
            Process p = Runtime.getRuntime().exec( prg) ;
            //"C:\\Documents and Settings\\cigdem.METU-GR0VQRPB9H\\My Documents\\Visual Studio 2005\\Projects\\deneme\\debug\\deneme.exe " + "C:\\a.png" + " C:\\b.png"

            //do whatever you want
            //some more code

            BufferedReader stdInput = new BufferedReader(new
InputStreamReader(p.getInputStream()));

        //System.out.println("Here is the standard output of the command:\n");
       String s="";
       int count=0;
       String result="";

      p.waitFor();

         while((s=stdInput.readLine()) !=null){

                count++;
                result = result+s+"\n";
                //System.out.println("result:"+count+": "+result);


        }

         System.out.println(result);

         }catch(Exception exc){/*handle exception*/}

     }

     private static boolean procDone(Process p) {
        try {
            int v = p.exitValue();
            return true;
        }
        catch(IllegalThreadStateException e) {
            return false;
        }
    }

No comments:

Post a Comment