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
git clone https://github.com/doublelf/Egg_Counting_and_Damage_Detection
cd Egg_Counting_and_Damage_Detection2. Create a virtual environment and install dependencies
python3 -m venv .venv
source .venv/bin/activate
pip install --upgrade pip
pip install -r requirements.txt3. 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.
cd Conveyor
python run.py --video ./video2.mp4 --conf-counter 0.99 --conf-inspector 0.25 --associate-iou 0.1You must
cd Conveyorfirst:run.pyreads models fromconfig.yamlby default, and the relative paths are resolved againstConveyor/.
Parameter Reference
| Parameter | Default | Description |
|---|---|---|
--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 PATH | same as counter | Path to the crack-model weights; ignored when mode=classical |
--inspector-mode | classical | auto / yolo / classical; defaults to the classical CV pipeline, no extra weights required |
--conf-counter FLOAT | 0.35 | Confidence threshold for the counting model |
--conf-inspector FLOAT | 0.25 | Confidence threshold for the crack model |
--associate-iou FLOAT | 0.3 | Minimum 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-direction | down | down / up / any; direction considered when judging a crossing |
--no-display | off | Disable the live preview window, suitable for headless servers |
--save-video PATH | — | Write the annotated frames to an mp4 file |
--frames-csv PATH | logs/frames.csv | Per-frame statistics output |
--crossings-csv PATH | logs/crossings.csv | Per-egg verdict for every line crossing |
--summary PATH | logs/summary.json | Job-level summary |
--loop | off | After a video finishes playing, loop back from the beginning |
--config PATH | config.yaml | Custom 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:Column Meaning frame_idx,timestamp,directionCrossing moment and direction track_idStable ID assigned by the counting model colorwhite/brown/unknown(classified by the Laba*channel)clsClass name returned by the crack model, e.g. brown-egg-crackcracked,dirty,intactDerived boolean fields is_defectivecracked or dirtymask_area_ratioFraction of the egg box covered by the crack mask iouIoU between the counting box and the crack box sourceinspector(successful match) orunknown(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:
[conveyor] Done. crossings=42 defective=3 frames=1280
[conveyor] Artifacts: frames=logs/frames.csv crossings=logs/crossings.csv summary=logs/summary.jsonConfiguration File
All defaults are centralized in Conveyor/config.yaml; CLI flags override the corresponding keys:
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: falseIf 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.