2014年4月20日 星期日

SKY2的影像轉換程式


將影像的最亮點找出來,其他的點均刪除,最後轉為ASC檔,利用MESHLAB為PLY檔



 //objects
 PFont f;

 PrintWriter output;

 //colors
 color black=color(0);
 color white=color(255);

 //variables
 int itr;             //iteration
 float pixBright;
 float maxBright=0;
 int maxBrightPos=0;
 int prevMaxBrightPos;
 int row;
 int col;
 int FileCount=1;
 int brightThHold=250;  //ignore the bright point below brightThHold
 int LaserSum=0;
 int LaserNum=0;

 //scanner parameters
 float NumSteps = 271;  //number of steps per revolution
 float AngleLaserCam = 30*PI/180;  //angle between laser and camera [radian]
 float AngleTwoSteps=2*PI/NumSteps;  //angle between 2 steps [radian]

 //coordinates
 float x, y, z;  //cartesian cords., [milimeter]
 float ro;  //first of polar coordinate, [milimeter]
 float fi; //second of polar coordinate, [radian]
 float distance; //distance between brightest pixel and middle of photo [pixel]
 float PixelHor = 5; //pixels per milimeter horizontally 1px=0.2mm
 float PixelVer = 5; //pixels per milimeter vertically 1px=0.2mm

 //================= CONFIG ===================

 void setup() {
   size(640,480);
   strokeWeight(1);
   smooth();
   background(0);

   //fonts
   f=createFont("Arial",16,true);
   //output file
   output=createWriter("RealImage.asc");

 }

 //============== MAIN PROGRAM =================

 void draw() {
    for (itr=0; itr<NumSteps; itr++){
 
     String RealImageFileName="RealImage-"+nf(itr+1, 3)+".png";
 
     PImage RealImage=loadImage(RealImageFileName);
     String LineImageFileName="LineImage-"+nf(itr+1, 3)+".png";
     PImage LineImage=createImage(RealImage.width, RealImage.height, RGB);
     RealImage.loadPixels();
     LineImage.loadPixels();
     int currentPos;
     fi=itr*AngleTwoSteps;
     println(fi);

     for(row=0; row<RealImage.height; row++){  //starting row analysis
     maxBrightPos=0;
     maxBright=0;

       for(col=0; col<RealImage.width; col++){
         currentPos = row * RealImage.width + col;
         pixBright=brightness(RealImage.pixels[currentPos]);
         if(pixBright>maxBright){
           maxBright=pixBright;
           maxBrightPos=currentPos;
           LaserSum=currentPos;
           LaserNum=1;
         }
         if(pixBright==maxBright){
           LaserSum=LaserSum+currentPos;
           LaserNum=LaserNum+1;
         }
         LineImage.pixels[currentPos]=black; //setting all pixels black
       }  // end od a row analysis

      if (maxBright > brightThHold) {
       maxBrightPos=LaserSum/LaserNum;
       LineImage.pixels[maxBrightPos]=white; //setting brightest pixel white
      }
       distance=((maxBrightPos+1-row*RealImage.width)-RealImage.width/2)/PixelHor;
       ro=distance/sin(AngleLaserCam);
 
   
       x=ro * cos(fi);  //changing polar coords to kartesian
       y=ro * sin(fi);
       z=row/PixelVer;
   
       if( (ro>=-30) && (ro<=60) ){              //printing coordinates
         output.println(x + "," + y + "," + z);
       }
   
     }//end of all  row analysis
 
     LineImage.updatePixels();
     LineImage.save(LineImageFileName);
 
   }
   output.flush();
   output.close();

   println("End processing.........");
     noLoop();
 }









沒有留言:

張貼留言