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

Asked by Cameron on 11 Jul 2012
Latest activity Commented on by Walter Roberson on 14 Jul 2012

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

Cameron

Products

No products are associated with this question.

1 Answer

Answer by Walter Roberson on 11 Jul 2012

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);

0 Comments

Walter Roberson

Contact us