Akuisisi citra digital menggunakan webcam


Matlab (Matrix Laboratory) merupakan salah satu perangkat lunak yang mendukung bidang pengolahan citra digital. Dalam bidang tersebut pada umumnya diawali dengan proses akuisisi citra digital.

Proses akuisisi citra digital dilakukan dengan cara menangkap (capture) atau memindai (scan) citra analog kemudian mengkonversinya menjadi citra digital agar dapat disimpan dan juga diolah melalui komputer.

Salah satu alat akuisisi citra digital yang sering digunakan adalah webcam.

Dalam software Matlab, proses akuisisi citra digital menggunakan webcam dapat dilakukan dengan terlebih dahulu menginstal driver Image Acquisition Support Packages for Hardware Adaptors.

Ada cukup banyak driver yang perlu diinstal yaitu sebagai berikut:

Adaptor Name Support package name in list Contents
Windows Video (winvideo) OS Generic Video Interface MATLAB files to use Windows Video, Macintosh Video, or Linux Video cameras with the toolbox. The correct OS files will be installed, depending on your system.
Kinect for Windows (kinect) Kinect for Windows Sensor MATLAB files to use Kinect for Windows cameras with the toolbox

Third party files – Kinect for Windows Runtime

QImaging (qimaging) QImaging Hardware MATLAB files to use QImaging cameras with the toolbox

Third party files – QImaging QCam

DALSA IFC (dalsaifc) Teledyne DALSA IFC Hardware MATLAB files to use DALSA IFC cameras with the toolbox
DALSA Sapera (dalsasapera) Teledyne DALSA Sapera Hardware MATLAB files to use DALSA Sapera cameras with the toolbox
GigE Vision (gige) GigE Vision Hardware MATLAB files to use GigE Vision cameras with the toolbox
Matrox (matrox) Matrox Hardware MATLAB files to use Matrox cameras with the toolbox
DCAM (dcam) DCAM Hardware MATLAB files to use DCAM cameras with the toolbox

Third party files – CMU DCAM on Windows driver file

GenICam GenTL (gentl) GenICam Interface MATLAB files to use GenTL cameras with the toolbox
Point Grey (pointgrey) Point Grey Hardware MATLAB files to use Point Grey cameras with the toolbox

Third party files – Point Grey FlyCapture

Linux Video (linuxvideo) OS Generic Video Interface MATLAB files to use Windows Video, Macintosh Video, or Linux Video cameras with the toolbox. The correct OS files will be installed, depending on your system.
Macintosh Video (macvideo) OS Generic Video Interface MATLAB files to use Windows Video, Macintosh Video, or Linux Video cameras with the toolbox. The correct OS files will be installed, depending on your system.
Data Translation (dt) Data Translation Frame Grabbers MATLAB files to use Data Translation hardware with the toolbox
Hamamatsu (hamamatsu) Hamamatsu Hardware MATLAB files to use Hamamatsu cameras with the toolbox
National Instruments (ni) NI Frame Grabbers MATLAB files to use NI hardware with the toolbox

Third party files – NI-IMAQ files

Langkah-langkah untuk menginstal driver-driver tersebut adalah:
1. Klik tool ‘Add-Ons’ pada home tool, kemudian pilih ‘Get Hardware Support Packages’

Untitled-1

2. Pilih install from internet, lalu pilih next

Untitled-2

3. Pilih support packages yang ingin diinstal sesuai dengan tabel tersebut di atas, misalnya ‘DCAM Hardware’, kemudian pilih next

Untitled-3

4. Log in dengan akun mathworks (bagi yang sudah punya akun). Jika belum mempunyai akun, sign up lah terlebih dahulu pada laman berikut https://www.mathworks.com/mwaccount/register?uri=/accesslogin/myAccount.do

Untitled-4

Untitled-5

5. Setelah log in, beri centang pada  ‘I accept’, kemudian pilih next

Untitled-6

6. Pilih next

Untitled-7

7. Lalu pilih install

Untitled-8

8. Install juga driver Image Acquisition Support Packages for Hardware Adaptors yang lain sesuai dengan tabel di atas.

9. Setelah semua driver-driver tersebut berhasil diinstal, maka Software Matlab telah support untuk melakukan akuisisi citra. Persiapkanlah webcam yang akan digunakan, bisa menggunakan usb webcam atau bisa juga menggunakan webcam laptop.

10. Berikut ini merupakan contoh pemrograman GUI Matlab untuk mengakuisisi citra digital menggunakan webcam:
a. Tampilan GUI awal

1

b. Konfigurasi kamera, untuk webcam pilih winvideo

2

c.Pilih device id 1 untuk webcam laptop, pilih device id 2 untuk usb webcam

3

d. Pilih resolusi kamera yang diinginkan

4

e. Klik capture untuk menangkap sekaligus menyimpan citra hasil akuisisi

6
5

f. Citra hasil akuisisi secara otomatis akan tersimpan dalam komputer

7

File GUIDE Matlab untuk akuisisi citra digital dapat diunduh melalui laman berikut ini: Source Code

Sedangkan tampilan source codenya adalah:

function varargout = Camera(varargin)
% CAMERA MATLAB code for Camera.fig
% CAMERA, by itself, creates a new CAMERA or raises the existing
% singleton*.
%
% H = CAMERA returns the handle to a new CAMERA or the handle to
% the existing singleton*.
%
% CAMERA('CALLBACK',hObject,eventData,handles,...) calls the local
% function named CALLBACK in CAMERA.M with the given input arguments.
%
% CAMERA('Property','Value',...) creates a new CAMERA or raises the
% existing singleton*. Starting from the left, property value pairs are
% applied to the GUI before Camera_OpeningFcn gets called. An
% unrecognized property name or invalid value makes property application
% stop. All inputs are passed to Camera_OpeningFcn via varargin.
%
% *See GUI Options on GUIDE's Tools menu. Choose "GUI allows only one
% instance to run (singleton)".
%
% See also: GUIDE, GUIDATA, GUIHANDLES

% Edit the above text to modify the response to help Camera

% Last Modified by GUIDE v2.5 04-Apr-2016 13:44:04

% Begin initialization code - DO NOT EDIT
gui_Singleton = 1;
gui_State = struct('gui_Name', mfilename, ...
    'gui_Singleton', gui_Singleton, ...
    'gui_OpeningFcn', @Camera_OpeningFcn, ...
    'gui_OutputFcn', @Camera_OutputFcn, ...
    'gui_LayoutFcn', [] , ...
    'gui_Callback', []);
if nargin && ischar(varargin{1})
    gui_State.gui_Callback = str2func(varargin{1});
end

if nargout
    [varargout{1:nargout}] = gui_mainfcn(gui_State, varargin{:});
else
    gui_mainfcn(gui_State, varargin{:});
end
% End initialization code - DO NOT EDIT


% --- Executes just before Camera is made visible.
function Camera_OpeningFcn(hObject, eventdata, handles, varargin)
% This function has no output args, see OutputFcn.
% hObject handle to figure
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
% varargin command line arguments to Camera (see VARARGIN)

% Choose default command line output for Camera
handles.output = hObject;

% Update handles structure
guidata(hObject, handles);
movegui(hObject,'center');

% UIWAIT makes Camera wait for user response (see UIRESUME)
% uiwait(handles.figure1);


% --- Outputs from this function are returned to the command line.
function varargout = Camera_OutputFcn(hObject, eventdata, handles)
% varargout cell array for returning output args (see VARARGOUT);
% hObject handle to figure
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)

% Get default command line output from handles structure
varargout{1} = handles.output;


% --- Executes on button press in pushbutton1.
function pushbutton1_Callback(hObject, eventdata, handles)
% hObject handle to pushbutton1 (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
IAHI = imaqhwinfo;
IA = (IAHI.InstalledAdaptors);
D = menu('Select Video Input Device:',IA);

if isempty(IA)||D==0
    msgbox({'You don''t have any VideoInput Installed Adaptors!',...
        'Please! try again and select Adaptor properly.'})
    return
end

IA = char(IA);
IA = IA(D,:);
IA(IA==' ')=[];
x = imaqhwinfo(IA);

try
    DeviceID = menu('Select Device ID',x.DeviceIDs);
    F = x.DeviceInfo(DeviceID).SupportedFormats;
    nF = menu('Select FORMAT',F);
    Format = F{nF};
catch
    warndlg({'Try Another Device or ID ';...
        'You Don''t Have Installed This Device (VideoInputDevice)'})
    return
end

VidObj = videoinput(IA, DeviceID, Format);
handles.VidObj = VidObj;
vidRes = get(handles.VidObj, 'VideoResolution');
nBands = get(handles.VidObj, 'NumberOfBands');
axes(handles.axes1)
hImage = image( zeros(vidRes(2), vidRes(1), nBands) );
preview(handles.VidObj, hImage)
set(VidObj,'returnedcolorspace','rgb');
guidata(hObject, handles);

% --- Executes on button press in pushbutton2.
function pushbutton2_Callback(hObject, eventdata, handles)
% hObject handle to pushbutton2 (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
try
    VidObj = handles.VidObj;
    i = getsnapshot(VidObj);
    
    n = str2double(get(handles.edit1,'String'))+1;
    set(handles.edit1,'String',num2str(n));
    
    axes(handles.axes2)
    imshow(i);
    
    imwrite(i,strcat(['Image ',num2str(n),'.jpg']))
catch
end

% --- Executes on button press in pushbutton3.
function pushbutton3_Callback(hObject, eventdata, handles)
% hObject handle to pushbutton3 (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
try
    delete(handles.VidObj)
catch
end

axes(handles.axes1)
cla reset
set(gca,'XTick',[])
set(gca,'YTick',[])

axes(handles.axes2)
cla reset
set(gca,'XTick',[])
set(gca,'YTick',[])

set(handles.edit1,'String',0)

% --- Executes on button press in pushbutton4.
function pushbutton4_Callback(hObject, eventdata, handles)
% hObject handle to pushbutton4 (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
close;


function edit1_Callback(hObject, eventdata, handles)
% hObject handle to edit1 (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)

% Hints: get(hObject,'String') returns contents of edit1 as text
% str2double(get(hObject,'String')) returns contents of edit1 as a double


% --- Executes during object creation, after setting all properties.
function edit1_CreateFcn(hObject, eventdata, handles)
% hObject handle to edit1 (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles empty - handles not created until after all CreateFcns called

% Hint: edit controls usually have a white background on Windows.
% See ISPC and COMPUTER.
if ispc && isequal(get(hObject,'BackgroundColor'), get(0,'defaultUicontrolBackgroundColor'))
    set(hObject,'BackgroundColor','white');
end

Save

Save

Save

Posted on April 4, 2016, in Pengenalan Matlab, Pengolahan Citra and tagged , , , , , , , , , , , , , , , , , , , . Bookmark the permalink. 3 Comments.

  1. Cara menentukan lokasi direktori untuk penyimpanan fotonya bagaimana ya ? Soalnya saya ga menemukan foto yg telah dicapture. Thx

  2. matlab yang digunakan crack atau asli ?, semisal crack, apakah bisa ?

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

%d bloggers like this: