/src/Trajectory.java
Java | 323 lines | 186 code | 53 blank | 84 comment | 36 complexity | ac675adec8dfbd574c5f1d4a8503da3e MD5 | raw file
- import static com.googlecode.javacv.cpp.opencv_core.*;
- import static com.googlecode.javacv.cpp.opencv_imgproc.*;
- import static com.googlecode.javacv.cpp.opencv_highgui.*;
- import java.io.File;
- import java.util.Scanner;
-
- public class Trajectory{
- public static void main (String[] args)throws Exception,NullPointerException
- {
- int location[][] = new int[16][4];
- File[] g = new File(("C:/Users/chens_000/Desktop/MM")).listFiles();
- CvPoint maxLoc3 = new CvPoint();
- CvPoint point3 = new CvPoint();
- for (int p=0;p <g.length;p++)
- {
-
- // System.out.println(g[p].getName());
- int task = taskorder(g[p].getName());
-
- IplImage src = cvLoadImage(g[p].getPath(),0);
-
- IplImage tmp = cvLoadImage("d.jpg",0);
-
- IplImage result = cvCreateImage(cvSize(src.width()-tmp.width()+1, src.height()-tmp.height()+1), IPL_DEPTH_32F, 1);
-
- cvZero(result);
- cvMatchTemplate(src, tmp, result, CV_TM_CCORR_NORMED);
-
- double[] min_val = new double[2];
- double[] max_val = new double[2];
-
- CvPoint minLoc = new CvPoint();
- CvPoint maxLoc = new CvPoint();
-
-
-
-
- cvMinMaxLoc(result, min_val, max_val, minLoc, maxLoc, null);
-
- CvPoint point = new CvPoint();
-
- point.x(maxLoc.x()+tmp.width());
- point.y(maxLoc.y()+tmp.height());
- location[task][0] = maxLoc.x();
- location[task][1] = maxLoc.y();
- location[task][2] = point.x();
- location[task][3] = point.y();
-
- // System.out.println("("+maxLoc.x()+", "+maxLoc.y()+") ("+point.x()+", "+point.y()+")");
- if(task == 6)
- {
- maxLoc3 = maxLoc;
- point3 = point;
- }
-
- if(task == 7)
- {
- cvRectangle(src, maxLoc3, point3, CvScalar.RED, 2, 8, 0);
- cvRectangle(src, maxLoc, point, CvScalar.RED, 2, 8, 0);
- cvSaveImage("C:/Users/chens_000/Desktop/MM/new9.jpg", src);
- }
- // cvShowImage("abc.jpg", src);
- // cvWaitKey(0);
- //Release
- cvReleaseImage(src);
- cvReleaseImage(tmp);
- cvReleaseImage(result);
-
- }
-
-
- File f = new File(("C:/Users/chens_000/Desktop/Test/Mouse_location_with_time.txt"));
- File h = new File(("C:/Users/chens_000/Desktop/Test/Keystroke_with_time.txt"));
- // File g = new File("C:/Users/chens_000/Desktop/New1/Mrigendra_Singh/Frame_and_mouselocation_and_keystroke_and_time.txt");
- // File f = new File("C:/Users/chens_000/Desktop/New1/Mrigendra_Singh/Mouse_location_with_time.txt");
- // System.out.println(g[0].getName());
- long timestample[] = new long[16];
- Scanner s = new Scanner(h);
- Scanner r = new Scanner(f);
- s.useDelimiter("\\s+|,|\\n|:|;|\\(|\\)| ");
- r.useDelimiter("\\s+|,|\\n|:|;|\\(|\\)| ");
- long a[] = new long[200000];
- long b[] = new long[200000];
-
- int ii = 0;
- a[0] = 0;
- String c = null;
-
- int jj = 0;
- b[0] = 0;
- String e = null;
-
- while (s.hasNext())
- {
- c = s.next();
- if (isParsableToInt(c))
- {
- if(Long.parseLong(c)>100000)
- {
- a[ii] = Long.parseLong(c);
- // System.out.println(a[ii]+" ");
- ii++;
- }
- }
- }
-
- while (r.hasNext())
- {
- e = r.next();
- if (isParsableToInt(e))
- {
- b[jj] = Long.parseLong(e);
- // System.out.println(b[jj]+" ");
- jj++;
- }
- }
-
-
-
- int k = 0;
- int l=0;
- int m;
- for(int n=0;n<16;n++)
- {
- for(m=l;m<jj;m+=4)
- {
- if((location[n][0]<=b[m]) & (b[m]<=location[n][2]) & (location[n][1]<=b[m+1]) & (b[m+1]<=location[n][3]) & (b[m+2]==1) & (b[m+6]==0))
- {
- timestample[n]=b[m+3];
- // System.out.println(n+" "+timestample[n]);
-
- l=m+4;
- break;
- }
- }
-
- }
- int nn=0;
- int mm=4;
- long cc[] = new long[16];
-
- for(int n=0;n<16;n++)
- {
-
- for(nn=mm; nn<ii; nn++)
- {
- if((timestample[n]<=a[nn]) && (a[nn-1]<=timestample[n]))
- {
- cc[n] = a[nn-1];
- System.out.println(cc[n]+" "+n+" "+timestample[n]);
-
- mm = nn+1;
- break;
- }
- }
- }
-
- long xy[][][]= new long[16][10000][2];
- IplImage src = cvLoadImage("C:/Users/chens_000/Desktop/MM/new9.jpg",0);
- // IplImage gray = cvCreateImage(cvGetSize(src), IPL_DEPTH_32F, 1);
- int radius = 1;
- l=0;
- int lo=0;
- for(int n=7;n<8;n++)
- {
- for(m=l;m<jj;m+=4)
- {
-
- if((b[m+3]<=timestample[n])&&(cc[n]<=b[m+3])&&(n!=2))
- {
- xy[n][lo][0] = b[m];
- xy[n][lo][1] = b[m+1];
- System.out.println(n+" "+xy[n][lo][0]+" "+xy[n][lo][1]+" "+b[m+3]+" "+location[7][0]+" "+location[7][1]+" "+location[7][2]+" "+location[7][3]);
- CvPoint center = cvPointFrom32f(new CvPoint2D32f(xy[n][lo][0],xy[n][lo][1]));
-
- cvCircle(src, center, radius, CvScalar.GREEN, 6, CV_AA, 0);
- lo++;
- }
- }
-
- }
- cvSaveImage("C:/Users/chens_000/Desktop/MM/89.jpg", src);
- cvShowImage("Result",src);
- cvWaitKey(0);
- /*
- int u=4;
- int w;
- long frame[] = new long[16];
- for(int n=0;n<16;n++)
- {
- for( w=u;w<ii;w++)
- {
- if( (100000<a[w-3]) & (100000<a[w+1]) & (a[w-3]<=timestample[n]) & (timestample[n]<=a[w+1]))
- {
- // System.out.println(n+" "+w+" "+a[w-3]+" "+timestample[n]+" "+a[w+1]);
- frame[n] = a[w];
- System.out.println(frame[n]);
- u=w;
- break;
- }
-
- }
- }
- /*
- long d[] = new long[ii];
-
-
- for (int j = 0; j < ii; j++)
- {
- d[j] = Long.parseLong(a[j]);
- }
-
-
- k=0;
- for (int j = 1; j <ii; j++)
- {
- if(d[j]>90000)
- k++;
-
- }
-
- long m[]=new long[k];
- k=0;
- for( int j=1;j<ii;j++)
- {
- if(d[j]>90000)
- {
- m[k]=d[j];
-
- k++;
-
- }
- }
-
- int count1=0;
- int temp=0;
- for(int j=1;j<k;j++)
- {
- for(int ij=2;ij<=jj/4;ij++)
- {
- if((m[j-1]<=b[ij*4-1])&(b[ij*4-1]<m[j]))
- {
-
- if(((b[ij*4-2]-b[ij*4-6])!=0) |((b[ij*4-3]-b[ij*4-7])!=0)|((b[ij*4-4])!=0)|((b[ij*4-8])!=0))
- count1++;
-
- }
- }
-
-
-
- System.out.println(count1);
-
- count1=0;
- }
- */
-
- }
-
-
-
-
-
-
- public static int taskorder(String i){
-
-
- int j = 0;
-
- if(i.equals("task1.jpg"))
- j=0;
- if(i.equals("task2.jpg"))
- j=1;
- if(i.equals("task3.jpg"))
- j=2;
- if(i.equals("task3a.jpg"))
- j=3;
- if(i.equals("task3b.jpg"))
- j=4;
- if(i.equals("task3c.jpg"))
- j=5;
- if(i.equals("task3d.jpg"))
- j=6;
- if(i.equals("task4.jpg"))
- j=7;
- if(i.equals("task5.jpg"))
- j=8;
- if(i.equals("task6.jpg"))
- j=9;
- if(i.equals("task7.jpg"))
- j=10;
- if(i.equals("task8.jpg"))
- j=11;
- if(i.equals("task9.jpg"))
- j=12;
- if(i.equals("task10.jpg"))
- j=13;
- if(i.equals("task11.jpg"))
- j=14;
- if(i.equals("task12.jpg"))
- j=15;
-
-
-
- return j;
-
- }
-
- public static boolean isParsableToInt(String i) {
-
- try
- {
- Long.parseLong(i);
- return true;
- }
- catch (NumberFormatException nfe)
- {
- return false;
- }
- }
-
-
- }