Course materials · Robot Basic Lab

Object Detection and False Detection Evaluation

English translation

Learning objectives

More detections do not necessarily mean a better setting. Compare with known circle positions and sizes to identify false detections.

Execution conditions

Use opencv-python-headless, NumPy, and Matplotlib.

Create an image with ground truth

Starting conditions

Draw circles in a 160×200 grayscale image with centers (50,50), (140,70), (90,120) and radii 15,20,12.

Procedure

  1. Apply HoughCircles to the provided circle image.
  2. Overlay detection results on the original image and match them to actual circles.

Results to retain

import numpy as np
import matplotlib.pyplot as plt
import cv2 as cv
truth=[(50,50,15),(140,70,20),(90,120,12)]
image=np.full((160,200),230,dtype=np.uint8)
for x,y,r in truth:cv.circle(image,(x,y),r,30,-1)
blur=cv.GaussianBlur(image,(5,5),1)
def detect(frame,threshold=20):
    return cv.HoughCircles(frame,cv.HOUGH_GRADIENT,dp=1,minDist=25,param1=100,param2=threshold,minRadius=8,maxRadius=25)
found=detect(blur);print(found)
plt.imshow(image,cmap='gray')
if found is not None:
    for x,y,r in found[0]:plt.gca().add_patch(plt.Circle((x,y),r,fill=False,color='tab:red'))

Record results and self-check

Circle:

True center/radius:

Detected center/radius:

Error [pixel]:

Points to check

Change one detection criterion

Starting conditions

Compare param2=15 and 25. Keep the same image and radius range.

Procedure

  1. Count detections, missed circles, duplicates, and false detections separately.
  2. Define a match as a detection with center error within 5 pixels and radius error within 4 pixels.
  3. Judge which criterion is better by the types of errors, rather than the detection count.

Results to retain

for threshold in [15,25]:print(threshold,detect(blur,threshold))
# TODO: Match detections to ground truth one-to-one and count errors.

Record results and self-check

param2:

Matched circle:

Missed circles:

False detections:

Center error:

Points to check

Find failures under blur and noise

Starting conditions

Add image noise with seed=7 and standard deviation 15, and apply the same settings.

Procedure

  1. Choose either a median or Gaussian filter before detection.
  2. Compare detections and computation time before and after filtering.
  3. Define one condition in which detection cannot be trusted for image-based control.

Results to retain

rng=np.random.default_rng(7)
noisy=np.clip(image.astype(float)+rng.normal(0,15,image.shape),0,255).astype(np.uint8)
filtered=cv.medianBlur(noisy,5);print(detect(filtered))
# TODO: Compare matching results and processing times before and after filtering.

Record results and self-check

Preprocessing:

Detection count:

Successful match:

Processing time [ms]:

Points to check

Official examples and data