PageRenderTime 154ms CodeModel.GetById 1ms RepoModel.GetById 0ms app.codeStats 0ms

/src/Thinkingtime_special.java

https://bitbucket.org/yan_chen/pc-image-processing
Java | 362 lines | 238 code | 57 blank | 67 comment | 49 complexity | 4fe6a6daf644e14002f38ad55036296a MD5 | raw file
  1. import static com.googlecode.javacv.cpp.opencv_core.*;
  2. import static com.googlecode.javacv.cpp.opencv_imgproc.*;
  3. import static com.googlecode.javacv.cpp.opencv_highgui.*;
  4. import java.io.File;
  5. import java.util.Scanner;
  6. public class Thinkingtime_special{
  7. public static void main (String[] args)throws Exception,NullPointerException
  8. {
  9. int location[][] = new int[17][4];
  10. File[] g = new File(("C:/Users/chens_000/Desktop/Test/new")).listFiles();
  11. for (int p=0;p <g.length;p++)
  12. {
  13. // System.out.println(g[p].getName());
  14. int task = taskorder(g[p].getName());
  15. IplImage src = cvLoadImage(g[p].getPath(),0);
  16. if(task == 0)
  17. {
  18. IplImage tmp1 = cvLoadImage("e.jpg",0);
  19. IplImage result1 = cvCreateImage(cvSize(src.width()-tmp1.width()+1, src.height()-tmp1.height()+1), IPL_DEPTH_32F, 1);
  20. cvZero(result1);
  21. cvMatchTemplate(src, tmp1, result1, CV_TM_CCORR_NORMED);
  22. double[] min_val = new double[2];
  23. double[] max_val = new double[2];
  24. CvPoint minLoc = new CvPoint();
  25. CvPoint maxLoc = new CvPoint();
  26. cvMinMaxLoc(result1, min_val, max_val, minLoc, maxLoc, null);
  27. CvPoint point = new CvPoint();
  28. point.x(maxLoc.x()+tmp1.width());
  29. point.y(maxLoc.y()+tmp1.height());
  30. location[task][0] = maxLoc.x();
  31. location[task][1] = maxLoc.y();
  32. location[task][2] = point.x();
  33. location[task][3] = point.y();
  34. cvReleaseImage(src);
  35. cvReleaseImage(tmp1);
  36. cvReleaseImage(result1);
  37. continue;
  38. }
  39. IplImage tmp = cvLoadImage("d.jpg",0);
  40. IplImage result = cvCreateImage(cvSize(src.width()-tmp.width()+1, src.height()-tmp.height()+1), IPL_DEPTH_32F, 1);
  41. cvZero(result);
  42. cvMatchTemplate(src, tmp, result, CV_TM_CCORR_NORMED);
  43. double[] min_val = new double[2];
  44. double[] max_val = new double[2];
  45. CvPoint minLoc = new CvPoint();
  46. CvPoint maxLoc = new CvPoint();
  47. cvMinMaxLoc(result, min_val, max_val, minLoc, maxLoc, null);
  48. CvPoint point = new CvPoint();
  49. point.x(maxLoc.x()+tmp.width());
  50. point.y(maxLoc.y()+tmp.height());
  51. location[task][0] = maxLoc.x();
  52. location[task][1] = maxLoc.y();
  53. location[task][2] = point.x();
  54. location[task][3] = point.y();
  55. // System.out.println(g[p].getName()+" "+task+" ("+maxLoc.x()+", "+maxLoc.y()+") ("+point.x()+", "+point.y()+")");
  56. cvReleaseImage(src);
  57. cvReleaseImage(tmp);
  58. cvReleaseImage(result);
  59. }
  60. File f = new File(("C:/Users/chens_000/Desktop/Test/Mouse_location_with_time.txt"));
  61. File h = new File(("C:/Users/chens_000/Desktop/Test/Frame_and_mouselocation_and_keystroke_and_time.txt"));
  62. File t = new File(("C:/Users/chens_000/Desktop/Test/Keystroke_with_time.txt"));
  63. // File g = new File("C:/Users/chens_000/Desktop/New1/Mrigendra_Singh/Frame_and_mouselocation_and_keystroke_and_time.txt");
  64. // File f = new File("C:/Users/chens_000/Desktop/New1/Mrigendra_Singh/Mouse_location_with_time.txt");
  65. // System.out.println(g[0].getName());
  66. long timestample[] = new long[17];
  67. Scanner s = new Scanner(h);
  68. Scanner r = new Scanner(f);
  69. Scanner v = new Scanner(t);
  70. v.useDelimiter("\\s+|,|\\n|:|;|\\(|\\)| ");
  71. s.useDelimiter("\\s+|,|\\n|:|;|\\(|\\)| ");
  72. r.useDelimiter("\\s+|,|\\n|:|;|\\(|\\)| ");
  73. long a[] = new long[200000];
  74. long b[] = new long[200000];
  75. String d[] = new String[200000];
  76. String q[] = new String[200000];
  77. q[0] = null;
  78. int qq=0;
  79. int ii = 0;
  80. a[0] = 0;
  81. String c = null;
  82. d[0] = null;
  83. int jj = 0;
  84. b[0] = 0;
  85. String e = null;
  86. int kk=0;
  87. while (v.hasNext())
  88. {
  89. q[qq]=v.next();
  90. // System.out.println(q[qq]+" ");
  91. qq++;
  92. }
  93. while (s.hasNext())
  94. {
  95. c = s.next();
  96. d[kk] = c;
  97. // System.out.println(d[kk]);
  98. kk++;
  99. if (isParsableToInt(c))
  100. {
  101. a[ii] = Long.parseLong(c);
  102. // System.out.println(a[ii]+" ");
  103. ii++;
  104. }
  105. }
  106. while (r.hasNext())
  107. {
  108. e = r.next();
  109. if (isParsableToInt(e))
  110. {
  111. b[jj] = Long.parseLong(e);
  112. // System.out.println(b[jj]+" ");
  113. jj++;
  114. }
  115. }
  116. int k = 0;
  117. int l=4;
  118. int m;
  119. int mm;
  120. int ll = 10;
  121. outer: for(int n=0;n<17;n++)
  122. {
  123. if(n<5)
  124. {
  125. for(m=l;m<jj;m+=4)
  126. {
  127. // 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]);
  128. 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))
  129. {
  130. timestample[n]=b[m+3];
  131. // System.out.println(n+" "+location[n][0]+" "+b[m]+" "+location[n][2]+" "+b[m+1]+" "+location[n][3]);
  132. l=m+4;
  133. continue outer;
  134. }
  135. }
  136. }
  137. for(mm = ll; mm<kk;mm++)
  138. {
  139. if(d[mm].equals("Tab"))
  140. for(int mn = mm; mn<mm+40;mn++)
  141. {
  142. if(d[mn].equals("Enter"))
  143. {
  144. timestample[n]= Long.parseLong(d[mn-3]);
  145. ll = mn+1;
  146. // if(n==8)
  147. {
  148. // System.out.println("time spend on task 4 = " + (timestample[8]-timestample[7])/1000.000);
  149. }
  150. continue outer;
  151. }
  152. }
  153. }
  154. }
  155. int u=4;
  156. int w;
  157. long frame[] = new long[17];
  158. for(int n=0;n<17;n++)
  159. {
  160. for( w=u;w<ii;w++)
  161. {
  162. if( (100000<a[w-3]) & (100000<a[w+1]) & (a[w-3]<=timestample[n]) & (timestample[n]<=a[w+1]))
  163. {
  164. // System.out.println(n+" "+w+" "+a[w-3]+" "+timestample[n]+" "+a[w+1]);
  165. frame[n] = a[w];
  166. System.out.println(n+" "+frame[n]+" tt "+timestample[n]);
  167. u=w;
  168. break;
  169. }
  170. }
  171. }
  172. long next[] = new long[17];
  173. int bb = 1;
  174. oo: for(int n=0;n<16;n++)
  175. {
  176. for(int aa=bb; aa<qq;aa++)
  177. {
  178. if (isParsableToInt(q[aa]))
  179. {
  180. if(n==2)
  181. {
  182. next[n] = timestample[n+1];
  183. System.out.println((next[n]-timestample[n])/1000.000);
  184. continue oo;
  185. }
  186. if((Long.parseLong(q[aa])>timestample[n]))
  187. {
  188. for(int run=aa+1;run<aa+10;run++)
  189. {
  190. if(q[run].equals("Press"))
  191. {
  192. next[n]=Long.parseLong(q[run+2]);
  193. bb = run+4;
  194. System.out.println((next[n]-timestample[n])/1000.000);
  195. continue oo;
  196. }
  197. }
  198. }
  199. }
  200. }
  201. }
  202. /*
  203. long d[] = new long[ii];
  204. for (int j = 0; j < ii; j++)
  205. {
  206. d[j] = Long.parseLong(a[j]);
  207. }
  208. k=0;
  209. for (int j = 1; j <ii; j++)
  210. {
  211. if(d[j]>90000)
  212. k++;
  213. }
  214. long m[]=new long[k];
  215. k=0;
  216. for( int j=1;j<ii;j++)
  217. {
  218. if(d[j]>90000)
  219. {
  220. m[k]=d[j];
  221. k++;
  222. }
  223. }
  224. int count1=0;
  225. int temp=0;
  226. for(int j=1;j<k;j++)
  227. {
  228. for(int ij=2;ij<=jj/4;ij++)
  229. {
  230. if((m[j-1]<=b[ij*4-1])&(b[ij*4-1]<m[j]))
  231. {
  232. 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))
  233. count1++;
  234. }
  235. }
  236. System.out.println(count1);
  237. count1=0;
  238. }
  239. */
  240. }
  241. public static int taskorder(String i){
  242. int j = 0;
  243. if(i.equals("pre.jpg"))
  244. j=0;
  245. if(i.equals("task1.jpg"))
  246. j=1;
  247. if(i.equals("task2.jpg"))
  248. j=2;
  249. if(i.equals("task3.jpg"))
  250. j=3;
  251. if(i.equals("task3a.jpg"))
  252. j=4;
  253. if(i.equals("task3b.jpg"))
  254. j=5;
  255. if(i.equals("task3c.jpg"))
  256. j=6;
  257. if(i.equals("task3d.jpg"))
  258. j=7;
  259. if(i.equals("task4.jpg"))
  260. j=8;
  261. if(i.equals("task5.jpg"))
  262. j=9;
  263. if(i.equals("task6.jpg"))
  264. j=10;
  265. if(i.equals("task7.jpg"))
  266. j=11;
  267. if(i.equals("task8.jpg"))
  268. j=12;
  269. if(i.equals("task9.jpg"))
  270. j=13;
  271. if(i.equals("task10.jpg"))
  272. j=14;
  273. if(i.equals("task11.jpg"))
  274. j=15;
  275. if(i.equals("task12.jpg"))
  276. j=16;
  277. return j;
  278. }
  279. public static boolean isParsableToInt(String i) {
  280. try
  281. {
  282. Long.parseLong(i);
  283. return true;
  284. }
  285. catch (NumberFormatException nfe)
  286. {
  287. return false;
  288. }
  289. }
  290. }