Forgot your password?
typodupeerror

Comment Re:TERCOM/DSMAC code sample....1/2 (Score 1) 690

import com.sun.image.codec.jpeg.*;import com.sun.image.codec.*;
import javax.imageio.*;import java.awt.*;import java.awt.event.*;
import java.awt.image.*;import java.applet.*;import java.io.*;
import java.lang.*;import java.net.*; // TERCOM algorithm simple applet. This is only to get you started. // Code is completely crappy. Sorry, this code is very very old. // A good TERCOM algorithm will optimize its search using inertial nav data // and use something much better than the crappy linear search here. // This is a very old applet. Progress has advanced way beyond this. // Usage of the applet : Create two images tercom0 & tercom1 in // PNG format (450x300 recommended). On tercom0 put your height/terrain map or // satellite image. on tercom1 leave it black except for the centre where // you can put the scaled down snapshot/RADAR/LIDAR terrain data from your // vehicle (or just cut a bit from tercom0 and put it in the centre to test). // comparing the two it will give you a rough location using the best match. // Your exact location on the satellite image (in x,y coordinates) is : // (matched B coord X-black area X),(matched B coordinate Y-black area Y) // You can then scale this to give longlitude and latitude from the sat. image. // A scale function is included to eventually allow you to automate this // process of taking the photo from your UAV and scaling to map(tercom0) scale. // Use mouse clicks on the applet to force a redraw of the matched regions. // put the following into an html page replace the square brackets with less // and greater than signs. Open up the java console to see the msgs & %match. // [html][head][/head] // [body bgcolor="#FFFFFF" onLoad=document.tercom.letsgo();] // [APPLET WIDTH="700" HEIGHT="500" CODE="tercom.class" name="tercom" SCRIPTABLE] // [/body][/html] // This program is licensed under the GNU General Public License // http://www.gnu.org/gpl (C) 1992-2004 Free Software Foundation Inc.
public class tercom extends Applet { // this code sucks. use for learning only.
int x1=50;int y1=50;String postit=new String(); boolean DEBUG=true;
int w=0; boolean nogo=true;int h=0;Graphics g; // image comparision, differencing & tercom matching applet
BufferedImage f0; BufferedImage f1; BufferedImage d0;
BufferedImage xf0; BufferedImage xf1;
BufferedImage of0; BufferedImage of1; // object only // find image->bufimg cnv. Represent heights in 3D terrain maps with colours.
public void init(){clean(); nogo=false; }
public void letsgo(){try{
while(nogo){Thread.yield();Thread.s leep(100);Threa d.yield();}while(!nogo){
log("Lets go start 1.0.0.h");loader("tercom0.png","tercom1.png");
lo g(" Syncing... ");syncimg(f0,f1,32);log("Lets go done");g=this.getGraphics();
g.drawImage(xf0,0,0, null);log("Drawing..");g.drawI mage(of0,320,0,null);
g.drawImage(xf1,0,200,null) ;log("Drawing..");g.dra wImage(of1,320,200,null);
Thread.yield();nogo=tru e;}}catch(Exception e){log(" "+e.toString());}}
public void loader(String imgstr0, String imgstr1) throws Exception{
this.setBackground(Color.black);g.setF ont(new Font("Sans-Serif", Font.BOLD, 18));
g.setColor(Color.white);postit=new String();repaint();
log(" Image 1:"+new URL(getCodeBase(),imgstr0)+" Image 2:"+new URL(getCodeBase(),imgstr1)+":");
try{URLConnectio n urlConn;
DataInputStream dis;urlConn=(new URL(getCodeBase(),imgstr0)).openConnection();
url Conn.setDoInput(true);urlConn.setUseCaches(fals e);
dis=new DataInputStream(urlConn.getInputStream());
f0=Ima geIO.read(dis); dis.close(); urlConn=null; }catch(Exception xx) {log("Err creating img:"+xx.toString()+" ");}
try{URLConnection urlConn;
DataInputStream dis;urlConn=(new URL(getCodeBase(),imgstr1)).openConnection();
url Conn.setDoInput(true);urlConn.setUseCaches(fals e);
dis=new DataInputStream(urlConn.getInputStream());
f1=Ima geIO.read(dis); dis.close(); urlConn=null; log("complete"); }catch(Exception xx) {log("Err creating img:"+xx.toString()+" ");}}
public void syncimg(BufferedImage ima, BufferedImage imb, int pixl){try{ // sync max EP (error probability-(abs(ep)+abs(diff))/2../2../2), // ep is 0-16777215 0=best. to get ep% (100-((ep/16777215)*100)) 100%=best // sync positions for image 0 & 1, x1y1x2y2 & a1b1a2b2 syncpos
long stt=System.currentTimeMillis();
log("xxsync phase 0 "+((System.currentTimeMillis()-stt) )+"ms");
int[] flatima=returnArray(ima);int[] flatimb=returnArray(imb);
int imaw=flatima[0];int imah=flatima[1];int imbw=flatimb[0];int imbh=flatimb[1];
if((imawimax2){temp2=imax2;}else {temp2=imbx2;}if(i mby2>imay2){temp3=imay2;}else{temp3=imby2;}
bga=n ew int[bgx2][bgy2];
bga=loadarray(bga,ximb,imbx1,imb y1,imbx2,imby2);// do CEP - ax2 since we do a sliding window not a true diff.
bga=loaddiffarray(bga,xima,imax1,imay1,imax 2,imay2 ); calcep=0.0; // calcep=(double)(Math.abs(Math.abs(bga[0][0])/2)%10 0);
for (int i=temp0;i cep){cep=(calcep/temp4); log("calcep:"+calcep+"cep:"+cep+" A:"+imax1+","+imay1);
cepimax1=imax1;cepimay1=ima y1;cepimax2=imax2; cepimay2=imay2;
cepimbx1=imbx1;cepimby1=imby1;cep imbx2=imbx2; cepimby2=imby2;}else{} // do CEP
}} // end loop
bga=new int[bgx2][bgy2];
log("Cep A coord:"+cepimax1+","+cepimay1+"-"+cepimax2+","+cep imay2+" Cep B coord:"+cepimbx1+","+cepimby1+"-"+cepimbx2+","+cep imby2);
log("xxsync phase 3 "+((System.currentTimeMillis()-stt) )+"ms");
log("Bg coords"+bgx1+","+bgy1+"-"+bgx2+","+bgy2);
log("xx sync phase 4 "+((System.currentTimeMillis()-stt) )+"ms");
log(" CEP: "+cep+" %: "+(double)(100.0-((cep/(double)temp4)*(double)100. 0))+" ");
log("xxsync phase 5 "+((System.currentTimeMillis()-stt) )+"ms"); // now crop and obtain images. for eliminating motion, ALSO for object recog. // object is cropped and get from the cropped arrays AFTER applying // null filter i.e. eliminate all with a 0. // for eliminating motion use the cropped arrays as original images instead.
int cropx1=bgx2;int cropx2=0;int cropy1=bgy2;int cropy2=0;
for(int i=cepimax1;i=i){cropx1=i;}if(cropx2=j){cropy1=j;}i f(cropy2 max ) val = max;
else if( val min )val = min;
return( val );}
public BufferedImage makeImage( int[] array ) {
int w = array[ 0 ];int h = array[ 1 ];
BufferedImage bi = new BufferedImage(w,h,BufferedImage.TYPE_INT_RGB);
Gr aphics gx = bi.createGraphics();
gx.drawImage(Toolkit.getDefa ultToolkit().createIma ge(new MemoryImageSource( w, h, array, 2, w ) ), 0, 0, null);
gx.dispose(); return(bi); }
public int returnWidth() {return( w );}
public int returnHeight() {return( h );}
public int[] returnArray( BufferedImage img ) {
int wh = img.getWidth();int hh = img.getHeight();int x=0;
int[] rgbs = new int[(wh*hh)+2];rgbs[x]=wh;x++;rgbs[x]=hh;x++; // img.getRGB(0, 0, wh, hh, rgbs, 2, wh);
for(int i=0;iwh;i++){for(int j=0;jhh;j++){
rgbs[x]=img.getRGB(i, j);x++; }}return( rgbs );}
public static BufferedImage Stretch(int squishx, int squishy, BufferedImage squash){
squash=(BufferedImage)((Image)squash).ge tScaledIns tance(squishx,squishy,Image.SCALE_DEFAULT);
retur n squash;}
public void log(String s){if(DEBUG){System.err.println(s);}}
} // end outer class

Slashdot Top Deals

The reward for working hard is more hard work.

Working...