-
Notifications
You must be signed in to change notification settings - Fork 0
/
flare_detect.py
executable file
·71 lines (61 loc) · 2.3 KB
/
flare_detect.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
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
import pandas as pd
import numpy as np
import cv2
import matplotlib.pyplot as plt
import math
from skimage import data, feature
import os
def is_flare(pixel):
if pixel[0]>= 80 and pixel[0]<= 190 and pixel[1] >= 0.1 and pixel[2] >= 150:
return True
else:
return False
def flare_list(img1):
img1_gray = cv2.cvtColor(img1, cv2.COLOR_BGR2GRAY)
blobs_dog = feature.blob_dog(img1_gray, threshold=0.1, max_sigma=20)
blobs_dog[:, 2] = blobs_dog[:, 2] * math.sqrt(2)
a = []
img1_hsv = cv2.cvtColor(img1.astype('float32'), cv2.COLOR_BGR2HSV)
for i in blobs_dog:
max_pixel = []
max_value = -1
clip = img1[int(i[0]-i[2]):int(i[0]+i[2]), int(i[1]-i[2]):int(i[1]+i[2])]
clip_hsv = img1_hsv[int(i[0]-i[2]):int(i[0]+i[2]), int(i[1]-i[2]):int(i[1]+i[2])]
for x in range(clip.shape[0]):
for y in range(clip.shape[1]):
if clip[x][y].sum() >= max_value:
max_value = clip[x][y].sum()
max_pixel = clip_hsv[x][y]
if max_value != -1:
if is_flare(max_pixel):
a.append(i)
a=np.array(a)
return a
'''
data = os.listdir('./dataset')
for d in data:
img1 = cv2.imread('./dataset/'+d)
#img1_gray = cv2.imread('./dataset/'+d, cv2.IMREAD_GRAYSCALE)
blobs_dog = feature.blob_dog(img1_gray, threshold=0.1, max_sigma=20)
blobs_dog[:, 2] = blobs_dog[:, 2] * math.sqrt(2)
a = []
img1_hsv = cv2.cvtColor(img1.astype('float32'), cv2.COLOR_BGR2HSV)
for i in blobs_dog:
max_pixel = []
max_value = -1
clip = img1[int(i[0]-i[2]):int(i[0]+i[2]), int(i[1]-i[2]):int(i[1]+i[2])]
clip_hsv = img1_hsv[int(i[0]-i[2]):int(i[0]+i[2]), int(i[1]-i[2]):int(i[1]+i[2])]
for x in range(clip.shape[0]):
for y in range(clip.shape[1]):
if clip[x][y].sum() >= max_value:
max_value = clip[x][y].sum()
max_pixel = clip_hsv[x][y]
if max_value != -1:
if is_flare(max_pixel):
a.append(i)
a=np.array(a)
output_img = img1.copy()
for i in a:
output_img = cv2.circle(output_img, (int(i[1]),int(i[0])), round(i[2]), color=(255, 255, 0), thickness = 1)
cv2.imwrite('./result/flare_'+d,output_img)
'''