Skip to content

Instantly share code, notes, and snippets.

View jdwang001's full-sized avatar

Alex Wang jdwang001

  • beijing
View GitHub Profile
@smeschke
smeschke / count_gear_teeth.py
Last active June 27, 2024 09:41
Counting gear teeth
import cv2, numpy as np, math
raw_image = cv2.imread('/home/stephen/Desktop/gear6.jpg')
bilateral_filtered_image = cv2.bilateralFilter(raw_image, 5, 175, 175)
# Added median blurring to improve edge detection
median_blurred_images = cv2.medianBlur(bilateral_filtered_image, 5)
edge_detected_image = cv2.Canny(median_blurred_images, 75, 200)
# Switched from RETR_TREE to RETR_EXTERNAL to only extract most outer contours
_, contours, _ = cv2.findContours(edge_detected_image, cv2.RETR_EXTERNAL, cv2.CHAIN_APPROX_SIMPLE)
contour_list = []
for contour in contours: