Skip to content

Commit

Permalink
mypy error fixed
Browse files Browse the repository at this point in the history
  • Loading branch information
sthysel committed Jul 22, 2021
1 parent 78d2132 commit ac6b351
Show file tree
Hide file tree
Showing 7 changed files with 27 additions and 108 deletions.
2 changes: 1 addition & 1 deletion .isort.cfg
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
[settings]
known_third_party = GPUtil,click,common,cpuinfo,cv2,imutils,matplotlib,nmap,numpy,pkg_resources,rakali,video,zeroconf
known_third_party = GPUtil,click,cpuinfo,cv2,imutils,matplotlib,nmap,numpy,pkg_resources,rakali,zeroconf
4 changes: 3 additions & 1 deletion examples/skeletonize.py
Original file line number Diff line number Diff line change
@@ -1,8 +1,10 @@
#! /usr/bin/env python

from pathlib import Path

from rakali import Image

img: Image = Image.from_file("rakali.jpg")
img: Image = Image.from_file(Path("rakali.jpg"))
img.skeletonize()
img.show()
img.write("rakali-skeletonize.jpg")
4 changes: 3 additions & 1 deletion examples/text.py
Original file line number Diff line number Diff line change
@@ -1,8 +1,10 @@
#! /usr/bin/env python

from pathlib import Path

from rakali import Image

img: Image = Image.from_file("rakali.jpg")
img: Image = Image.from_file(Path("rakali.jpg"))
img.add_text(labels=["Rakali", "Hydromys chrysogaster"])
img.show()
img.write("rakali-text.jpg")
88 changes: 0 additions & 88 deletions src/facedetect.py

This file was deleted.

14 changes: 7 additions & 7 deletions src/rakali/camera/chessboard.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
import json
import os
import sys
from typing import Tuple
from typing import List, Optional, Tuple

import cv2 as cv
import numpy as np
Expand Down Expand Up @@ -54,7 +54,7 @@ def refine_corners(self, gray, corners):
return corners

def corners(self, frame, fast=True):
""" Get the corners for calibration"""
"""Get the corners for calibration"""
gray = cv.cvtColor(frame, cv.COLOR_BGR2GRAY)
ret, corners = self.get_chessboard_corners(gray, fast=fast)
if ret:
Expand All @@ -64,7 +64,7 @@ def corners(self, frame, fast=True):

@cost
def has_chessboard(self, frame):
"""boolean test for chessboard pressense in frame """
"""boolean test for chessboard pressense in frame"""
gray = cv.cvtColor(frame, cv.COLOR_BGR2GRAY)
ret, _ = self.get_chessboard_corners(gray=gray)
return ret
Expand All @@ -74,8 +74,8 @@ def draw(self, frame, corners):
return cv.drawChessboardCorners(frame, self.size, corners, True)


def load_image_points_file(save_file) -> Tuple[list, list, tuple]:
"""load from previously computed file """
def load_image_points_file(save_file) -> Optional[Tuple[List, List, Tuple]]:
"""load from previously computed file"""

print(f"Loading previously computed image points from {save_file}")
try:
Expand Down Expand Up @@ -164,10 +164,10 @@ def filter_unusable_pairs(
boards_path,
chessboard_size,
):
""" Run through image set and remove all pairs that fail the quality test"""
"""Run through image set and remove all pairs that fail the quality test"""

def remove_pair(filename):
"""remove complementary pair if one of the pair is unfit """
"""remove complementary pair if one of the pair is unfit"""
print(f"Removing complementary pair of which {filename} is part")
_, rest = filename.split("_")
pair = glob.glob(str(boards_path / f"*_{rest}"))
Expand Down
17 changes: 9 additions & 8 deletions src/rakali/camera/fisheye_stereo.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
import logging
from datetime import datetime
from pathlib import Path
from typing import Dict, Optional

import cv2 as cv
import numpy as np
Expand All @@ -24,7 +25,7 @@


def stereo_calibrate(calibration_data, use_pre_calibrated=True):
""" do stereo calibration using pre-calibration values from left and right eyes """
"""do stereo calibration using pre-calibration values from left and right eyes"""

print("Calibrate Fisheye Stereo camera using pre-calibrated values")

Expand Down Expand Up @@ -123,7 +124,7 @@ def save_stereo_calibration(
pick_size: int,
cid: str,
):
"""" Save calibration data """
""" " Save calibration data"""

calibration_parameters["image_size"] = image_size
calibration_parameters["salt"] = salt
Expand All @@ -137,8 +138,8 @@ def save_stereo_calibration(
f.write(dumped)


def load_stereo_calibration(calibration_file) -> dict:
"""load from previously computed file """
def load_stereo_calibration(calibration_file) -> Optional[Dict]:
"""load from previously computed file"""

print(f"Loading previously computed stereo calibration from {calibration_file}")
try:
Expand All @@ -160,7 +161,7 @@ def load_stereo_calibration(calibration_file) -> dict:


def print_calibration(calibration):
""" Pretty print stereo fisheye calibration parameters """
"""Pretty print stereo fisheye calibration parameters"""

with np.printoptions(precision=3, suppress=True):
print("K Left")
Expand Down Expand Up @@ -198,7 +199,7 @@ def calibration_labels(calibration, side):


class CalibratedStereoFisheyeCamera:
""" A Calibrated stereo fish-eye camera """
"""A Calibrated stereo fish-eye camera"""

def __init__(
self,
Expand Down Expand Up @@ -245,11 +246,11 @@ def calibration_time(self):

@property
def calibration_time_formatted(self):
""" formated calibration time """
"""formated calibration time"""
return datetime.fromtimestamp(self.calibration_time)

def set_stereo_rectify_parameters(self):
""" set rotation matrices """
"""set rotation matrices"""

self.R_left, self.R_right, self.P1, self.P2, self.Q = cv.fisheye.stereoRectify(
K1=self.calibration["K_left"],
Expand Down
6 changes: 4 additions & 2 deletions src/rakali/testimages/__init__.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
from pathlib import Path

from pkg_resources import resource_filename

from ..img import Image

print(resource_filename(__name__, "rakali.jpg"))
rakali = Image.from_file(resource_filename(__name__, "rakali.jpg"))
orb_spider = Image.from_file(resource_filename(__name__, "orb-spider.jpg"))
rakali = Image.from_file(Path(resource_filename(__name__, "rakali.jpg")))
orb_spider = Image.from_file(Path(resource_filename(__name__, "orb-spider.jpg")))

0 comments on commit ac6b351

Please sign in to comment.