PageRenderTime 36ms CodeModel.GetById 0ms RepoModel.GetById 0ms app.codeStats 0ms

/src/Testculture.java

https://bitbucket.org/yan_chen/pc-image-processing
Java | 259 lines | 152 code | 40 blank | 67 comment | 34 complexity | 16c8f0794c083c18115da124922f91a4 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 Testculture{
  7. public static void main (String[] args)throws Exception,NullPointerException
  8. {
  9. int location[][] = new int[16][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. IplImage tmp = cvLoadImage("d.jpg",0);
  17. IplImage result = cvCreateImage(cvSize(src.width()-tmp.width()+1, src.height()-tmp.height()+1), IPL_DEPTH_32F, 1);
  18. cvZero(result);
  19. cvMatchTemplate(src, tmp, result, CV_TM_CCORR_NORMED);
  20. double[] min_val = new double[2];
  21. double[] max_val = new double[2];
  22. CvPoint minLoc = new CvPoint();
  23. CvPoint maxLoc = new CvPoint();
  24. cvMinMaxLoc(result, min_val, max_val, minLoc, maxLoc, null);
  25. CvPoint point = new CvPoint();
  26. point.x(maxLoc.x()+tmp.width());
  27. point.y(maxLoc.y()+tmp.height());
  28. location[task][0] = maxLoc.x();
  29. location[task][1] = maxLoc.y();
  30. location[task][2] = point.x();
  31. location[task][3] = point.y();
  32. // System.out.println(g[p].getName()+" "+task+" ("+maxLoc.x()+", "+maxLoc.y()+") ("+point.x()+", "+point.y()+")");
  33. cvRectangle(src, maxLoc, point, CvScalar.RED, 2, 8, 0);
  34. // cvSaveImage("abc.jpg", src);
  35. // cvShowImage("abc.jpg", src);
  36. // cvWaitKey(0);
  37. //Release
  38. cvReleaseImage(src);
  39. cvReleaseImage(tmp);
  40. cvReleaseImage(result);
  41. }
  42. File f = new File(("C:/Users/chens_000/Desktop/Test/Mouse_location_with_time.txt"));
  43. File h = new File(("C:/Users/chens_000/Desktop/Test/Frame_and_mouselocation_and_keystroke_and_time.txt"));
  44. // File g = new File("C:/Users/chens_000/Desktop/New1/Mrigendra_Singh/Frame_and_mouselocation_and_keystroke_and_time.txt");
  45. // File f = new File("C:/Users/chens_000/Desktop/New1/Mrigendra_Singh/Mouse_location_with_time.txt");
  46. // System.out.println(g[0].getName());
  47. long timestample[] = new long[16];
  48. Scanner s = new Scanner(h);
  49. Scanner r = new Scanner(f);
  50. s.useDelimiter("\\s+|,|\\n|:|;|\\(|\\)| ");
  51. r.useDelimiter("\\s+|,|\\n|:|;|\\(|\\)| ");
  52. long a[] = new long[200000];
  53. long b[] = new long[200000];
  54. int ii = 0;
  55. a[0] = 0;
  56. String c = null;
  57. int jj = 0;
  58. b[0] = 0;
  59. String e = null;
  60. while (s.hasNext())
  61. {
  62. c = s.next();
  63. if (isParsableToInt(c))
  64. {
  65. a[ii] = Long.parseLong(c);
  66. // System.out.println(a[ii]+" ");
  67. ii++;
  68. }
  69. }
  70. while (r.hasNext())
  71. {
  72. e = r.next();
  73. if (isParsableToInt(e))
  74. {
  75. b[jj] = Long.parseLong(e);
  76. // System.out.println(b[jj]+" ");
  77. jj++;
  78. }
  79. }
  80. int k = 0;
  81. int l=4;
  82. int m;
  83. for(int n=0;n<16;n++)
  84. {
  85. for(m=l;m<jj;m+=4)
  86. {
  87. // 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]);
  88. 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))
  89. {
  90. timestample[n]=b[m+3];
  91. // System.out.println(n+" "+location[n][0]+" "+b[m]+" "+location[n][2]+" "+b[m+1]+" "+location[n][3]);
  92. if(n==7)
  93. {
  94. System.out.println("time spend on task 4 = " + (timestample[7]-timestample[6])/1000.000);
  95. }
  96. l=m+4;
  97. break;
  98. }
  99. }
  100. }
  101. int u=4;
  102. int w;
  103. long frame[] = new long[16];
  104. for(int n=0;n<16;n++)
  105. {
  106. for( w=u;w<ii;w++)
  107. {
  108. if( (100000<a[w-3]) & (100000<a[w+1]) & (a[w-3]<=timestample[n]) & (timestample[n]<=a[w+1]))
  109. {
  110. // System.out.println(n+" "+w+" "+a[w-3]+" "+timestample[n]+" "+a[w+1]);
  111. frame[n] = a[w];
  112. System.out.println(n+" "+frame[n]+" tt "+timestample[n]);
  113. u=w;
  114. break;
  115. }
  116. }
  117. }
  118. /*
  119. long d[] = new long[ii];
  120. for (int j = 0; j < ii; j++)
  121. {
  122. d[j] = Long.parseLong(a[j]);
  123. }
  124. k=0;
  125. for (int j = 1; j <ii; j++)
  126. {
  127. if(d[j]>90000)
  128. k++;
  129. }
  130. long m[]=new long[k];
  131. k=0;
  132. for( int j=1;j<ii;j++)
  133. {
  134. if(d[j]>90000)
  135. {
  136. m[k]=d[j];
  137. k++;
  138. }
  139. }
  140. int count1=0;
  141. int temp=0;
  142. for(int j=1;j<k;j++)
  143. {
  144. for(int ij=2;ij<=jj/4;ij++)
  145. {
  146. if((m[j-1]<=b[ij*4-1])&(b[ij*4-1]<m[j]))
  147. {
  148. 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))
  149. count1++;
  150. }
  151. }
  152. System.out.println(count1);
  153. count1=0;
  154. }
  155. */
  156. }
  157. public static int taskorder(String i){
  158. int j = 0;
  159. if(i.equals("task1.jpg"))
  160. j=0;
  161. if(i.equals("task2.jpg"))
  162. j=1;
  163. if(i.equals("task3.jpg"))
  164. j=2;
  165. if(i.equals("task3a.jpg"))
  166. j=3;
  167. if(i.equals("task3b.jpg"))
  168. j=4;
  169. if(i.equals("task3c.jpg"))
  170. j=5;
  171. if(i.equals("task3d.jpg"))
  172. j=6;
  173. if(i.equals("task4.jpg"))
  174. j=7;
  175. if(i.equals("task5.jpg"))
  176. j=8;
  177. if(i.equals("task6.jpg"))
  178. j=9;
  179. if(i.equals("task7.jpg"))
  180. j=10;
  181. if(i.equals("task8.jpg"))
  182. j=11;
  183. if(i.equals("task9.jpg"))
  184. j=12;
  185. if(i.equals("task10.jpg"))
  186. j=13;
  187. if(i.equals("task11.jpg"))
  188. j=14;
  189. if(i.equals("task12.jpg"))
  190. j=15;
  191. return j;
  192. }
  193. public static boolean isParsableToInt(String i) {
  194. try
  195. {
  196. Long.parseLong(i);
  197. return true;
  198. }
  199. catch (NumberFormatException nfe)
  200. {
  201. return false;
  202. }
  203. }
  204. }