Sunday 14 December 2014

MATLAB :: Deteksi wajah (face detection) menggunakan algoritma Viola-Jones


945431_692045540806193_773492431_n
1
2
3
4
5
faceDetector = vision.CascadeObjectDetector;
I = imread('visionteam.jpg');
bboxes = step(faceDetector, I);
IFaces = insertObjectAnnotation(I, 'rectangle', bboxes, 'Face');
figure, imshow(IFaces), title('Detected faces');

sumber :
http://pemrogramanmatlab.wordpress.com/2013/11/05/deteksi-wajah-face-detection-menggunakan-algoritma-viola-jones/

MATLAB :: Source code Face detection menggunakan matlab

FACE DETECTION - MATLAB CODE


  
Prerequisite: Computer vision system toolbox

FACE DETECTION:

clear all
clc
%Detect objects using Viola-Jones Algorithm

%To detect Face
FDetect = vision.CascadeObjectDetector;

%Read the input image
I = imread('HarryPotter.jpg');

%Returns Bounding Box values based on number of objects
BB = step(FDetect,I);

figure,
imshow(I); hold on
for i = 1:size(BB,1)
    rectangle('Position',BB(i,:),'LineWidth',5,'LineStyle','-','EdgeColor','r');
end
title('Face Detection');
hold off;



The step(Detector,I) returns Bounding Box value that contains [x,y,Height,Width] of the objects of interest.


BB =

    52    38    73    73
   379    84    71    71
   198    57    72    72

NOSE DETECTION:


%To detect Nose
NoseDetect = vision.CascadeObjectDetector('Nose','MergeThreshold',16);



BB=step(NoseDetect,I);


figure,
imshow(I); hold on
for i = 1:size(BB,1)
    rectangle('Position',BB(i,:),'LineWidth',4,'LineStyle','-','EdgeColor','b');
end
title('Nose Detection');
hold off;





EXPLANATION:


To denote the object of interest as 'nose', the argument  'Nose' is passed.

vision.CascadeObjectDetector('Nose','MergeThreshold',16);

The default syntax for Nose detection :
vision.CascadeObjectDetector('Nose');

Based on the input image, we can modify the default values of the parameters passed tovision.CascaseObjectDetector. Here the default value for 'MergeThreshold' is 4.

When default value for 'MergeThreshold' is used, the result is not correct.
Here there are more than one detection on Hermione.




To avoid multiple detection around an object, the 'MergeThreshold' value can be overridden. 


MOUTH DETECTION:



%To detect Mouth
MouthDetect = vision.CascadeObjectDetector('Mouth','MergeThreshold',16);

BB=step(MouthDetect,I);


figure,
imshow(I); hold on
for i = 1:size(BB,1)
 rectangle('Position',BB(i,:),'LineWidth',4,'LineStyle','-','EdgeColor','r');
end
title('Mouth Detection');
hold off;



EYE DETECTION:


%To detect Eyes
EyeDetect = vision.CascadeObjectDetector('EyePairBig');

%Read the input Image
I = imread('harry_potter.jpg');

BB=step(EyeDetect,I);



figure,imshow(I);
rectangle('Position',BB,'LineWidth',4,'LineStyle','-','EdgeColor','b');
title('Eyes Detection');
Eyes=imcrop(I,BB);
figure,imshow(Eyes);







Cropped Image


I will discuss more about object detection and how to train detectors to identify object of our interest in my upcoming posts. Keep reading for updates.

Sumber : http://angeljohnsy.blogspot.com/2013/07/face-detection-matlab-code.html

Source Code Face Detection and Tracking Using CAMShift


Introduction



Object detection and tracking are important in many computer vision applications including activity recognition, automotive safety, and surveillance. In this example, you will develop a simple face tracking system by dividing the tracking problem into three separate problems:
  1. Detect a face to track
  2. Identify facial features to track
  3. Track the face
Step 1: Detect a Face To Track
Before you begin tracking a face, you need to first detect it. Use the vision.CascadeObjectDetector to detect the location of a face in a video frame. The cascade object detector uses the Viola-Jones detection algorithm and a trained classification model for detection. By default, the detector is configured to detect faces, but it can be configured for other object types.
% Create a cascade detector object.
faceDetector = vision.CascadeObjectDetector();

% Read a video frame and run the detector.
videoFileReader = vision.VideoFileReader('visionface.avi');
videoFrame = step(videoFileReader);
bbox = step(faceDetector, videoFrame);

% Draw the returned bounding box around the detected face.
videoOut = insertObjectAnnotation(videoFrame,'rectangle',bbox,'Face');
figure, imshow(videoOut), title('Detected face');
You can use the cascade object detector to track a face across successive video frames. However, when the face tilts or the person turns their head, you may lose tracking. This limitation is due to the type of trained classification model used for detection. To avoid this issue, and because performing face detection for every video frame is computationally intensive, this example uses a simple facial feature for tracking.
Step 2: Identify Facial Features To Track
Once the face is located in the video, the next step is to identify a feature that will help you track the face. For example, you can use the shape, texture, or color. Choose a feature that is unique to the object and remains invariant even when the object moves.
In this example, you use skin tone as the feature to track. The skin tone provides a good deal of contrast between the face and the background and does not change as the face rotates or moves.
% Get the skin tone information by extracting the Hue from the video frame
% converted to the HSV color space.
[hueChannel,~,~] = rgb2hsv(videoFrame);

% Display the Hue Channel data and draw the bounding box around the face.
figure, imshow(hueChannel), title('Hue channel data');
rectangle('Position',bbox(1,:),'LineWidth',2,'EdgeColor',[1 1 0])
Step 3: Track the Face
With the skin tone selected as the feature to track, you can now use the vision.HistogramBasedTracker for tracking. The histogram based tracker uses the CAMShift algorithm, which provides the capability to track an object using a histogram of pixel values. In this example, the Hue channel pixels are extracted from the nose region of the detected face. These pixels are used to initialize the histogram for the tracker. The example tracks the object over successive video frames using this histogram.
% Detect the nose within the face region. The nose provides a more accurate
% measure of the skin tone because it does not contain any background
% pixels.
noseDetector = vision.CascadeObjectDetector('Nose');
faceImage = imcrop(videoFrame,bbox(1,:));
noseBBox = step(noseDetector,faceImage);

% The nose bounding box is defined relative to the cropped face image.
% Adjust the nose bounding box so that it is relative to the original video
% frame.
noseBBox(1,1:2) = noseBBox(1,1:2) + bbox(1,1:2);

% Create a tracker object.
tracker = vision.HistogramBasedTracker;

% Initialize the tracker histogram using the Hue channel pixels from the
% nose.
initializeObject(tracker, hueChannel, noseBBox(1,:));

% Create a video player object for displaying video frames.
videoInfo = info(videoFileReader);
videoPlayer = vision.VideoPlayer('Position',[300 300 videoInfo.VideoSize+30]);

% Track the face over successive video frames until the video is finished.
while ~isDone(videoFileReader)

% Extract the next video frame
videoFrame = step(videoFileReader);

% RGB -> HSV
[hueChannel,~,~] = rgb2hsv(videoFrame);

% Track using the Hue channel data
bbox = step(tracker, hueChannel);

% Insert a bounding box around the object being tracked
videoOut = insertObjectAnnotation(videoFrame,'rectangle',bbox,'Face');

% Display the annotated video frame using the video player object
step(videoPlayer, videoOut);

end

% Release resources
release(videoFileReader);
release(videoPlayer);
Summary
In this example, you created a simple face tracking system that automatically detects and tracks a single face. Try changing the input video and see if you are able to track a face. If you notice poor tracking results, check the Hue channel data to see if there is enough contrast between the face region and the background.
Reference
[1] G.R. Bradski "Real Time Face and Object Tracking as a Component of a Perceptual User Interface", Proceedings of the 4th IEEE Workshop on Applications of Computer Vision, 1998.
[2] Viola, Paul A. and Jones, Michael J. "Rapid Object Detection using a Boosted Cascade of Simple Features", IEEE CVPR, 2001.

sumber : http://www.mathworks.com/help/vision/examples/face-detection-and-tracking-using-camshift.html

Friday 12 December 2014

MICROCONTROLLER :: BELAJAR INTERFACE MODEM WAVECOM DENGAN AT89S52



Setelah lihat2 tutorial kebanyakan modemnya masih yang serial, kemudian saya membeli konverter usb ke rs232 dengan berharap bisa langsung dikomunikasikan… tetapi apa yang terjadi malah tidak bisaaaaaa…
Proses I.
Kemudian tetap semangat search di google ternyata ada salah satu web yang memperlihatkan cara koneksi modem ini secara langsung (TTL) yaitu tidak melewati konverter/konektor seperti usb dan rs 232 tetapi harus membongkar modem wavecom. kemudian saya bongkar modemnya dan saya contoh tutorialnya dengan cara menjumper titik konektor tx dan rx (TTL) modem. Hasilnya waow hebat saya dapat menjumpernya dengan kabel, saya sangan senang sekali akhirnya dapat dengan mudah mengkoneksikan modem ini dengan mikrokontroler tanpa melalui konektor db9, pakai usbpun bisa. eh malah jumperannya coplok gara2 kesenggol dan pin konektor TTLnya pun rusakkkk…..
contoh koneksi TTL nyontoh di web orang
Koneksi Modem ke komputer
cara setting baudrate:
1. hubungkan usb modem ke cpu
2. cari com yang terdeteksi pada komputer misal com 8
3. setting default wavecom 115200
4. ketik AT kemudian enter jika balasan ok berarti sudah konek
5. untuk bisa komunikasi dengan mikro baudrate harus dirubah ke 19200/ lainnya.
6. ketik at+ipr=19200 kemudian enter
tutup hyperterminal kemudian buka kembali dari awal setting baudrate 19200….
7. balasan ok kemudian menghilangkan echo ketik ATE0 enter
8. Settingan harus disimpan ke eeprom wavecom dengan cara ketik AT&W kemudian enter.
9. Modem siap dikomunikasikan dengan mikro
Untuk rangkaiannya bikin sendiri cm konek ke tx dan rx mikrokontroler
contoh listing program assembly kirim at command ke modem melalui mikro at89s52
;#########################################################################;
; Program SMS controler 2 titik lampu menggunakan 2 buah relai
; Mikrokontroler at89s52
; modem wavecom1206b
;#########################################################################;
LED bit P1.2
Relai_1 bit p2.0
Relai_2 bit p2.1
data_pesan equ 30h
;#########################################################################;
ORG 00H
clr led
call tunda_long
setb led
call tunda_long
clr led
call tunda_long
call initial
;#########################################################################;
; program_utama loop
;#########################################################################;
Program_utama: call kirim_ate0
call tunda_long
call Kirim_at
tunggu_1: jnb ri,$
clr ri
mov A,sbuf
cjne A,#’O’,tunggu_1
jnb ri,$
clr ri
mov A,sbuf
tunggu_2: cjne A,#’K’,tunggu_2
call tunda_long
jmp kirim_pesan
Kirim_pesan: call kirim_sms
tunggu_sms_1: jnb ri,$
clr ri
mov A,sbuf
cjne A,#’>’,tunggu_sms_1
call tunda_long
call Kirim_isi_sms
tunggu_sms_2: jnb ri,$
clr ri
mov A,sbuf
cjne A,#’>’,tunggu_sms_2
call tunda_long
call Kirim_ctrlz
setb led
jmp $
Looping: jnb ri,$
clr ri
mov A,sbuf
mov @R0,a
cjne A,#’K’,tunggu_2
ret
;#########################################################################;
Print_At: db ‘at’,13,10,0
Print_Ate0: db ‘ate0′,13,10,0
Print_sms: db ‘at+cmgs=083840377711′,13,10,0
Print_isi_sms: db ‘Tes sms nganggo modem wavecom’,13,10,0
;#########################################################################;
; INISIALISASI BAUT RATE 19200
;#########################################################################;
INITIAL: MOV SCON,#50H ;INISIALISASI BAUD RATE 19200
MOV TMOD,#20H
Mov 87h,#80h
MOV TH1,#0FdH
SETB TR1
RET
;>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
;>>>>>>>>>>>>>>>>>>>>HAPUS SMS DI LOKASI INBOX INDEX 1>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
;>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
Kirim_at: MOV DPTR,#print_at ;KIRIM PRINTAH ‘AT+CMGD=1′
jmp tunggu_at
Kirim_ate0: MOV DPTR,#print_ate0
jmp tunggu_at
Kirim_sms: MOV DPTR,#Print_sms
jmp tunggu_at
Kirim_isi_sms: MOV DPTR,#Print_isi_sms
jmp tunggu_at
Kirim_ctrlz: mov A,#26
clr ti
mov sbuf,a
ret
Tunggu_at: CLR A ;KOSONGKAN ACC
MOVC A,@A+DPTR ;AMBIL DATA TABEL YANG DITUNJUK DPTR
CLR TI ;AKTIVASI KIRIM SERIAL
MOV SBUF,A ;KIRIMKAN DATA
JNB TI,$ ;TUNGGU SELESAI DIKIRIM
INC DPTR ;NAIKKAN PENUNJUK TABEL
CJNE A,#00,Tunggu_at ;TUNGGU SEMUA KARAKTER DIKIRIM
ret
;#########################################################################;
; TUNDA WAKTU
;#########################################################################;
TUNDA_LONG: MOV R5,#010H
JJz: CALL TUNDA
DJNZ R5,JJz
RET
TUNDA: MOV R7,#100
LD1: DJNZ R6,$
DJNZ R7,LD1
RET
end