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

/src/Trajectory.java

https://bitbucket.org/yan_chen/pc-image-processing
Java | 323 lines | 186 code | 53 blank | 84 comment | 36 complexity | ac675adec8dfbd574c5f1d4a8503da3e 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 Trajectory{
  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/MM")).listFiles();
  11. CvPoint maxLoc3 = new CvPoint();
  12. CvPoint point3 = new CvPoint();
  13. for (int p=0;p <g.length;p++)
  14. {
  15. // System.out.println(g[p].getName());
  16. int task = taskorder(g[p].getName());
  17. IplImage src = cvLoadImage(g[p].getPath(),0);
  18. IplImage tmp = cvLoadImage("d.jpg",0);
  19. IplImage result = cvCreateImage(cvSize(src.width()-tmp.width()+1, src.height()-tmp.height()+1), IPL_DEPTH_32F, 1);
  20. cvZero(result);
  21. cvMatchTemplate(src, tmp, result, 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(result, min_val, max_val, minLoc, maxLoc, null);
  27. CvPoint point = new CvPoint();
  28. point.x(maxLoc.x()+tmp.width());
  29. point.y(maxLoc.y()+tmp.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. // System.out.println("("+maxLoc.x()+", "+maxLoc.y()+") ("+point.x()+", "+point.y()+")");
  35. if(task == 6)
  36. {
  37. maxLoc3 = maxLoc;
  38. point3 = point;
  39. }
  40. if(task == 7)
  41. {
  42. cvRectangle(src, maxLoc3, point3, CvScalar.RED, 2, 8, 0);
  43. cvRectangle(src, maxLoc, point, CvScalar.RED, 2, 8, 0);
  44. cvSaveImage("C:/Users/chens_000/Desktop/MM/new9.jpg", src);
  45. }
  46. // cvShowImage("abc.jpg", src);
  47. // cvWaitKey(0);
  48. //Release
  49. cvReleaseImage(src);
  50. cvReleaseImage(tmp);
  51. cvReleaseImage(result);
  52. }
  53. File f = new File(("C:/Users/chens_000/Desktop/Test/Mouse_location_with_time.txt"));
  54. File h = new File(("C:/Users/chens_000/Desktop/Test/Keystroke_with_time.txt"));
  55. // File g = new File("C:/Users/chens_000/Desktop/New1/Mrigendra_Singh/Frame_and_mouselocation_and_keystroke_and_time.txt");
  56. // File f = new File("C:/Users/chens_000/Desktop/New1/Mrigendra_Singh/Mouse_location_with_time.txt");
  57. // System.out.println(g[0].getName());
  58. long timestample[] = new long[16];
  59. Scanner s = new Scanner(h);
  60. Scanner r = new Scanner(f);
  61. s.useDelimiter("\\s+|,|\\n|:|;|\\(|\\)| ");
  62. r.useDelimiter("\\s+|,|\\n|:|;|\\(|\\)| ");
  63. long a[] = new long[200000];
  64. long b[] = new long[200000];
  65. int ii = 0;
  66. a[0] = 0;
  67. String c = null;
  68. int jj = 0;
  69. b[0] = 0;
  70. String e = null;
  71. while (s.hasNext())
  72. {
  73. c = s.next();
  74. if (isParsableToInt(c))
  75. {
  76. if(Long.parseLong(c)>100000)
  77. {
  78. a[ii] = Long.parseLong(c);
  79. // System.out.println(a[ii]+" ");
  80. ii++;
  81. }
  82. }
  83. }
  84. while (r.hasNext())
  85. {
  86. e = r.next();
  87. if (isParsableToInt(e))
  88. {
  89. b[jj] = Long.parseLong(e);
  90. // System.out.println(b[jj]+" ");
  91. jj++;
  92. }
  93. }
  94. int k = 0;
  95. int l=0;
  96. int m;
  97. for(int n=0;n<16;n++)
  98. {
  99. for(m=l;m<jj;m+=4)
  100. {
  101. 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))
  102. {
  103. timestample[n]=b[m+3];
  104. // System.out.println(n+" "+timestample[n]);
  105. l=m+4;
  106. break;
  107. }
  108. }
  109. }
  110. int nn=0;
  111. int mm=4;
  112. long cc[] = new long[16];
  113. for(int n=0;n<16;n++)
  114. {
  115. for(nn=mm; nn<ii; nn++)
  116. {
  117. if((timestample[n]<=a[nn]) && (a[nn-1]<=timestample[n]))
  118. {
  119. cc[n] = a[nn-1];
  120. System.out.println(cc[n]+" "+n+" "+timestample[n]);
  121. mm = nn+1;
  122. break;
  123. }
  124. }
  125. }
  126. long xy[][][]= new long[16][10000][2];
  127. IplImage src = cvLoadImage("C:/Users/chens_000/Desktop/MM/new9.jpg",0);
  128. // IplImage gray = cvCreateImage(cvGetSize(src), IPL_DEPTH_32F, 1);
  129. int radius = 1;
  130. l=0;
  131. int lo=0;
  132. for(int n=7;n<8;n++)
  133. {
  134. for(m=l;m<jj;m+=4)
  135. {
  136. if((b[m+3]<=timestample[n])&&(cc[n]<=b[m+3])&&(n!=2))
  137. {
  138. xy[n][lo][0] = b[m];
  139. xy[n][lo][1] = b[m+1];
  140. 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]);
  141. CvPoint center = cvPointFrom32f(new CvPoint2D32f(xy[n][lo][0],xy[n][lo][1]));
  142. cvCircle(src, center, radius, CvScalar.GREEN, 6, CV_AA, 0);
  143. lo++;
  144. }
  145. }
  146. }
  147. cvSaveImage("C:/Users/chens_000/Desktop/MM/89.jpg", src);
  148. cvShowImage("Result",src);
  149. cvWaitKey(0);
  150. /*
  151. int u=4;
  152. int w;
  153. long frame[] = new long[16];
  154. for(int n=0;n<16;n++)
  155. {
  156. for( w=u;w<ii;w++)
  157. {
  158. if( (100000<a[w-3]) & (100000<a[w+1]) & (a[w-3]<=timestample[n]) & (timestample[n]<=a[w+1]))
  159. {
  160. // System.out.println(n+" "+w+" "+a[w-3]+" "+timestample[n]+" "+a[w+1]);
  161. frame[n] = a[w];
  162. System.out.println(frame[n]);
  163. u=w;
  164. break;
  165. }
  166. }
  167. }
  168. /*
  169. long d[] = new long[ii];
  170. for (int j = 0; j < ii; j++)
  171. {
  172. d[j] = Long.parseLong(a[j]);
  173. }
  174. k=0;
  175. for (int j = 1; j <ii; j++)
  176. {
  177. if(d[j]>90000)
  178. k++;
  179. }
  180. long m[]=new long[k];
  181. k=0;
  182. for( int j=1;j<ii;j++)
  183. {
  184. if(d[j]>90000)
  185. {
  186. m[k]=d[j];
  187. k++;
  188. }
  189. }
  190. int count1=0;
  191. int temp=0;
  192. for(int j=1;j<k;j++)
  193. {
  194. for(int ij=2;ij<=jj/4;ij++)
  195. {
  196. if((m[j-1]<=b[ij*4-1])&(b[ij*4-1]<m[j]))
  197. {
  198. 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))
  199. count1++;
  200. }
  201. }
  202. System.out.println(count1);
  203. count1=0;
  204. }
  205. */
  206. }
  207. public static int taskorder(String i){
  208. int j = 0;
  209. if(i.equals("task1.jpg"))
  210. j=0;
  211. if(i.equals("task2.jpg"))
  212. j=1;
  213. if(i.equals("task3.jpg"))
  214. j=2;
  215. if(i.equals("task3a.jpg"))
  216. j=3;
  217. if(i.equals("task3b.jpg"))
  218. j=4;
  219. if(i.equals("task3c.jpg"))
  220. j=5;
  221. if(i.equals("task3d.jpg"))
  222. j=6;
  223. if(i.equals("task4.jpg"))
  224. j=7;
  225. if(i.equals("task5.jpg"))
  226. j=8;
  227. if(i.equals("task6.jpg"))
  228. j=9;
  229. if(i.equals("task7.jpg"))
  230. j=10;
  231. if(i.equals("task8.jpg"))
  232. j=11;
  233. if(i.equals("task9.jpg"))
  234. j=12;
  235. if(i.equals("task10.jpg"))
  236. j=13;
  237. if(i.equals("task11.jpg"))
  238. j=14;
  239. if(i.equals("task12.jpg"))
  240. j=15;
  241. return j;
  242. }
  243. public static boolean isParsableToInt(String i) {
  244. try
  245. {
  246. Long.parseLong(i);
  247. return true;
  248. }
  249. catch (NumberFormatException nfe)
  250. {
  251. return false;
  252. }
  253. }
  254. }