Skip to content

Commit

Permalink
Upgrade pillow version (#177)
Browse files Browse the repository at this point in the history
* Upgrade pillow version

* Fix typing errors

* Stop supporting python 3.8

* Fix ImageFont length and overlay_predictions

* Support python 3.8

* Remove python 3.12

* Support pillow >9,<11
  • Loading branch information
camiloaz authored Feb 9, 2024
1 parent cf12333 commit 4f6b159
Show file tree
Hide file tree
Showing 7 changed files with 2,014 additions and 1,711 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/ci_cd.yml
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ jobs:
Test:
strategy:
matrix:
python-version: [3.8, 3.10.11]
python-version: ["3.8", "3.9", "3.10", "3.11"]
os: [ ubuntu-22.04, windows-2022, macos-12 ]
runs-on: ${{ matrix.os }}
steps:
Expand Down
1 change: 0 additions & 1 deletion examples/apps/zoom-app/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,5 +2,4 @@

Ensure you have python 3.8 or higher installed on your machine. If you do not, follow these [instructions](https://docs.anaconda.com/free/anaconda/install/index.html) to install python. Run `pip install -r requirements.txt` to install the requirements.


Once the requirements are installed run `streamlit run app.py` to run the application. It should show up on your browser, you may have to give python permissions to view your camera for it to run properly.
2 changes: 1 addition & 1 deletion landingai/pipeline/image_source.py
Original file line number Diff line number Diff line change
Expand Up @@ -236,7 +236,7 @@ class NetworkedCamera(BaseModel, ImageSourceBase):
stream_url: str
motion_detection_threshold: int
capture_interval: Union[float, None] = None
previous_frame: Union[Frame, None] = None
previous_frame: Union[np.ndarray, None] = None
_last_capture_time: datetime = PrivateAttr()
_cap: Any = PrivateAttr() # cv2.VideoCapture
_t: Any = PrivateAttr() # threading.Thread
Expand Down
2 changes: 1 addition & 1 deletion landingai/timer.py
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ def __init__(self, *args: Any, **kwargs: Any) -> None:
"""Add a private dictionary keeping track of all timings"""
super().__init__(*args, **kwargs)
self._timings: Dict[str, MutableSequence[float]] = defaultdict(
partial(deque, maxlen=_MAX_SIZE) # type: ignore
partial(deque, maxlen=_MAX_SIZE)
)

def add(self, name: str, value: float) -> None:
Expand Down
7 changes: 5 additions & 2 deletions landingai/visualize.py
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@ def overlay_ocr_predictions(
img_right_text = _draw_box_text((w, h), box, txt)
pts = np.array(box, np.int32).reshape((-1, 1, 2))
cv2.polylines(img_right_text, [pts], True, color, 1)
img_right = cv2.bitwise_and(img_right, img_right_text)
img_right = np.array(cv2.bitwise_and(img_right, img_right_text), dtype=np.uint8)
img_left = Image.blend(image, img_left, 0.5)
img_show = Image.new("RGB", (w * 2, h), (255, 255, 255))
img_show.paste(img_left, (0, 0, w, h))
Expand Down Expand Up @@ -127,6 +127,9 @@ def overlay_bboxes(
else:
image = np.asarray(image)

# Numpy arrays created from PIL images are read-only by default. By copying it, we make it writeable.
image = image.copy()

if options is None:
options = {}
bbox_style = options.get("bbox_style", "default").lower()
Expand Down Expand Up @@ -350,7 +353,7 @@ def _create_font(
) -> ImageFont.FreeTypeFont:
font_size = int(min(size) * 0.99)
font = ImageFont.truetype(font_path, font_size, encoding="utf-8")
length = font.getsize(txt)[0]
length = font.getlength(txt)
if length > size[0]:
font_size = int(font_size * size[0] / length)
font = ImageFont.truetype(font_path, font_size, encoding="utf-8")
Expand Down
3,709 changes: 2,005 additions & 1,704 deletions poetry.lock

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ python = ">=3.8,<4.0"

opencv-python = ">=4.5,<5.0" # about 87MB (exclude transitive dependencies)
numpy = ">=1.21.0,<2.0.0"
pillow = "9.*" # Version 10.0.0 had a issue on FreeTypeFont that will be fixed on the next release
pillow = ">=9.0,<11.0"
pydantic = { version = "1.*", extras = ["dotenv"] } # Version 2 has breaking changes (in particular to seetings)
requests = "2.*"
# snowflake-connector-python = "3.0.*" # about 51MB (exclude transitive dependencies)
Expand Down

0 comments on commit 4f6b159

Please sign in to comment.