Download Print this page

Image Analysis - Parallax TSL1401-DB Instructions Manual

Linescan camera module

Advertisement

You can use DEBUG to display the acquired pixels, as in the following program fragment. (A somewhat
fancier version is given in the complete program later in this section.)
FOR i = 0 TO 7
DEBUG BIN16 pdata(i) REV 16
NEXT
The variable i can be declared as a NIBble. The reason for the REV is because the data were read in
LSB first, but DEBUG's BIN formatter displays data MSB-first. So we need to reverse the order of the
bits to get an accurate picture of the pixel order. One might well ask why we didn't just read the data in
MSB first to begin with. After all, SHIFTIN, can do that just as easily. The answer lies in the image
analysis routines to follow.

Image Analysis

Analyzing a linescan image to extract useful information from it involves two major operations: pixel
counting, and pixel and edge location. The PBASIC subroutines that perform these operations treat the
original array of eight words as an array of 128 bits, each bit corresponding to a single pixel. Bit 0 is the
first pixel read; bit 127, the last. (This mapping is why the pixels needed to be read in LSB first.) Here's
how the word and bit arrays are declared:
pdata
VAR Word(8)
pixels
VAR pdata.BIT0
Counting light or dark pixels within a given range is simple. Here's the code that does it:
CountPix:
cnt = 0
IF (lptr <= rptr AND rptr <= 127) THEN
FOR i = lptr TO rptr
IF (pixels(i) = which) THEN cnt = cnt + 1 '
NEXT
ENDIF
RETURN
cnt can be declared as a byte, since it will never exceed 128. lptr and rptr are also bytes that can range
from 0 to 127, inclusive. They indicate the range over which the counting occurs. which is a bit variable
that indicates whether to count dark pixels (0) or light pixels (1). Counting pixels is handy for computing
an object's area – either in one scan, or cumulatively over multiple scans for two-dimensional objects
passing under the camera on a conveyor.
Locating the first occurrence of a dark or light pixel within a given range isn't much harder:
FindPix:
IF (found = 1 AND lptr <= rptr AND rptr <= 127) THEN
IF (dir = FWD) THEN
FOR lptr = lptr TO rptr
IF (pixels(lptr) = which) THEN RETURN '
NEXT
ELSE
FOR rptr = rptr TO lptr
IF (pixels(rptr) = which) THEN RETURN '
NEXT
ENDIF
ENDIF
© Bueno Systems, Inc. • TSL1401-DB (2009.10.01)
'Initialize count.
'Valid range?
'
Yes: Loop over desired range.
Add to count when pixel matches.
'Still looking & within bounds?
'
Yes: Search left-to-right?
'
Yes: Loop forward.
Return on match.
'
No:
Loop backward.
Return on match.
Page 7 of 52

Advertisement

loading