Sunday, May 6, 2012

complete 2d to 3d blueprint visualization by image processing

Its been a month since i finished  the project an man i forgot to blog about it . Here u could see how i completed the project which i thought i could never finish and as well some new things that i learnt from it so here it comes.

Firstly as you can see my previous post i was completely unplanned before starting the project , every 1 does mistakes:). so here i started the project with little knowledge about java.  so working on the first part was pretty easy ie processing the blueprint and obtaining the various symbols.
                                                         So this was one of my  test blueprints.

 So my job was  to identify the symbols from this image as it was drawn to perfect we just needed to image map the symbols and store the coordinates.But as there could be a pixel mismatch i had to convert the image into binary format like below 

                      this is done by a small code with the help of pixel grabber using the below code.


private int[][] binimage(BufferedImage bi1) {
        PixelGrabber pg = null;
        int data[] = new int[h * w];
        pg = new PixelGrabber(bi1, 0, 0, w, h, data, 0, w); // pix[(j - y) * scansize + (i - x) + off].g
        try {
            pg.grabPixels();
        } catch (Exception e) {
            e.printStackTrace();
        }
        int r, g, b, p;
        int i, j;
        int edge[][] = new int[w][h];
        int blackThreshold = 180;
        for (i = 0; i < w; i++) {
            for (j = 0; j < h; j++) {
                p = data[j * w + i];     //pix[(j - y) * scansize + (i - x) + off].
                r = 0xff & p >> 16;
                g = 0xff & p >> 8;
                b = 0xff & p;
                p = (int) (0.33 * r + 0.56 * g + 0.11 * b); // Convert to gray Scale
                if (p <= blackThreshold) {
                    p = 1;
                } else {
                    p = 0;
                }
                edge[i][j] = p;
            }
        }
        return edge;
    }

After its conversion its just require few for loops to find the various predefined symbols  as below.                
 
window
vent
     And these values are then later used to place the various 3d objects in java 3d so this finishes our first part placing the objects in the universe much easier part where you just needed to place the already created 3d objects into the universe and add some texture to it which made it more attractive.




This made me feel very good an man made me more interested into it  and here i was to create the final part of the project, " the WALK THROUGH" man i was pretty scared and absolutely had no idea how to do this . But to my luck while searching in the net  i came across an example program in java 3d which gave me the exact coding that i needed . i just needed to make few changes in the code and there it was a fully functional system i could move through the building like a ghost man it was my happiest moment :).
an i found this code in the last example in the following url

in this web site

download 
the last example in this has a code which is very useful for creating walk through in j3d












































No comments:

Post a Comment