-
Notifications
You must be signed in to change notification settings - Fork 6
/
slagalica-z-threshold-finder.py
59 lines (40 loc) · 2.07 KB
/
slagalica-z-threshold-finder.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
import cv2
import numpy
import sys
def nothing(x):
# dummy
pass
def preprocessBeforeOCR(imageToProcess, lower_bound, upper_bound, type, useBlurBefore, useBlurAfter):
hsv = cv2.cvtColor(imageToProcess, cv2.COLOR_RGB2HSV)
h, s, v1 = cv2.split(hsv)
result = v1
if useBlurBefore:
result = cv2.GaussianBlur(v1,(5,5),0)
# Can be played with...
result = cv2.threshold(v1, lower_bound, upper_bound, type)[1]
if useBlurAfter:
result = cv2.medianBlur(result, 3)
return result
fileName1 = 'examples/2018.05.04 Slagalica.mp4-q3-22782-2.1-question.jpg'
#fileName1 = 'examples/Slagalica 01.01.2020. (1080p_25fps_H264-128kbit_AAC).mp4-21685-2.1-question.jpg'
image = cv2.imread(fileName1)
#image2 = preprocessBeforeOCR(image, 147, 255, cv2.THRESH_BINARY)
#cv2.imshow('Image1', image2)
#cv2.waitKey()
cv2.namedWindow("tresholdTrackbars")
cv2.createTrackbar("lower_global_treshold", "tresholdTrackbars", 241, 255, nothing)
cv2.createTrackbar("upper_global_treshold", "tresholdTrackbars", 255, 255, nothing)
cv2.createTrackbar("gaussan_before_blur_on", "tresholdTrackbars", 0, 1, nothing)
cv2.createTrackbar("median_after_blur_on", "tresholdTrackbars", 0, 1, nothing)
while True:
global_treshold_lower = cv2.getTrackbarPos("lower_global_treshold", "tresholdTrackbars")
global_treshold_upper = cv2.getTrackbarPos("upper_global_treshold", "tresholdTrackbars")
gaussan_blur_on = (cv2.getTrackbarPos("gaussan_before_blur_on", "tresholdTrackbars") == 1)
median_blur_on = (cv2.getTrackbarPos("median_after_blur_on", "tresholdTrackbars") == 1)
image1Processed = preprocessBeforeOCR(image.copy(), global_treshold_lower, global_treshold_upper, cv2.THRESH_BINARY, gaussan_blur_on, median_blur_on)
cv2.imshow('Image1 global threshold', image1Processed)
image1Processed2 = preprocessBeforeOCR(image.copy(), global_treshold_lower, global_treshold_upper, cv2.THRESH_BINARY + cv2.THRESH_OTSU, gaussan_blur_on, median_blur_on)
cv2.imshow('Image1 global + otsu', image1Processed2)
key = cv2.waitKey(1)
if key == 27: # ESC
break