William Zhang2026-09-20

Egg Counting and Crack Detection Based on reComputer RK3576

The egg counting and crack detection system based on reComputer RK3576 simultaneously performs egg counting and crack/dirt detection on a conveyor belt line. Through Conveyor orchestration and IoU association, it outputs the position, count, and damage condition of each egg.

YOLODamage DetectionEgg CountingGitHub

An Egg Counting and Crack Detection System Based on RK3576 / RKNN / YOLO

Source code: https://github.com/doublelf/Egg_Counting_and_Damage_Detection


Egg counting and crack detection based on reComputer RK3576 are integrated by the Conveyor/ orchestrator into a unified conveyor-belt quality inspection pipeline: each frame runs the counting model and the crack model simultaneously, and an IoU associator pairs “line-crossing events” with “crack detections,” ultimately assigning each egg a cracked / dirty / intact verdict.

Counting: from Automated-Egg-Counting-System/, using single-class object detection + centroid tracking + line-crossing counting.

Crack detection: from crack_inspect/; by default it uses a classical CV pipeline (CLAHE → black-hat → adaptive thresholding → connected components) and does not rely on additional weights; it can also switch to a YOLOv8-seg model via --inspector-mode yolo.

Orchestration: Conveyor/src/egg_pipeline/ links the two together and writes CSV / JSON / optional annotated video.

Quick Start

1. Clone the repository

bash
git clone https://github.com/doublelf/Egg_Counting_and_Damage_Detection
cd Egg_Counting_and_Damage_Detection

2. Create a virtual environment and install dependencies

bash
python3 -m venv .venv
source .venv/bin/activate
pip install --upgrade pip
pip install -r requirements.txt

3. Run inference

The counting threshold is set very high (--conf-counter 0.99) to keep line-crossing counts stable; the crack threshold stays at its default (--conf-inspector 0.25); the cross-model association threshold is loosened to --associate-iou 0.1 to tolerate slight box-position differences between the two models.

bash
cd Conveyor
python run.py --video ./video2.mp4 --conf-counter 0.99 --conf-inspector 0.25 --associate-iou 0.1

You must cd Conveyor first: run.py reads models from config.yaml by default, and the relative paths are resolved against Conveyor/.


Parameter Reference

ParameterDefaultDescription
--video PATH—Path to a local video file (mutually exclusive with --webcam)
--webcam [INDEX]—Use a webcam; with no value this resolves to 0; specify --webcam 1 explicitly to use index 1
--source STR—Directly overrides video.source (a digit string is treated as a webcam index; any other string is treated as a file path)
--counter-weights PATH—Path to the counting-model weights (YOLOv5)
--inspector-weights PATHsame as counterPath to the crack-model weights; ignored when mode=classical
--inspector-modeclassicalauto / yolo / classical; defaults to the classical CV pipeline, no extra weights required
--conf-counter FLOAT0.35Confidence threshold for the counting model
--conf-inspector FLOAT0.25Confidence threshold for the crack model
--associate-iou FLOAT0.3Minimum IoU required to associate a counting box with a crack box; below this value the egg is recorded as unknown
--line-start X Y[100, 240]Line-crossing start point (pixel coordinates)
--line-end X Y[540, 240]Line-crossing end point (pixel coordinates)
--line-directiondowndown / up / any; direction considered when judging a crossing
--no-displayoffDisable the live preview window, suitable for headless servers
--save-video PATH—Write the annotated frames to an mp4 file
--frames-csv PATHlogs/frames.csvPer-frame statistics output
--crossings-csv PATHlogs/crossings.csvPer-egg verdict for every line crossing
--summary PATHlogs/summary.jsonJob-level summary
--loopoffAfter a video finishes playing, loop back from the beginning
--config PATHconfig.yamlCustom YAML configuration file

For the complete list, see python run.py --help.


Output Artifacts

After execution, the following files are produced under Conveyor/logs/ (paths can be redirected via the CLI):

  • logs/frames.csv: per-frame statistics (frame index, timestamp, current frame egg count, cumulative crossing count, etc.).

  • logs/crossings.csv: per-egg line-crossing verdicts. Column meanings:

    ColumnMeaning
    frame_idx, timestamp, directionCrossing moment and direction
    track_idStable ID assigned by the counting model
    colorwhite / brown / unknown (classified by the Lab a* channel)
    clsClass name returned by the crack model, e.g. brown-egg-crack
    cracked, dirty, intactDerived boolean fields
    is_defectivecracked or dirty
    mask_area_ratioFraction of the egg box covered by the crack mask
    iouIoU between the counting box and the crack box
    sourceinspector (successful match) or unknown (no overlap)
  • logs/summary.json: total count + counts per color + defect rate.

  • --save-video output/annotated.mp4 (optional): annotated video with the crossing line, detection boxes, crack masks, and HUD.

Sample terminal output:

Code
[conveyor] Done. crossings=42 defective=3 frames=1280
[conveyor] Artifacts: frames=logs/frames.csv crossings=logs/crossings.csv summary=logs/summary.json

Configuration File

All defaults are centralized in Conveyor/config.yaml; CLI flags override the corresponding keys:

yaml
counter:
  model:
    weights: ../Automated-Egg-Counting-System/best.pt
    device: auto
    img_size: 640
    conf_threshold: 0.35   # corresponds to --conf-counter
    iou_threshold: 0.45
  line:
    start: [100, 240]     # corresponds to --line-start
    end:   [540, 240]     # corresponds to --line-end
    direction: down       # corresponds to --line-direction
    min_track_length: 3
  tracker:
    max_lost_frames: 30
    iou_match_threshold: 0.2

inspector:
  model:
    weights: ../Automated-Egg-Counting-System/best.pt
    mode: classical       # corresponds to --inspector-mode
    conf_threshold: 0.25  # corresponds to --conf-inspector
  filter:
    crack_only: false
    min_mask_pixels: 0
    min_bbox_area: 16

association:
  min_iou: 0.3            # corresponds to --associate-iou

video:
  source: "0"             # corresponds to --source / --video / --webcam
  loop: false

If the two models' boxes are systematically offset (so the counting box and the crack box barely overlap), you can lower cfg.association.min_iou; raise it instead when you see clear mismatches.