PageRenderTime 105ms CodeModel.GetById 17ms RepoModel.GetById 1ms app.codeStats 0ms

/src/Thinkingtime_for_copy_task.java

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