Advertisement
Guest User

Untitled

a guest
Nov 22nd, 2019
98
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.16 KB | None | 0 0
  1. clear all
  2. close all
  3. clc
  4.  
  5. % baca video
  6. videos = VideoReader('visiontraffic.avi');
  7.  
  8. % terapkan optical flow lucas-kanade
  9. OFLucasKanade = opticalFlowLK('NoiseThreshold',0.0039);
  10.  
  11. % terapkan optical flow horn-schunck
  12. OFHornSchunck = opticalFlowHS(...
  13. 'Smoothness',1,...
  14. 'MaxIteration',10,...
  15. 'VelocityDifference',0);
  16.  
  17. % terapkan optical flow farneback
  18. OFFarneback = opticalFlowFarneback(...
  19. 'NumPyramidLevels',3,...
  20. 'PyramidScale',0.5,...
  21. 'NumIterations',3,...
  22. 'NeighborhoodSize',5,...
  23. 'FilterSize',15);
  24.  
  25. figure(1); % buat jendela baru
  26. suptitle('Hasil Penerapan Optical Flow'); % judul jendela
  27.  
  28. % iterasi sampai semua frame pada video diproses
  29. while hasFrame(videos)
  30. % baca setiap frame
  31. frame_rgb = readFrame(videos);
  32. % ubah ukuran citra
  33. frame_rgb = imresize(frame_rgb,[180,320]);
  34. % konversi ruang warna ke grayscale
  35. frame_gray = rgb2gray(frame_rgb);
  36.  
  37. % perkirakan motion dengan metode optical flow yang dipilih
  38. flowLK = estimateFlow(OFLucasKanade,frame_gray);
  39. flowHS = estimateFlow(OFHornSchunck,frame_gray);
  40. flowFB = estimateFlow(OFFarneback,frame_gray);
  41.  
  42. % tampilkan hasil Optical Flow Lucas Kanade
  43. ax1 = subplot(1,3,1);
  44. imshow(frame_rgb,'InitialMagnification','fit');
  45. title('Optical Flow Lucas-Kanade');
  46. hold on;
  47.  
  48. % gambar arah aliran pergerakan dengan anak panah
  49. plot(flowLK,'DecimationFactor',[5 5],'ScaleFactor',10)
  50. q = findobj(gca,'type','Quiver');
  51. q.Color = 'r'; hold off;
  52. % tampilkan hasil Optical Flow Horn Schunck
  53. ax2 = subplot(1,3,2);
  54. imshow(frame_rgb,'InitialMagnification','fit');
  55. title('Optical Flow Horn-Schunck');
  56. hold on;
  57. % gambar arah aliran pergerakan dengan anak panah
  58. plot(flowHS,'DecimationFactor',[5 5],'ScaleFactor',50)
  59. q = findobj(gca,'type','Quiver');
  60. q.Color = 'g'; hold off;
  61. % tampilkan hasil Optical Flow Farneback
  62. ax3 = subplot(1,3,3);
  63. imshow(frame_rgb,'InitialMagnification','fit');
  64. title('Optical Flow Farneback');
  65. hold on;
  66. % gambar arah aliran pergerakan dengan anak panah
  67. plot(flowFB,'DecimationFactor',[5 5],'ScaleFactor',5)
  68. q = findobj(gca,'type','Quiver');
  69. q.Color = 'c'; hold off;
  70.  
  71. % maksimalkan layar
  72. set(gcf, 'units','normalized','outerposition',[0 0 1 1]);
  73. drawnow;
  74. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement