-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.py
30 lines (21 loc) · 790 Bytes
/
main.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
import cv2 as cv2
import numpy as np
import matplotlib.pyplot as plt
# https://docs.opencv.org/4.x/d4/d73/tutorial_py_contours_begin.html
# On charge l'image.
img = cv2.imread("img/screen.png")
img2 = cv2.imread("img/screen.png",cv2.IMREAD_GRAYSCALE)
# On grise l'image
imgray = cv2.cvtColor(img, cv2.COLOR_BGR2GRAY)
# on fait un threshold,
# gris, adaptatif https://kongakura.fr/article/opencv-threshold
th = cv2.adaptiveThreshold(
imgray, 255, cv2.ADAPTIVE_THRESH_GAUSSIAN_C, cv2.THRESH_BINARY, 71, 17)
cv2.imwrite('output/th.png', th)
# On recherche les contours.
contours, hierarchy = cv2.findContours(
th, cv2.RETR_EXTERNAL, cv2.CHAIN_APPROX_SIMPLE)
# # Draw contour
etst = cv2.drawContours(th, contours, -1, (0, 255, 0), 3)
# cv2.imshow("img",etst)
# cv2.waitKey(0)