Seeking advice: self-training workflow for small object counting (2K camera, no pretrained models)

I’m new in OpenCV and currently working on an object counting system using a 2K camera, but I’m not using any pretrained models or machine learning yet. My current pipeline is fully classical — it relies on OpenCV filters and contour detection. The object i’m counting is small around 5²mm or even smaller.

Here’s the current processing flow (simplified):

def extra_process(img):
    sm = cv2.bilateralFilter(img, d=9, sigmaColor=75, sigmaSpace=75)
    lab = cv2.cvtColor(sm, cv2.COLOR_BGR2LAB)
    l, a, b = cv2.split(lab)
    clahe = cv2.createCLAHE(clipLimit=2.0, tileGridSize=(8,8))
    l_clahe = clahe.apply(l)
    lab_cl = cv2.merge((l_clahe, a, b))
    return cv2.cvtColor(lab_cl, cv2.COLOR_LAB2BGR)

def process_pipeline(img):    
    enhanced = extra_process(img)
    gray = cv2.cvtColor(enhanced, cv2.COLOR_BGR2GRAY)
    gray = cv2.equalizeHist(gray)
    blur = cv2.GaussianBlur(gray, (5, 5), 0)
    canny = cv2.Canny(blur, 30, 150, 3)
    kernel = np.ones((3,3), np.uint8)
    closed = cv2.morphologyEx(canny, cv2.MORPH_CLOSE, kernel)

    cnt, _ = cv2.findContours(closed.copy(), cv2.RETR_EXTERNAL, cv2.CHAIN_APPROX_TC89_KCOS)
    rgb = cv2.cvtColor(img, cv2.COLOR_BGR2RGB)
    cv2.drawContours(rgb, cnt, -1, (0, 255, 0), 2)

    counted = sum(1 for c in cnt if cv2.contourArea(c) > 100)
    return rgb, counted

It works fine for non-touching objects, but fails when multiple small objects (around 3.5 mm × 1.5 mm each) are touching or overlapping — they end up being counted as one single blob.

My Goals:

I want to build a semi-automatic self-training workflow that helps the computer learn new object types quickly.
The concept:

  1. The system asks the user to place one sample object on the tray.

  2. Then it requests two, three, or more of the same object, possibly overlapping or at different angles.

  3. The system uses these samples to train itself to recognize and separate those objects.

  4. Once confirmed, the user can place hundreds of similar objects on the tray for automatic counting.

This way, the system can adapt to new models quickly without needing a full external training cycle.

I’m avoiding to use YOLO or pretrained models. The main reason is that my production line has very high object variety — sometimes two or more new object models appear daily.
Re-training or fine-tuning YOLO (or any pretrained CNN) for each new model would be too time-consuming and inefficient.
I’m looking for a lightweight local learning or adaptive OpenCV-based recognition approach instead.

My Question:

  1. Is a self-training workflow like this feasible purely using OpenCV (classical methods)?
  2. What would be a good approach to help the system recognize and separate overlapping small objects of the same kind?
  3. Any advice, research references, or similar projects you can point me to would be really appreciated.

see also: