Color Tracking with Webcam, how do I speed it up??

This is my code:
clear all
vid=videoinput('winvideo',1);
set(vid,'ReturnedColorSpace','RGB');
for x = 1:10
img = getsnapshot(vid);
R = img(:,:,1);
G = img(:,:,2);
B = img(:,:,3);
a = find(R>90 & R<157 & G>0 & G<100 & B>0 & B<81);
BW=zeros(480,640);
BW(a)=1;
imshow(BW)
end

Answers (1)

Change your two lines
BW=zeros(480,640);
BW(a)=1;
to
BW = double(a);
This would produce exactly the same matrix as you are now producing.
You might possibly get slightly better graphics performance with uint8 instead of double, but you'd want to time carefully to be sure. For that,
BW = uint8(255) .* uint8(a);
or maybe
BW = uint8( 255 .* a );
or perhaps even
T = uint8([0 255]);
BW = T(1 + a);

Categories

Find more on Convert Image Type in Help Center and File Exchange

Asked:

on 11 Jul 2012

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!