-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.py
21 lines (15 loc) · 820 Bytes
/
main.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
import cv2
import numpy as np
imgPath = "image.jpg" # Photo by Samuel Richard (@mumbolicious on unsplash.com)
imgInGrayScale = cv2.imread(imgPath, cv2.IMREAD_GRAYSCALE) # Load the image in grayscale
if imgInGrayScale is not None : # Only if we are able to open the image
# Used to distinguish between glued dots
dotPattern = np.ones((2, 2), np.uint8) # Dot pattern definition
dilatedImg = cv2.dilate(imgInGrayScale, dotPattern, iterations=1)
# Used to identify the dots
dots = cv2.Canny(dilatedImg, threshold1=30, threshold2=90) # Dots detection
contours, _ = cv2.findContours(dots, cv2.RETR_EXTERNAL, cv2.CHAIN_APPROX_SIMPLE) # Find external contours
dotsNb = len(contours)
print("Number of celestial bodies (aproximately) : ", dotsNb)
else :
print("Unable to open the file")