Compare commits

...

2 Commits

Author SHA1 Message Date
Doc
4c01b72b54 Improved the seeking in the grid calibration
- Make the seeking of the upper left corner more intelligent/responsive rather than hard coding "left 15 times up 15 times"
- Commented out more experimentation code
2026-01-13 10:08:15 -05:00
Doc
4e4d3fc854 Fixed variable name in map size calculation
- accidentlally used cal_right_border instead of cal_bottom_border. Always pay attention to warnings of unused variables
- commented out unused code
2026-01-13 09:57:09 -05:00
2 changed files with 41 additions and 35 deletions

View File

@@ -1,6 +1,5 @@
import json
import time
import timeit
from pathlib import Path
import cv2
@@ -248,8 +247,22 @@ class DFWINDOW:
time.sleep(self.sleep_after_mouse)
self.focusWindow()
time.sleep(self.sleep_after_focus)
self.sendKeys("w", 30)
self.sendKeys("a", 30)
# Improved seeking upper left
self.sendKeys("w", 8)
img = self.capContent()
while not self.TOOLS.isTopBorder(img):
self.sendKeys("w", 4)
img = self.capContent()
self.sendKeys("w", 4)
self.sendKeys("a", 8)
img = self.capContent()
while not self.TOOLS.isLeftBorder(img):
self.sendKeys("a", 4)
img = self.capContent()
self.sendKeys("a", 4)
img = self.capWindow()
self._content_left, self._content_top = self.TOOLS.find_content_origin(img)
self._content_right = int(img.shape[1] - self._content_left)
@@ -369,7 +382,7 @@ class DFWINDOW:
self._map_height = (
(img.shape[0] - cal_top_border) # Grid x = 0
+ ((self._gridy_max - 1) * self._step_size_y) # All the middle
+ cal_right_border # grid x = max
+ cal_bottom_border # grid x = max
)
self.setGridPos(0, 0)
@@ -382,31 +395,31 @@ class DFWINDOW:
def test1(self):
# rawimg = cv2.imread("./test_img.png")
rawimg = cv2.imread("grid_base_3.png")
img = rawimg[100 : -self.bottom_to_ignore - 70, 65:-65]
tlb = self.TOOLS.firstNotBlackX(img)
ttb = self.TOOLS.firstNotBlackY(img)
# rawimg = cv2.imread("grid_base_3.png")
# img = rawimg[100 : -self.bottom_to_ignore - 70, 65:-65]
# tlb = self.TOOLS.firstNotBlackX(img)
# ttb = self.TOOLS.firstNotBlackY(img)
tt_setup = (
r"gc.enable() ; import cv2 ; import numpy as np ; timg = cv2.imread('./test_img.png', cv2.IMREAD_UNCHANGED)"
)
tt1 = timeit.Timer(
"np.where(np.mean(cv2.cvtColor(timg, cv2.COLOR_BGR2GRAY), axis=0) > 15)[0][0]",
setup=tt_setup,
)
tt2 = timeit.Timer(
"np.where(np.max(cv2.cvtColor(timg, cv2.COLOR_BGR2GRAY), axis=0) > 25)[0][0]",
setup=tt_setup,
)
tt3 = timeit.Timer(
"np.where(np.max(cv2.cvtColor(timg, cv2.COLOR_BGRA2GRAY), axis=0) > 25)[0][0]",
setup=tt_setup,
)
# tt_setup = (
# r"gc.enable() ; import cv2 ; import numpy as np ; timg = cv2.imread('./test_img.png', cv2.IMREAD_UNCHANGED)"
# )
# tt1 = timeit.Timer(
# "np.where(np.mean(cv2.cvtColor(timg, cv2.COLOR_BGR2GRAY), axis=0) > 15)[0][0]",
# setup=tt_setup,
# )
# tt2 = timeit.Timer(
# "np.where(np.max(cv2.cvtColor(timg, cv2.COLOR_BGR2GRAY), axis=0) > 25)[0][0]",
# setup=tt_setup,
# )
# tt3 = timeit.Timer(
# "np.where(np.max(cv2.cvtColor(timg, cv2.COLOR_BGRA2GRAY), axis=0) > 25)[0][0]",
# setup=tt_setup,
# )
num_tests = 80
r1 = tt1.timeit(number=num_tests)
r2 = tt2.timeit(number=num_tests)
r3 = tt3.timeit(number=num_tests)
# num_tests = 80
# r1 = tt1.timeit(number=num_tests)
# r2 = tt2.timeit(number=num_tests)
# r3 = tt3.timeit(number=num_tests)
logger.debug("Pause here for testing")
@@ -456,11 +469,6 @@ class DFWINDOW:
self._map_width = calib_info["map_width"]
def getPanoramaMap(self):
# self.test1()
# return
self.calibrateGrid()
# self.test_saveGrids()
# self.test_loadCalib()
return None

View File

@@ -2,8 +2,6 @@ import json
import subprocess
import pydantic as pyd
import cv2
import numpy as np
from .dfwindow import DFWINDOW
from .mylogging import logger, setup_logging