Sunday 14 December 2014

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

MICROCONTROLLER :: Belajar Microcontroller 8051 dengan Simulator



Buat para pemula alangkah lebih baik selain mempelajari teori juga mempraktekan teori  dengan modul/rangkaian yang sebenarnya. Tapi jika anda belum memiliki modul ,  anda  bisa latihan dengan simulator . Pada kesempatan ini saya akan memperkenalkan simulator yang cocok untuk pemula yaitu UVI51 , simulator untuk micon jenis MCS-51 (8051, At89s51,At89c4051). software ini bisa di download di : ftp://ftp.dte.uvigo.es/uvi51/
simulator microcontroller
Tampilan Simulator microcontroller untuk 8051, 89s51 , 89c4051 dan sejenisnya
Simulator  ini   sangat membatu saya dalam memahami microcontroller untuk pertama kalinya , kususnya MCS-51 ( 8051 ,89s51 , 89c4051 dst) karena simulator ini selain mudah digunakan juga sangat jelas menggambarkan cara kerja sebuah microcontroller.  Sekarang saya sudah tidak lagi menggunakan MCS-51 , saya lebih suka  AVR  :-).  Simulator ini berjalan di windows XP, windows versi  yang lain saya belum pernah coba. Fungsi Microcontroller yang disimulasikan:
  • Input : switch
  • output : LED, seven sement, LCD 2×16
  • Timer
  • Serial komunikasi (Uvi51 bisa mensimulasikan 2 micon sekaligus)
  •  Interupsi
  • Bisa melihat isi Ram dan register
Langkah langkah  menggunakan Simulator Uvi51:
  1. Download  simulator dan contoh file di: ftp://ftp.dte.uvigo.es/uvi51/
  2. extract file hasil download
  3. klik file uvi51.exe.
    uvi51_exe
    uvi51_exe
  4. klik Open
    uvi51_1
    uvi51_1
  5. klik salah satu contoh  misal EX1A.CNX
    uvi51_2
    uvi51_2
  6. klik   menu “A”
    klik_A
    klik_A
  7. klik enter.
    klik enter
    setelah muncul tulisan "Assembly complete no error" lalu tekan enter
  8. klik Simulate.
    klik simulate2
    klik simulate judul
  9. klik run atau step
Membuat  simulasi  baru
Untuk  mejalankan simulator UVI51 kita membutuhkan 2 file :
  1.  file ber extension *.cnx ,   file ini berisi konfigurasi hardware misal switch ,LCD 2×6, PushButton , Led , rs232  dll.
  2. file berextension *.src  source code
Contoh :
buka notepad buat 2 buah file berikut.
file test1.src ber isi:
; Data transfers using MOV
;
org 0
; Port 0 contents are copied into several targets
mov a,p0
mov b,p0
mov 20h,p0
; P0 contents are copied into RAM address pointed by P1
mov r0,p1
mov @r0,p0
jmp 0
end
file test1.cnx berisi:
* clock 12 mega , ram 256 byte memory program 1024 byte
Utest1.src 12 256 1024

P00=2 ; PORT0.0 diberi beri tanda sebagai node 2
P01=3 ; PORT0.1 diberi beri tanda sebagai node 3

* Switches dgn nama B0 di hubungkan ke node 2 (PORT0.0) ,lokasi switch dikotak no 4
SB0 2 0 1 4

* Pushbutton dgn nama P0 dihubungkan ke node 3 (PORT0.1) , lokasi pushbuton di kotak no 9
KP0 3 0 9
Beberapa ilustrasi penjelasan  isi file cnx ,(  konfigurasi hardware)  : 

lebih detainya bisa baca manualnya: ftp://ftp.dte.uvigo.es/uvi51/UVI51_50_MANUAL.ZI
P

MICROCONTROLLER :: Komunikasi serial menggunakan uC AT89


Kita tahu port serial masih digunakan hingga saat ini, walaupun beberapa peralatan komputer sudah menghilangkan port ini, namun kita masih bisa membeli (atau pinjem juga boleh, he he he) alat dan/atau perangkat lunak usb2serial, sehingga komunikasi via port serial masih tetap bisa kita lakukan.
Selain untuk kebutuhan komunikasi, port serial atau port RS232 bisa digunakan untuk kebutuhan pengontrolan, nah artikel kali ini saya akan membahas tentang rangkaian dan contoh program dalam BASIC (BASCOM51) port serial untuk kontrol lampu LED, dan tentunya bisa Anda kembangkan untuk aplikasi-aplikasi lainnya, seperti komunikasi dengan HP, sehingga bisa digunakan untuk kontrol jarak jauh dan lain sebagainya…
Baiklah, berikut ini adalah gambar rangkaian minimal yang akan kita gunakan untuk eksperimen, cukup sederhana, tapi khasiatnya… he he he…
Okey, ceritanya begini… Port serial akan kita gunakan untuk mengontrol pola hidup 8 LED yang kita hubungkan ke PORT1 dan pemantauan tombol-tekan di PORT3, perintah-perintah yang digunakan sebagai berikut:
  • 01 : menghidupkan LED di Port1.0
  • 11 : menghidupkan LED di Port1.1
  • 21 : menghidupkan LED di Port1.2
  • 31 : menghidupkan LED di Port1.3
  • 41 : menghidupkan LED di Port1.4
  • 51 : menghidupkan LED di Port1.5
  • 61 : menghidupkan LED di Port1.6
  • 71 : menghidupkan LED di Port1.7
  • 00 : mematikan LED di Port1.0
  • 10 : mematikan LED di Port1.1
  • 20 : mematikan LED di Port1.2
  • 30 : mematikan LED di Port1.3
  • 40 : mematikan LED di Port1.4
  • 50 : mematikan LED di Port1.5
  • 60 : mematikan LED di Port1.6
  • 70 : mematikan LED di Port1.7
  • id : menampilkan kalimat “Made by A.E.P 2008″
  • ba : baca status semua tombol pushbutton di P3
  • b2 : baca status tombol pushbutton di P3.2
  • b2 : baca status tombol pushbutton di P3.3
  • b2 : baca status tombol pushbutton di P3.4
  • b2 : baca status tombol pushbutton di P3.5
  • b2 : baca status tombol pushbutton di P3.6
  • b2 : baca status tombol pushbutton di P3.7
Catatan:
  • Tombol di P3.0 dan P3.1 tidak digunakan karena sebagai jalur komunikasi serial, jika tetap dibaca akan menimbulkan kesalahan atau error…
Kemudian listing program menggunakan BASIC-nya BASCOM51 sebagai berikut…
$regfile = "89c55wd.dat"     ' pustaka untuk AT89c55
$crystal = 11059200 ' gunakan kristal 12 MHz
$baud = 9600

Dim S As String * 2
Do
Input S
Select Case S
Case "01" : P1.0 = 0
Case "11" : P1.1 = 0
Case "21" : P1.2 = 0
Case "31" : P1.3 = 0
Case "41" : P1.4 = 0
Case "51" : P1.5 = 0
Case "61" : P1.6 = 0
Case "71" : P1.7 = 0
Case "00" : P1.0 = 1
Case "10" : P1.1 = 1
Case "20" : P1.2 = 1
Case "30" : P1.3 = 1
Case "40" : P1.4 = 1
Case "50" : P1.5 = 1
Case "60" : P1.6 = 1
Case "70" : P1.7 = 1
Case "b2" : Print P3.2
Case "b3" : Print P3.3
Case "b4" : Print P3.4
Case "b5" : Print P3.5
Case "b6" : Print P3.6
Case "b7" : Print P3.7
Case "ba" : Print P3
Case "id" : Print "Made by A.E.P 2008"
Case Else
Print "er"
End Select
Loop
Keterangan:
  • Program diawali dengan pernyataan “$regfile” yang digunakan untuk mendefinisikan uC yang digunakan, dilanjutkan dengan “$crystal” yang menyatakan frekuensi kristal yang digunakan, $baud untuk menentukan kecepatan komunikasi serial dalam bit per second atau bps;
  • inti dari program ini ada dua, penerimaan data dan pemrosesan data yang diterima. Yang pertama dilakukan melalui pernyataan “Input s” (kondisi menunggu masukan dari terminal komputer - komunikasi serial) dan yang Kedua melalui pernyataan “Select Case S” hingga “End Select“;
  • Penerjemahan protokol atau aturan komunikasi melalui pernyataan “Select Case S“, misalnya untuk perintah “01” diterjemahkan sebagai “Case “01″ : P1.0=1” dan seterusnya, selain itu (dengan pernyataan “else case” akan dikirimkan pesan “er”, artinya ada error atau perintah tidak dikenal;
  • Percobaan dapat dilakukan dengan menghubungkan board uC ke port serial menggunakan kabel serial bersilang, maksudnya dilakukan pasangan antara uC dan PC sebagai berikut: Gnd - Gnd, Tx(komputer) - Rx(mikrokontroler) dan Tx(komputer) - Rx(mikrokontroler);
  • Keterangan dan penjelasan lengkap mengenai komunikasi serial ini bisa Anda baca di buku saya “Belajar Mikrokontroler AT89C51/52/55: Teori dan Aplikasi“, Edisi 2.
Bagaimana mudah khan? kalo sudah begini, Anda bisa mengembangkan aplikasi ini untuk pembuatan program kontrol atau pemantauan menggunakan Visual Basic atau Delphi - Teknik Antarmuka PC.
Terima kasih, semoga bermanfaat… Komentar/pertanyaan silahkan…