-
Notifications
You must be signed in to change notification settings - Fork 1
/
taskbar_detect.py
77 lines (58 loc) · 2.36 KB
/
taskbar_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
72
73
74
75
76
77
import cv2
import os
def crop_image(image_path, crop_size):
# Read the image
image = cv2.imread(image_path)
# Get the dimensions of the image
height, width = image.shape[:2]
# Crop regions
top = image[0:crop_size, 0:width]
bottom = image[height-crop_size:height, 0:width]
left = image[0:height, 0:crop_size]
right = image[0:height, width-crop_size:width]
return top, bottom, left, right
# Load images
folder_path = 'icons/'
files = os.listdir(folder_path)
# Crop image
top, bottom, left, right = crop_image('img3.png', 50)
taskbar_found = 0
# Loop through browser icons
for file in files:
icon = cv2.imread(os.path.join(folder_path, file))
for region in [bottom, top, left, right]:
# Convert to grayscale
gray_region = cv2.cvtColor(region, cv2.COLOR_BGR2GRAY)
gray_icon = cv2.cvtColor(icon, cv2.COLOR_BGR2GRAY)
result = cv2.matchTemplate(gray_region, gray_icon, cv2.TM_CCOEFF_NORMED)
min_val, max_val, min_loc, max_loc = cv2.minMaxLoc(result)
if max_val > 0.8:
print("Browser found")
taskbar_found = 1
# # Icon location
# icon_width, icon_height = icon.shape[1], icon.shape[0]
# top_left = max_loc
# bottom_right = (top_left[0] + icon_width, top_left[1] + icon_height)
# # Take top_left and bottom_right and draw a box
# cv2.rectangle(region, top_left, bottom_right, (0, 255, 0), 2)
# cv2.imshow('Icon found', region)
# cv2.waitKey(0)
# cv2.destroyAllWindows()
break
if taskbar_found:
pass
# def find_icon(image_path, icon_path):
# # Load images
# image = cv2.imread(image_path)
# icon = cv2.imread(icon_path)
# # Convert to grayscale
# gray_image = cv2.cvtColor(image, cv2.COLOR_BGR2GRAY)
# gray_icon = cv2.cvtColor(icon, cv2.COLOR_BGR2GRAY)
# # Perform template matching
# result = cv2.matchTemplate(gray_image, gray_icon, cv2.TM_CCOEFF_NORMED)
# min_val, max_val, min_loc, max_loc = cv2.minMaxLoc(result)
# # Icon location
# icon_width, icon_height = icon.shape[1], icon.shape[0]
# top_left = max_loc
# bottom_right = (top_left[0] + icon_width, top_left[1] + icon_height)
# return top_left, bottom_right