© Bueno Systems, Inc. • TSL1401-DB (2009.10.01)
Page 34 of 52
CNTNEW|Modifiers, Begin, End
CNTNXT|Modifiers
CNTNEW
is a constant defined in the template as
$C8.
The
CNTNEW
command counts pixels or edges
between pixels
Begin
and
End
, inclusive.
Begin
and
End
can
range from
1
to
255
, and
Begin
should
be less than or equal to
End
. (Remember that binary pixel locations are one-based, not zero-based. The
first pixel is pixel #1.)
CNTNXT
(
$C0
) counts pixels or edges between the current internal Left and Right limits, whatever they
might be. These limits are set by the following actions, whichever occurred most recently:
•
Any acquire command, which resets Left to
1
and Right to
255
.
•
Any
CNTNEW
command. Left ends up at
Begin
; Right, at
End.
•
A
FNDNEW
command. Left is initialized to
Begin
; Right, to
End
.
•
Any
FNDNEW
or
FNDNXT
command, wherein Left is moved to the found pixel or edge
(searching forward), or Right is moved to the found pixel or edge (searching backward). If the
desired feature is not found, Left will equal Right + 1, causing further counts and finds to return
zero.
The modifiers that can be used with (i.e. ORed to)
CNTNEW
or
CNTNXT
are:
Name
Value
Description
DRKPIX
$00
Count dark pixels.
BRTPIX
$02
Count bright pixels.
DRKEDG
$03
Count dark (high-to-low) edges.
BRTEDG
$01
Count bright (low-to-high) edges.
When
DRKPIX
or
BRTPIX
is selected, the command counts either dark pixels or bright pixels,
depending on which modifier is used. Here’s an example:
OWOUT owio, 0, [CNTNEW|DRKPIX, 32, 64]
GOSUB Ready
This will count all the dark pixels between locations 32 and 64, inclusive. Suppose the binary pixel array
looked like this, where vertical bars represent the location 32 and 64 boundaries:
… 0000111000 11111111000000001111110000111111
1111100000 …
31 32 64 65
In this case, there would be twelve dark pixels counted, and a
12
would be written at the next available
byte location in the results buffer. Assuming that this
CNTNEW
was the first command after an image
acquisition, that would be location
RESULTS + 5
(
$25
), so we could read the result into the Byte
variable
dark_count
with the following code:
OWOUT owio, 0, [DUMPADR, R 5]
OWIN owio, 2, [dark_count]
Once this sequence of code has executed, remember, the results buffer pointer is reset to
RESULTS
(
$20
), and the next result computed will be buffered there. This is due to the reset sent at the end of
the
OWIN
statement.