How To: Measure Part Area from a Camera Image

Start to finish: get a real area measurement out of a live camera, and make it survive a restart.

Before you start

  • LumiScan Cam Driver is installed and publishing an image, for example at hdvisionsystems/lumiscan-cam-driver/camera1/output/image.

  • LumiScan Area Detector is installed and licensed, and system/modules lists module-1.

  • The parts are in front of the camera, in the lighting the installation will actually use.

Step 1: see what is found with the defaults

module-1/detect-area/input/input-image-address = hdvisionsystems/lumiscan-cam-driver/camera1/output/image
write module-1/detect-area/execute

Check output/status-code is 1, then read output/result. Look at blob_count: too many means noise is being counted, zero means nothing matched.

The areas are already real pixel counts. What the next step changes is how the regions are found.

Step 2: commission the level

The one setting that decides whether this works is the brightness a pixel must exceed. Do not guess it - measure the picture:

system/analyse-scene/input/input-image-address = "hdvisionsystems/lumiscan-cam-driver/camera1/output/image"
write system/analyse-scene/execute
read  system/analyse-scene/output/recommended-settings
read  system/analyse-scene/output/histogram

recommended-settings gives you a level, which end is the part, and whether to fill holes. histogram is how you check it: the level wants to sit in the valley between the part’s hump and the background’s. Two humps with a gap means the picture separates cleanly; one hump means no level will save it and the lighting needs fixing instead.

Then set it on the module:

module-1/detect-area/input/method-specific/fixed/level = 128
write module-1/detect-area/execute

If the parts are darker than the background, add:

module-1/detect-area/input/detect-dark = true

Step 3: stop counting noise

Look at the smallest entries in blobs. The app reports every region it separated - there is no area window to raise - so noise and dust are dealt with in one of two places:

  • At the level. Raising method-specific/fixed/level until noise stops crossing the threshold is the better fix, because those regions then cost nothing to find.

  • In your control program. Ignore any blobs[] entry whose area is below what a part can be. A quarter of the area of the smallest part you care about is a good starting point. That decision belongs to you: only you know what a part is.

Step 4: check the number against something you know

Measure a part whose real area you know - or count its pixels once in an image viewer - and compare it against blobs[0].area. They should agree closely. If the measurement is consistently low, the threshold is cutting into the part: lower method-specific/fixed/level, and try detect-dark if the part is the darker of the two.

Step 5: make it permanent

system/save-module-inputs/input/module-id = module-1
write system/save-module-inputs/execute
write system/save-current-modules/execute

Both should report 1. The module and its settings now survive a restart.

Step 6: run it from a control program

Per cycle:

  1. Write to module-1/detect-area/execute.

  2. Read module-1/detect-area/output/status-code.

  3. If negative, the run failed - read output/status-text and do not use the result.

  4. If 1, read output/result and act on total_area, or on blob_count for a presence check.

Read the outputs before triggering the next execute: a run empties them as it starts.

If the numbers look wrong

Symptom What to do

Area is much larger than the part

The level is letting background in. Lower it, or check detect-dark.

Area is consistently short

The level is trimming the part’s edge - lower it. If the part has a hole you meant to include, turn on fill-holes.

Many tiny regions reported

Raise the level so the noise stops crossing it, and ignore the entries below a plausible part area when you read output/result.

One part reported as several

Parts are being split by a shadow or highlight; try preprocessing, or detect-dark.

Nothing found at all

Check status-code, then whether detect-dark matches which end the parts are; then whether the level is above every pixel in the part.

The reading drifts with the lighting

Read system/analyse-scene/output/area-sensitivity. Above about 0.05 the picture will not hold still, and the fix is the lamp, not the level.