-
Notifications
You must be signed in to change notification settings - Fork 51
/
flagfinder.beta.py
50 lines (40 loc) · 1.75 KB
/
flagfinder.beta.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
#!/usr/bin/python
###### # ## #### ###### # # # ##### ###### #####
# # # # # # # # ## # # # # # #
##### # # # # ##### # # # # # # ##### # #
# # ###### # ### # # # # # # # # #####
# # # # # # # # # ## # # # # #
# ###### # # #### # # # # ##### ###### # #
#
# quick n dirty based on the idea/program from munona and in code i found on the net, and ported to python by beta
# use the cascade file from flagfinder2.
# If someone interested in work on another cascade sheet and train it, contact me. Im beta
#
# The program accepts jpg input files list and display if has isis flags or not
# feel free to incorporate and modify it on your scripts #opparis
#
import cv2, sys
from cv2 import cv
def detect(img, cascade):
for scale in [float(i)/10 for i in range(11, 15)]:
for neighbors in range(2,5):
rects = cascade.detectMultiScale(img, scaleFactor=scale, minNeighbors=neighbors,
minSize=(20, 20), flags=cv2.cv.CV_HAAR_SCALE_IMAGE)
if len(rects)>0:
return True
return False
def find_flag(img):
gray = cv2.cvtColor(img, cv2.COLOR_BGR2GRAY)
gray = cv2.equalizeHist(gray)
detected = detect(gray, cascade)
return detected
if __name__ == '__main__':
cascade_fn = "cascade.xml"
cascade = cv2.CascadeClassifier(cascade_fn)
for fname in sys.argv[1:]:
try:
img = cv2.imread(fname)
except:
pass
else:
print " %s %s " % (fname, "isis" if find_flag(img) else "?")