Download Print this page

Parallax TSL1401-DB Instructions Manual page 8

Linescan camera module

Advertisement

found = 0
RETURN
found is a bit variable that should be initialized to 1 for the search to commence and indicates when the
subroutine returns whether the desired pixel has been found (0 = no; 1 = yes). lptr and rptr have the
same meaning as in the counting routine, except that one or the other can get moved to the location of
the found pixel. Combined with the cumulative effect that found has, this make it easier to perform a
whole string of searches. dir is a bit variable that indicates which end of the (lptr, rptr) range to start
the search from. You can predefine the constants FWD (= 0, "left_to_right") and BKWD (= 1, "right-to-
left") to assign to dir to make your programs more readable. which, as with the counting routine,
indicates what kind of pixel to look for. You can predefine constants for which as well (DRK = 0; BRT =
1) for readability.
When FindPix returns, found will indicate whether the desired pixel was located, and either lptr (if dir
= FWD) or rptr (if dir = BKWD) will point to the found pixel location.
Sometimes, it's necessary to locate an edge instead of just a pixel. A
begins with a dark pixel, then transisitions to a light one. The FindPix routine can be used to find edges,
too, by looking for the first pixel
matches the edge value. The routine to do it is:
FindEdge:
which = 1 - which
GOSUB FindPix
which = 1 - which
GOSUB FindPix
RETURN
Locating pixels and edges is handy for finding objects in a field of view and measuring their "extents". An
object's
extent
includes its outside boundaries and everything in between, regardless of pixel intensity.
For example, in the bagel illustration, the bagel's extent would include the hole, while its
by counting bright pixels) would not.
Here is a complete program which incorporates all the routines described above (and then some). It
acquires images and locates bright objects, computing both their extents and areas. You can also use it
as a template for your own programs.
' =========================================================================
'
'
File...... TSL1401_scan.bs2
'
Purpose... Image capture and processing demo using the TSL1401-DB
'
Author.... Phil Pilgrim, Bueno Systems, Inc.
'
E-mail....
'
Started... 11 July 2007
'
Updated...
'
'
{$STAMP BS2}
'
{$PBASIC 2.5}
'
' =========================================================================
' -----[ Program Description ]---------------------------------------------
' This program demonstrates image capture and processing using the
' TSL1401-DB (Parallax p/n 28317). It continuously acquires and displays
' images from the TSL1401R sensor chip. It then locates both left and right
© Bueno Systems, Inc. • TSL1401-DB (2009.10.01)
opposite
of the edge you're seeking, then the next pixel after that that
'Look for opposite kind of pixel first.
'THEN look for desired pixel.
'Didn't look or nothing found.
'Return.
light edge
, for example is one that
area
(obtained
Page 8 of 52

Advertisement

loading