Skip to content

Commit 703090f

Browse files
author
anna-singleton-resolver
committed
style: standardise opencv2 imports to be import cv2 as cv
1 parent 81dd1b1 commit 703090f

3 files changed

Lines changed: 15 additions & 15 deletions

File tree

src/resolver_athena_client/client/transformers/core.py

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99
import enum
1010

1111
import brotli
12-
import cv2
12+
import cv2 as cv
1313
import numpy as np
1414

1515
from resolver_athena_client.client.consts import EXPECTED_HEIGHT, EXPECTED_WIDTH
@@ -28,10 +28,10 @@ class OpenCVResamplingAlgorithm(enum.Enum):
2828
resampling algorithms.
2929
"""
3030

31-
NEAREST = cv2.INTER_NEAREST
32-
BOX = cv2.INTER_AREA
33-
BILINEAR = cv2.INTER_LINEAR
34-
LANCZOS = cv2.INTER_LANCZOS4
31+
NEAREST = cv.INTER_NEAREST
32+
BOX = cv.INTER_AREA
33+
BILINEAR = cv.INTER_LINEAR
34+
LANCZOS = cv.INTER_LANCZOS4
3535

3636

3737
def _is_raw_bgr_expected_size(data: bytes) -> bool:
@@ -66,7 +66,7 @@ def process_image() -> tuple[bytes, bool]:
6666

6767
# Try to load the image data directly
6868
img_data_buf = np.frombuffer(image_data.data, dtype=np.uint8)
69-
img = cv2.imdecode(img_data_buf, cv2.IMREAD_COLOR)
69+
img = cv.imdecode(img_data_buf, cv.IMREAD_COLOR)
7070

7171
if img is None:
7272
err = "Failed to decode image data for resizing"
@@ -75,7 +75,7 @@ def process_image() -> tuple[bytes, bool]:
7575
if img.shape[0] == EXPECTED_HEIGHT and img.shape[1] == EXPECTED_WIDTH:
7676
resized_img = img
7777
else:
78-
resized_img = cv2.resize(
78+
resized_img = cv.resize(
7979
img, _target_size, interpolation=sampling_algorithm.value
8080
)
8181

tests/client/transformers/test_hash_pipeline.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22

33
import hashlib
44

5-
import cv2
5+
import cv2 as cv
66
import numpy as np
77
import pytest
88

@@ -27,7 +27,7 @@ def create_test_png_image(width: int = 200, height: int = 200) -> bytes:
2727
img[:] = (255, 0, 0) # Red color
2828

2929
# Encode image as PNG to memory
30-
success, buffer = cv2.imencode(".png", img)
30+
success, buffer = cv.imencode(".png", img)
3131
if not success:
3232
err = "Failed to encode image as PNG"
3333
raise RuntimeError(err)

tests/functional/conftest.py

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import os
22
import uuid
33

4-
import cv2
4+
import cv2 as cv
55
import numpy as np
66
import pytest
77
import pytest_asyncio
@@ -26,7 +26,7 @@ def _create_base_test_image_opencv(width: int, height: int) -> np.ndarray:
2626
height: Image height in pixels
2727
2828
Returns:
29-
numpy array in BGR format suitable for cv2.imencode
29+
numpy array in BGR format suitable for cv.imencode
3030
"""
3131
# Create a simple test image with random colors
3232
# Background color (blue-green)
@@ -36,7 +36,7 @@ def _create_base_test_image_opencv(width: int, height: int) -> np.ndarray:
3636
# Add an accent rectangle for visual variation
3737
x1, y1 = width // 4, height // 4
3838
x2, y2 = (width * 3) // 4, (height * 3) // 4
39-
return cv2.rectangle(img_bgr, (x1, y1), (x2, y2), (200, 100, 50), -1)
39+
return cv.rectangle(img_bgr, (x1, y1), (x2, y2), (200, 100, 50), -1)
4040

4141

4242
SUPPORTED_TEST_FORMATS = [
@@ -138,10 +138,10 @@ def valid_formatted_image(
138138
# Encode image in the target format
139139
if image_format in ["pgm", "pbm"]:
140140
# PGM and PBM are grayscale, so convert the image to grayscale
141-
gray_image = cv2.cvtColor(base_image, cv2.COLOR_BGR2GRAY)
142-
success, encoded = cv2.imencode(f".{image_format}", gray_image)
141+
gray_image = cv.cvtColor(base_image, cv.COLOR_BGR2GRAY)
142+
success, encoded = cv.imencode(f".{image_format}", gray_image)
143143
else:
144-
success, encoded = cv2.imencode(f".{image_format}", base_image)
144+
success, encoded = cv.imencode(f".{image_format}", base_image)
145145

146146
if not success:
147147
pytest.fail(f"OpenCV failed to encode image in {image_format} format")

0 commit comments

Comments
 (0)