/src/Testculture.java
Java | 259 lines | 152 code | 40 blank | 67 comment | 34 complexity | 16c8f0794c083c18115da124922f91a4 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 Testculture{
- public static void main (String[] args)throws Exception,NullPointerException
- {
- int location[][] = new int[16][4];
- File[] g = new File(("C:/Users/chens_000/Desktop/Test/new")).listFiles();
-
- 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(g[p].getName()+" "+task+" ("+maxLoc.x()+", "+maxLoc.y()+") ("+point.x()+", "+point.y()+")");
- cvRectangle(src, maxLoc, point, CvScalar.RED, 2, 8, 0);
- // cvSaveImage("abc.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/Frame_and_mouselocation_and_keystroke_and_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))
- {
- 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=4;
- int m;
- for(int n=0;n<16;n++)
- {
- for(m=l;m<jj;m+=4)
- {
- // System.out.println(n+" "+location[n][0]+" <= "+b[m]+" <= " +location[n][2]+" "+location[n][1]+" <= "+b[m+1]+" <= "+location[n][3]+" "+b[m+2]+" "+b[m+3]);
- if(((location[n][0])<=b[m]) && (b[m]<=(location[n][2])) && (location[n][1]<=b[m+1]) && (b[m+1]<=(location[n][3]+10)) && (b[m+2]==1) && (b[m-2]==1) && ((b[m+3]-b[m-1])<500))
- {
- timestample[n]=b[m+3];
- // System.out.println(n+" "+location[n][0]+" "+b[m]+" "+location[n][2]+" "+b[m+1]+" "+location[n][3]);
- if(n==7)
- {
- System.out.println("time spend on task 4 = " + (timestample[7]-timestample[6])/1000.000);
- }
-
- l=m+4;
- break;
- }
- }
-
- }
- 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(n+" "+frame[n]+" tt "+timestample[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;
- }
- }
-
-
- }