-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathfishfilter.py
More file actions
51 lines (35 loc) · 1.48 KB
/
fishfilter.py
File metadata and controls
51 lines (35 loc) · 1.48 KB
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
import pytesseract
import numpy as np
import cv2 as cv
class Filter:
match_words = []
language = "tur"
TEXT_POSITION = (80, 0)
TEXT_SIZE = (20, 300)
def __init__(self):
pytesseract.pytesseract.tesseract_cmd='C:\\Program Files\\Tesseract-OCR\\tesseract.exe'
file = open('fishs.txt', encoding="utf-8")
for fish in file:
self.match_words.append(fish.replace('\n', ''))
print("Fishs: ")
print(self.match_words)
def change_image(self, crop_img):
crop_img = cv.cvtColor(crop_img, cv.COLOR_BGR2GRAY)
sharpen_kernel = np.array([[-1,-1,-1], [-1,9,-1], [-1,-1,-1]])
crop_img = cv.filter2D(crop_img, -1, sharpen_kernel)
crop_img = cv.threshold(crop_img, 0, 255, cv.THRESH_BINARY_INV + cv.THRESH_OTSU)[1]
return crop_img
def get_text_image(self, crop_img):
return pytesseract.image_to_string(crop_img, lang=self.language)
def match_with_text(self, screenshot):
crop_img = screenshot[self.TEXT_POSITION[0]:self.TEXT_POSITION[0] + self.TEXT_SIZE[0],
self.TEXT_POSITION[1]:self.TEXT_POSITION[1] + self.TEXT_SIZE[1]]
crop_img = self.change_image(crop_img)
text = self.get_text_image(crop_img)
print("Detect text:")
print(text)
for fish in self.match_words:
if fish.lower() in text.lower():
print(f"✅ Eşleşme bulundu: {fish}")
return True
return False