Skip to content

Commit

Permalink
refactor: lock versions, upgrade to python 3.11
Browse files Browse the repository at this point in the history
  • Loading branch information
alex-ong committed Dec 29, 2023
1 parent 3a9d882 commit e24d173
Show file tree
Hide file tree
Showing 19 changed files with 27 additions and 45 deletions.
1 change: 0 additions & 1 deletion nestris_ocr/calibration/auto_number.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@ def track_best_result(lowestScore, bestRect, result):


def auto_adjust_numrect(capture_coords, rect, numDigits, updateUI):

pattern = "D" * numDigits

i = 0
Expand Down
1 change: 0 additions & 1 deletion nestris_ocr/calibration/number_chooser.py
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,6 @@ def __init__(self, root, name, defaultValue, isFloat, OnChange, minCrement):
).grid(row=1, column=3, sticky="nsew")

def changeValueText(self):

success, value = self.checker(self.value.get())
if success:
self.OnChange(value)
Expand Down
1 change: 0 additions & 1 deletion nestris_ocr/calibration/widgets.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,5 @@ def __init__(self, *args, **kwargs):

super(Button, self).__init__(*args, **kwargs)


else:
from tkinter import Button
1 change: 0 additions & 1 deletion nestris_ocr/capturing/deinterlacer.py
Original file line number Diff line number Diff line change
Expand Up @@ -108,7 +108,6 @@ def deinterlace_np(img):

# de-interlaces a PIL.Image
def deinterlace(img):

mode, res = get_mode_res()

full_size = list(img.size)
Expand Down
1 change: 0 additions & 1 deletion nestris_ocr/capturing/file.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,6 @@ def __init__(self, source_id: str, xywh_box: XYWHBox, extra_data: str) -> None:
self.total_frames = int(self.cap.get(cv2.CAP_PROP_FRAME_COUNT))

def get_image(self, rgb: bool = False) -> Tuple[float, Image.Image]:

if not self.cap:
return None, None

Expand Down
2 changes: 0 additions & 2 deletions nestris_ocr/capturing/opencv/opencv.py
Original file line number Diff line number Diff line change
Expand Up @@ -99,7 +99,6 @@ def get_image(self, rgb: bool = False) -> Tuple[float, Image.Image]:
image_ts = self.image_ts

if rgb:

cv2_image = cv2.cvtColor(cv2_image, cv2.COLOR_BGR2RGB)

image = Image.fromarray(cv2_image).crop(xywh_to_ltrb(self.xywh_box))
Expand All @@ -124,7 +123,6 @@ def update(self):
frame_times = deque([], 10)
start_frame_ts = None
while self.running:

cv2_retval, cv2_image = self.cap.read()
avg_ft = self.calculate_avg_frametime(frame_times, start_frame_ts)
start_frame_ts = time.time()
Expand Down
4 changes: 1 addition & 3 deletions nestris_ocr/network/autobahn_client.py
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,6 @@ def CreateClient(target, port):


class MyClientProtocol(WebSocketClientProtocol):

connections = []

def onConnect(self, response):
Expand Down Expand Up @@ -87,7 +86,6 @@ def close_all(cls):


class MyClientFactory(WebSocketClientFactory, ReconnectingClientFactory):

protocol = MyClientProtocol
closing = False
kickMessage = None
Expand All @@ -108,7 +106,7 @@ def __init__(self, target, port):
super().__init__()
self.port = port
self.host = target
self.factory = MyClientFactory(u"ws://" + target + ":" + str(port))
self.factory = MyClientFactory("ws://" + target + ":" + str(port))

# reactor thread
def run(self):
Expand Down
5 changes: 2 additions & 3 deletions nestris_ocr/network/autobahn_server.py
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,7 @@ def __init__(self, target, port):
print(
"Warning, starting up autobahn_server with target not equal to localhost"
)
self.url = u"ws://" + target + ":" + str(port)
self.url = "ws://" + target + ":" + str(port)
self.protocol = OCRServer
self.running = False

Expand Down Expand Up @@ -132,14 +132,13 @@ def stop(self):


if __name__ == "__main__":

import sys

from twisted.python import log

log.startLogging(sys.stdout)

factory = WebSocketServerFactory(u"ws://127.0.0.1:3338")
factory = WebSocketServerFactory("ws://127.0.0.1:3338")
factory.protocol = MyServerProtocol

reactor.listenTCP(3338, factory)
Expand Down
Binary file not shown.
Binary file not shown.
1 change: 0 additions & 1 deletion nestris_ocr/network/tcp_client.py
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,6 @@ def run(self):
# Create a socket (SOCK_STREAM means a TCP socket)
while not self.stopped():
with socket.socket(socket.AF_INET, socket.SOCK_STREAM) as sock:

sock.setsockopt(socket.IPPROTO_TCP, socket.TCP_NODELAY, True)
sock.settimeout(TIME_OUT)
try:
Expand Down
2 changes: 0 additions & 2 deletions nestris_ocr/ocr_algo/board2.py
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,6 @@ def match_color(pixr, pixg, pixb, colors):
cache=True,
)
def shine_parse(img, colors_bw, colors_noblack):

# todo: maybe pass this in as a 3d array instead,
# as numba hates python arrays
colors_noblack_remap = [1, 2, 3]
Expand Down Expand Up @@ -100,7 +99,6 @@ def shine_parse(img, colors_bw, colors_noblack):
cache=True,
)
def ao9_parse(img, colors):

# todo: maybe pass this in as a 3d array instead,
# as numba hates python arrays

Expand Down
Binary file not shown.
2 changes: 0 additions & 2 deletions nestris_ocr/ocr_algo/build_fastboard.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,6 @@ def match_color(pixr, pixg, pixb, colors):

@cc.export("shine_parse", "uint8[:,:](uint8[:,:,:],uint8[:,:],uint8[:,:])")
def shine_parse(img, colors_bw, colors_noblack):

# todo: maybe pass this in as a 3d array instead,
# as numba hates python arrays
colors_noblack_remap = [1, 2, 3]
Expand Down Expand Up @@ -91,7 +90,6 @@ def shine_parse(img, colors_bw, colors_noblack):

@cc.export("ao9_parse", "uint8[:,:](uint8[:,:,:],uint8[:,:])")
def ao9_parse(img, colors):

# todo: maybe pass this in as a 3d array instead,
# as numba hates python arrays

Expand Down
8 changes: 3 additions & 5 deletions nestris_ocr/ocr_algo/digit.py
Original file line number Diff line number Diff line change
Expand Up @@ -36,9 +36,7 @@ def setupColour(prefix, outputDict, digitList):

img = img.convert("L")
if IMAGE_MULT != 1:
img = img.resize(
(SCALED_IMAGE_SIZE, SCALED_IMAGE_SIZE), PIL.Image.LANCZOS
)
img = img.resize((SCALED_IMAGE_SIZE, SCALED_IMAGE_SIZE), PIL.Image.LANCZOS)

img = img.getdata()
img = np.asarray(img)
Expand Down Expand Up @@ -107,7 +105,7 @@ def scoreImage0(img, digitPattern):
count = len(digitPattern)
img = convertImg(img, count, False)

for (i, pattern) in enumerate(digitPattern):
for i, pattern in enumerate(digitPattern):
result = getDigit(img, pattern, i * (BLOCK_SIZE * IMAGE_MULT), 0, False)
if result[0] == "null":
return None
Expand All @@ -121,7 +119,7 @@ def scoreImage(img, digitPattern, show=False, red=False):
count = len(digitPattern)
img = convertImg(img, count, show)
label = ""
for (i, pattern) in enumerate(digitPattern):
for i, pattern in enumerate(digitPattern):
if pattern == "X":
result = "X"
else:
Expand Down
1 change: 1 addition & 0 deletions nestris_ocr/ocr_state/field_state.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
from nestris_ocr.config import config # TODO: remove this dependency.
from nestris_ocr.network.byte_stuffer import prePackField


# Todo: numba optimize for numTiles
# Make sure we account for rotating piece above field, as this reduces
# Blockcount by 2
Expand Down
1 change: 0 additions & 1 deletion nestris_ocr/scan_strat/scan_helpers.py
Original file line number Diff line number Diff line change
Expand Up @@ -149,7 +149,6 @@ def scan_black_n_white(full_image):

for x in range(img_bnw_mono.width):
for y in range(img_bnw_mono.height):

value = img_bnw_mono.getpixel((x, y))

if value > whitest:
Expand Down
16 changes: 8 additions & 8 deletions requirements.txt
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
autobahn[twisted]
cached-property
numba
numpy
opencv-python
pillow
pre-commit
websockets
autobahn[twisted]==23.6.2
cached-property==1.5.2
numba==0.58.1
numpy==1.26.2
opencv-python==4.8.1.78
pillow==10.1.0
pre-commit==3.6.0
websockets==12.0
pyobjc; sys_platform == "darwin"
pypiwin32; sys_platform == "win32"
tkmacosx; sys_platform == "darwin"
25 changes: 12 additions & 13 deletions scripts/build-windows/requirements.txt
Original file line number Diff line number Diff line change
@@ -1,16 +1,15 @@
autobahn[twisted]
cached-property
numba==0.50.1
https://download.lfd.uci.edu/pythonlibs/w3jqiv8s/numpy-1.18.5+vanilla-cp37-cp37m-win32.whl; sys_platform == "win32"
opencv-python-headless
pillow
pre-commit
websockets
autobahn[twisted]==23.6.2
cached-property==1.5.2
numba==0.58.1
numpy==1.26.2
opencv-python-headless==4.8.1.78
pillow==10.1.0
pre-commit==3.6.0
websockets==12.0
pyobjc; sys_platform == "darwin"
pypiwin32; sys_platform == "win32"
tkmacosx; sys_platform == "darwin"
setuptools==44.0.0
pyinstaller==3.6
zip-files
gitchangelog
pystache
pyinstaller==5.13.1
zip-files==0.4.1
gitchangelog==3.0.4
pystache==0.6.5

0 comments on commit e24d173

Please sign in to comment.