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
- Apply HoughCircles to the provided circle image.
- Overlay detection results on the original image and match them to actual circles.
Results to retain
- Ground truth/detection comparison image and an error table for each circle.
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
- Have you avoided recording a missed detection as error 0?
- Have you avoided duplicate matching of nearby circles?
Change one detection criterion
Starting conditions
Compare param2=15 and 25. Keep the same image and radius range.
Procedure
- Count detections, missed circles, duplicates, and false detections separately.
- Define a match as a detection with center error within 5 pixels and radius error within 4 pixels.
- Judge which criterion is better by the types of errors, rather than the detection count.
Results to retain
- Detection images and a matching table for the two settings.
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
- Did you use the same matching criteria for different thresholds?
- Have you avoided counting multiple detections of one circle as separate correct detections?
Find failures under blur and noise
Starting conditions
Add image noise with seed=7 and standard deviation 15, and apply the same settings.
Procedure
- Choose either a median or Gaussian filter before detection.
- Compare detections and computation time before and after filtering.
- Define one condition in which detection cannot be trusted for image-based control.
Results to retain
- A preprocessing comparison on noisy images and validity criteria.
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
- Did you limit values to 0…255 before converting to uint8?
- Have you avoided treating a single timing measurement as the algorithm's general speed?