Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- clear all
- close all
- clc
- % baca video
- videos = VideoReader('visiontraffic.avi');
- % terapkan optical flow lucas-kanade
- OFLucasKanade = opticalFlowLK('NoiseThreshold',0.0039);
- % terapkan optical flow horn-schunck
- OFHornSchunck = opticalFlowHS(...
- 'Smoothness',1,...
- 'MaxIteration',10,...
- 'VelocityDifference',0);
- % terapkan optical flow farneback
- OFFarneback = opticalFlowFarneback(...
- 'NumPyramidLevels',3,...
- 'PyramidScale',0.5,...
- 'NumIterations',3,...
- 'NeighborhoodSize',5,...
- 'FilterSize',15);
- figure(1); % buat jendela baru
- suptitle('Hasil Penerapan Optical Flow'); % judul jendela
- % iterasi sampai semua frame pada video diproses
- while hasFrame(videos)
- % baca setiap frame
- frame_rgb = readFrame(videos);
- % ubah ukuran citra
- frame_rgb = imresize(frame_rgb,[180,320]);
- % konversi ruang warna ke grayscale
- frame_gray = rgb2gray(frame_rgb);
- % perkirakan motion dengan metode optical flow yang dipilih
- flowLK = estimateFlow(OFLucasKanade,frame_gray);
- flowHS = estimateFlow(OFHornSchunck,frame_gray);
- flowFB = estimateFlow(OFFarneback,frame_gray);
- % tampilkan hasil Optical Flow Lucas Kanade
- ax1 = subplot(1,3,1);
- imshow(frame_rgb,'InitialMagnification','fit');
- title('Optical Flow Lucas-Kanade');
- hold on;
- % gambar arah aliran pergerakan dengan anak panah
- plot(flowLK,'DecimationFactor',[5 5],'ScaleFactor',10)
- q = findobj(gca,'type','Quiver');
- q.Color = 'r'; hold off;
- % tampilkan hasil Optical Flow Horn Schunck
- ax2 = subplot(1,3,2);
- imshow(frame_rgb,'InitialMagnification','fit');
- title('Optical Flow Horn-Schunck');
- hold on;
- % gambar arah aliran pergerakan dengan anak panah
- plot(flowHS,'DecimationFactor',[5 5],'ScaleFactor',50)
- q = findobj(gca,'type','Quiver');
- q.Color = 'g'; hold off;
- % tampilkan hasil Optical Flow Farneback
- ax3 = subplot(1,3,3);
- imshow(frame_rgb,'InitialMagnification','fit');
- title('Optical Flow Farneback');
- hold on;
- % gambar arah aliran pergerakan dengan anak panah
- plot(flowFB,'DecimationFactor',[5 5],'ScaleFactor',5)
- q = findobj(gca,'type','Quiver');
- q.Color = 'c'; hold off;
- % maksimalkan layar
- set(gcf, 'units','normalized','outerposition',[0 0 1 1]);
- drawnow;
- end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement