0% found this document useful (0 votes)
61 views

Sheet Computer Vision

The document describes methods for real-time face detection, color detection, and motion detection using computer vision and a webcam. It includes code to: 1) Detect faces in real-time video by thresholding color channels and finding the largest skin-colored region with an aspect ratio between 1-1.8. 2) Detect colored objects in video by subtracting one color channel from the grayscale image, filtering noise, and finding bounding boxes. 3) Estimate optical flow between frames using a Horn-Schunck method to detect motion regions and plot flow vectors.

Uploaded by

dalvinda100501
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
61 views

Sheet Computer Vision

The document describes methods for real-time face detection, color detection, and motion detection using computer vision and a webcam. It includes code to: 1) Detect faces in real-time video by thresholding color channels and finding the largest skin-colored region with an aspect ratio between 1-1.8. 2) Detect colored objects in video by subtracting one color channel from the grayscale image, filtering noise, and finding bounding boxes. 3) Estimate optical flow between frames using a Horn-Schunck method to detect motion regions and plot flow vectors.

Uploaded by

dalvinda100501
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 2

SHEET COMPUTER VISION SK2

>> imaqhwinfo : %untuk mengetahui cameranya sudah terinstall atau belum

>>dev_info = imaqhwinfo('winvideo',1) : % untuk mengetahui informasi camera.

DETEKSI WAJAH SECARA REAL TIME


close all;
clear all;
clc;
vid=videoinput('winvideo',1,'YUY2_320x240');
set(vid,'TriggerRepeat',Inf);
vid.returnedcolorspace='rgb';
vid.FrameGrabInterval=2;
start(vid)
while(vid.FramesAcquired<=200)
I = getsnapshot(vid);cform = makecform('srgb2lab');
J = applycform(I,cform);
K=J(:,:,2);
L=graythresh(J(:,:,2));
BW1=im2bw(J(:,:,2),L);
M=graythresh(J(:,:,3));
BW2=im2bw(J(:,:,3),M);
O=BW1.*BW2;
% Bounding box untuk mendeteksi ukuran wajah
P=bwlabel(O,8);BB=regionprops(P,'Boundingbox');
BB1=struct2cell(BB);BB2=cell2mat(BB1);
[s1 s2]=size(BB2);mx=0;
imshow(I)
for k=3:4:s2-1
p=BB2(1,k)*BB2(1,k+1);
if p>mx && (BB2(1,k)/BB2(1,k+1))<1.8
mx=p;
j=k;
end
end
BB2(1,j+1)
hold on
rectangle('Position',[BB2(1,j-2),BB2(1,j-1),BB2(1,j),BB2(1,j+1)],'EdgeColor','y' )
hold off
end
%menghentikan video
stop(vid)
delete(vid);
imaqreset;

DETEKSI WARNA
close all;
clear all;
clc;

vid=videoinput('winvideo',1, 'YUY2_160x120');
set(vid,'TriggerRepeat',Inf);
vid.returnedcolorspace='rgb';
vid.FrameGrabInterval=2;
start(vid)
SHEET COMPUTER VISION SK2

while(vid.FramesAcquired<=200)

data = getsnapshot(vid);
diff_im = imsubtract(data(:,:,3), rgb2gray(data));
diff_im = medfilt2(diff_im, [3 3]);
diff_im = im2bw(diff_im,0.16);
diff_im = bwareaopen(diff_im,100);
bw = bwlabel(diff_im, 8);
stats = regionprops(bw, 'BoundingBox', 'Centroid');
imshow(data)

hold on
for object = 1:length(stats)
bb = stats(object).BoundingBox;
bc = stats(object).Centroid;
rectangle('Position',bb,'EdgeColor','r','LineWidth',1)
plot(bc(1),bc(2), '-m+')

a=text(bc(1)+15,bc(2),strcat('X:',num2str(round(bc(1))),'Y:',num2str(round(bc(2)))));
set(a,'FontName','Arial','FontWeight','bold','FontSize',12,'Color','Blue');
end
hold off
end
stop(vid)

DETEKSI GERAK

vidDevice = imaq.VideoDevice('winvideo', 1, 'RGB24_640x480','ReturnedColorSpace','rgb');

opticFlow = opticalFlowHS;

% Mulai mendeteksi per frame


nFrames = 0;
while (nFrames<500) % Proses pendeteksian 100 buah frame
% Acquire single frame from imaging device.
% ambil satu frame saja untuk diproses
frameRGB = vidDevice();

% Hitung optical flow untuk frame tertentu.


flow = estimateFlow(opticFlow,rgb2gray(frameRGB));

imshow(frameRGB)
hold on
plot(flow,'DecimationFactor',[5 5],'ScaleFactor',25)
hold off

% Tambahkan nilai frame (untuk pengecekan frame berikutnya)


nFrames = nFrames + 1;
end

You might also like