Sie sind auf Seite 1von 9

El procesamiento digital requiere transformar las seales de entrada a un formato

digital, es decir, a funciones f(n)

Esto ocurre en una etapa llamada conversin analgica-digital (A/D).


La seal digitalizada es tratada luego en el procesador digital de seales, que
puede ser desde un computador de propsito general, pasando por sistemas
empotrados basados en microcontroladores, hasta circuitos digitales
especialmente diseados para realizar las tareas de procesamiento deseadas; sin
embargo, las conjuraciones programables tanto en software como en hardware
reconfigurable son las que han brindado al procesamiento digital una flexibilidad
inalcanzable con sistemas analgicos equivalentes

El ltimo paso del procesamiento digital consiste en convertir la salida del bloque
procesador a una seal analgica, lo que ocurre en el llamado convertidor digitalanalgico (D/A). En aplicaciones de anlisis de seal, la ltima etapa puede no ser
necesaria, cuando la informacin a extraer se obtiene directamente de las
representaciones digitales.

Matlab Arduino Y Procesamiento De


Imgenes (Posicin de un servomotor)
El siguiente proyecto de procesamiento digital tiene como objetivo mover un
servomotor (controlar la posicin de un servomotor) mediante el movimiento de un
objeto, haciendo uso de procesamiento de imgenes.
Esta aplicacin la considero como principios bsicos de robtica (un pequeo
sistema de visin artificial). Nace con la necesidad de entender el procesamiento
digital de seales, la idea bsica a qui aunque nos apoyamos de la tarjeta de
arduino, no es programar directamente arduino, si no programar en Matlab y
enviar desde Matlab los datos a arduino

Materiales
-

Arduino
Matlab
Servomotor
Algn objeto de color
Cmara
Cables

La dinmica es que mediante la segmentacin de un color, podamos darle giro al


servomotor a medida que vayamos moviendo el color en la pantalla
Usaremos segmentacin basada en distancia euclidiana.
En matemticas, la distancia euclidiana es la distancia "ordinaria" entre dos
puntos de un espacio eucldeo, la cual se deduce a partir del teorema de
Pitgoras.
Por ejemplo, en un espacio bidimensional, la distancia euclidiana entre dos
puntos P1 y P2, de coordenadas cartesianas (x1, y1) y (x2, y2) respectivamente, es:

En general, la distancia euclidiana entre los puntos


Y

, del espacio eucldeo n-dimensional, se define como:

El cdigo generado para el anlisis de informacin de la cmara sobre el color a


analizar:
function out = MyVid
%MYVID Code for creating a video input object.
%
%
This is the machine generated representation of a video input object.
%
This MATLAB code file, MYVID.M, was generated from the OBJ2MFILE
function.
%
A MAT-file is created if the object's UserData property is not
%
empty or if any of the callback properties are set to a cell array
%
or to a function handle. The MAT-file will have the same name as the
%
code file but with a .MAT extension. To recreate this video input
object,
%
type the name of the code file, MyVid, at the MATLAB command prompt.
%
%
The code file, MYVID.M and its associated MAT-file, MYVID.MAT (if
%
it exists) must be on your MATLAB path.
%
%
Example:
%
vidobj = MyVid;
%
%
See also VIDEOINPUT, IMAQDEVICE/PROPINFO, IMAQHELP, PATH.
%
% Check if we can check out a license for the Image Acquisition Toolbox.
canCheckoutLicense = license('checkout', 'Image_Acquisition_Toolbox');
% Check if the Image Acquisition Toolbox is installed.
isToolboxInstalled = exist('videoinput', 'file');
if ~(canCheckoutLicense && isToolboxInstalled)
% Toolbox could not be checked out or toolbox is not installed.
error(message('imaq:obj2mfile:invalidToolbox'));
end
% Load the MAT-file containing UserData and CallBack property values.
try
MATvar = load('C:\Users\Jhonalexander\Desktop\Demos Proy\MyVid');
MATLoaded = true;
catch
warning(message('imaq:obj2mfile:MATload'));
MATLoaded = false;
end
% Device Properties.
adaptorName = 'winvideo';
deviceID = 1;
vidFormat = 'YUY2_352x288';
tag = '';
% Search for existing video input objects.
existingObjs1 = imaqfind('DeviceID', deviceID, 'VideoFormat', vidFormat,
'Tag', tag);
if isempty(existingObjs1)
% If there are no existing video input objects, construct the object.
vidObj1 = videoinput(adaptorName, deviceID, vidFormat);
else
% There are existing video input objects in memory that have the same
% DeviceID, VideoFormat, and Tag property values as the object we are
% recreating. If any of those objects contains the same AdaptorName

%
%
%
%
%

value as the object being recreated, then we will reuse the object.
If more than one existing video input object contains that
AdaptorName value, then the first object found will be reused. If
there are no existing objects with the AdaptorName value, then the
video input object will be created.

% Query through each existing object and check that their adaptor
name
% matches the adaptor name of the object being recreated.
for i = 1:length(existingObjs1)
% Get the object's device information.
objhwinfo = imaqhwinfo(existingObjs1{i});
% Compare the object's AdaptorName value with the AdaptorName
value
% being recreated.
if strcmp(objhwinfo.AdaptorName, adaptorName)
% The existing object has the same AdaptorName value as the
% object being recreated. So reuse the object.
vidObj1 = existingObjs1{i};
% There is no need to check the rest of existing objects.
% Break out of FOR loop.
break;
elseif(i == length(existingObjs1))
% We have queried through all existing objects and no
% AdaptorName values matches the AdaptorName value of the
% object being recreated. So the object must be created.
vidObj1 = videoinput(adaptorName, deviceID, vidFormat);
end %if
end %for
end %if
% Configure properties whose values are saved in
C:\Users\Jhonalexander\Desktop\Demos Proy\MyVid.mat.
if (MATLoaded)
% MAT-file loaded successfully. Configure the properties whose values
% are saved in the MAT-file.
set(vidObj1, 'ErrorFcn', MATvar.errorfcn1);
else
% MAT-file could not be loaded. Configure properties whose values were
% saved in the MAT-file to their default value.
set(vidObj1, 'ErrorFcn', @imaqcallback);
end
% Configure vidObj1 properties.
set(vidObj1, 'FramesPerTrigger', 1);
set(vidObj1, 'ReturnedColorSpace', 'rgb');
% Configure vidObj1's video source properties.
srcObj1 = get(vidObj1, 'Source');
set(srcObj1(1), 'Brightness', 64);
set(srcObj1(1), 'Saturation', 84);
out = vidObj1 ;

Este cdigo bsicamente lo que har ser analizar la ubicacin o coordenadas del
color que estemos analizando y cuando este color se mueva de lugar nos
calculara las nuevas coordenadas o nueva ubicacin y de esa manera podremos
enviarle la seal al arduino para que mueva al servomotor en la direccin correcta.

Una vez seleccionado el color que deseamos analizar en este caso el color rojo,
ya el servomotor se movera desde 0 - 180 . La idea es que el servomotor gire
cada ves que movamos el color que elejimos.
Una aplicacin que podriamos dar a este ejemplo es mover un brazo robotico o un
humanoide.

El cdigo para conectar el servomotor con el arduino en el pin 9, es el siguiente:


vid = MyVid;
vid.FrameGrabInterval = 2.7;
set(vid,'TriggerRepeat',Inf);
a = getsnapshot(vid);
figure('Name','Select Mask','NumberTitle',...
'off')
mask=roipoly(a);
red=immultiply(mask, a(:,:,1));% identificar la region roja
green=immultiply(mask, a(:,:,2));% identificar la region verde
blue=immultiply(mask, a(:,:,3));%identificar la region azul
g=cat(3,red,green,blue);
[M,N,K]=size(g);
I=reshape(g,M*N,3);
idx=find(mask);
I=double(I(idx,1:3));
[C, m]=covmatrix(I);
%[x,y,z]=size(a);
figure('Name','Video Segmentation','NumberTitle',...
'off');

a=arduino('COM7');
a.servoAttach(9);
start(vid);
%hold on;
%pause(1);
while(vid.FramesAcquired<=200)% Stop after 1000 frames
data = getdata(vid,1);
b = data(:,:,:,1);
immult=colorseg('euclidean',b,50,m);% segment ime using multiples of
T=25 for threshold
[i,j]=RapidCentroid(immult);
imshow(b);
X=floor(i*0.5114);
a.servoWrite(9,X);
%hold on
text(i-5,j-20,num2str(X),'Color','w','FontSize',12,...
'BackgroundColor',(m()')/255)
end
a.servoWrite(9,0);
stop(vid);

Conclusiones:
o Para lograr una ptima segmentacin en una imagen a color, es
recomendable tomar un nmero considerable de muestras representativas;
entre ms muestras representativas mejores resultados obtendremos.
o En los resultados logramos una mejor segmentacin del objeto con el
mtodo de la Distancia Euclidiana. Debido a que con este mtodo se tiene
una mayor flexibilidad, modificando levemente la distancia umbral para
determinar la pertenencia del pxel al objeto deseado.
o El mtodo de la Distancia permiten llevar a cabo la segmentacin de una
imagen a color, el uso exclusivo depende de la imagen y de las situaciones,

Das könnte Ihnen auch gefallen