OpenCV Countersink Inspection Tool


As part of my independent study in computer vision and machine learning, I developed a vision-based countersink inspection tool using the OpenCV library and Python 3. To capture the images, a 5 MP digital microscope was connected to a Raspberry Pi 3 and a 7″ touch screen display. I proposed this project to my supervisor to help minimize the wasted motion of technicians who needed to verify setup parts in the quality department prior to running the batch. The total cost of the hardware was just over $200 and my time was considered free since this project was, after all, homework. I installed the inspection tool at the countersink station, and it has successfully reduced wasted motion by approximately 300%.

Countersink Inspection Tool reading an out of tolerance value


This inspection tool is fairly simple in that it doesn’t require any user operations besides placing the part within the view area of the microscope. The measurements are then displayed in real-time along with a message indicating whether or not the value conforms to acceptable ranges. One of the primary objectives of this project was to make it as user-friendly as possible, so slight adjustments to the information displayed have been made based on feedback from our technicians.


Having gained some familiarity with both Python 3 and OpenCV from my Aerial Lift Bridge project, I was able to incorporate the more technical knowledge gained from my course to provide an adaptable imaging and measurement solution for our company. The basic algorithm followed to achieve this is as follows:

  1. Read microscope stream
  2. Parse stream into individual frames
  3. Perform image operations to enhance desired features
  4. Detect edges
  5. Identify strongest contour
  6. Locate centroid and radius
  7. Draw a circle with those values
  8. Apply a pixel-to-inch conversion factor
  9. Determine status of conformity
  10. Display original images with relevant data overlaid

Some of the code that performs this algorithm can be seen below.

Read and parse stream
Image operations
Edge detection
Find and define strongest contours
Pixel-to-inch conversion factor
Annotation and conformance check
Consolidated output


An example of what is displayed for the technician. The fourth decimal place may be optimistic, though it has been reliable to within ±.001″.


The sample used for development purposes. Additional samples were used to account for the variable surface finish between materials and processes.


The inspection tool successfully measures countersink features with acceptable reliability. The Raspberry Pi proved to be an intuitive and appropriate platform for a project of this scale and the CPU provided adequate processing power for both video and image processing applications.

A duplicate image of the MicroSD card that holds the operating system has been provided to Hydrosolutions of Duluth should there be a data failure along with the full bill of materials shown above.

Some potential issues that may restrict the applications of this tool are:

  • The ranges of values entered in the database account only for the most common types of fasteners used in this environment.
  • The image processing techniques, though designed to be adaptable, may not accommodate for certain surface finishes and lighting conditions.