|
import cv2
|
|
import numpy as np
|
|
from matplotlib import pyplot as plt
|
|
|
|
"""
|
|
Premiere methode, detection avec Hough
|
|
"""
|
|
|
|
print("Entrez le nom de l'image")
|
|
img = input("exemple : img4.jpg \n")
|
|
fin = input("Entrez le nom de l'image résultat, exemple : img4.jpg \n")
|
|
|
|
img1 = cv2.imread(img)
|
|
mask =cv2.cvtColor(img1, cv2.COLOR_BGR2GRAY)
|
|
img =cv2.cvtColor(img1, cv2.COLOR_BGR2HSV)
|
|
|
|
|
|
for a in range(np.shape(img)[0]):
|
|
for b in range(np.shape(img)[1]):
|
|
if (img[a,b,0] > 38 and img[a,b,0] < 75):
|
|
mask[a,b] = 250
|
|
else:
|
|
mask[a,b]= 0
|
|
|
|
|
|
circle = cv2.HoughCircles(mask, cv2.HOUGH_GRADIENT,2, np.shape(img)[0], 200, 100 )
|
|
cv2.circle( img1,(circle[0,0,0],circle[0,0,1]), circle[0,0,2], (250,0,255),10,8,0 )
|
|
|
|
cv2.imwrite(fin,img1)
|
|
|
|
"""
|
|
deuxieme methode, avec une image cible
|
|
import cv2
|
|
import numpy as np
|
|
from matplotlib import pyplot as plt
|
|
|
|
img_rgb = cv2.imread('img.jpg')
|
|
img_gray = cv2.cvtColor(img_rgb, cv2.COLOR_BGR2GRAY)
|
|
template = cv2.imread('templ.jpg',0)
|
|
w, h = template.shape[::-1]
|
|
|
|
res = cv2.matchTemplate(img_gray,template,cv2.TM_CCOEFF_NORMED)
|
|
threshold = 0.8
|
|
loc = np.where( res >= threshold)
|
|
for pt in zip(*loc[::-1]):
|
|
cv2.rectangle(img_rgb, pt, (pt[0] + w, pt[1] + h), (0,0,255), 2)
|
|
|
|
|
|
plt.subplot(221),plt.imshow(img_rgb,vmin=0, vmax=255),plt.title('ORIGINAL')
|
|
plt.show()
|
|
|
|
"""
|