<filename>src/recognition/image.py
import cv2
import imutils


class open_images(object):

    def __init__(self, path):
        self._images      = cv2.imread(path)

    def rectangle(self, color, thickness, line_type, shift):
        self._images = cv2.rectangle(self.cv, color, thickness, line_type, shift)

    @property
    def shape(self) -> tuple:
        return self.cv.shape

    @property
    def dimensions(self) -> tuple:
        return int(self.width), int(self.height)

    @property
    def width(self) -> int:
        return self.shape[1]

    @property
    def height(self) -> int:
        return self.shape[0]

    @property
    def gray(self):
        return cv2.cvtColor(self.cv, cv2.COLOR_BGR2GRAY)

    @property
    def cv(self):
        return self._images

    @property
    def buffer(self):
        return cv2.imencode(".png", self.cv)[1]


class find_contour(object):

    def __init__(self, difference):
        self._difference = difference
        self._contours = imutils.grab_contours(
            cv2.findContours(self._thresh.copy(), cv2.RETR_EXTERNAL, cv2.CHAIN_APPROX_SIMPLE)
        )

    @property
    def _thresh(self):
        return cv2.threshold(self._difference, 0, 255, cv2.THRESH_BINARY_INV | cv2.THRESH_OTSU)[1]

    def __iter__(self):
        for contour in self._contours:
            yield cv2.boundingRect(contour)


__all__ = [
    "open_images", "find_contour"
]
<filename>src/recognition/image.py
import cv2
import imutils


class open_images(object):

    def __init__(self, path):
        self._images      = cv2.imread(path)

    def rectangle(self, color, thickness, line_type, shift):
        self._images = cv2.rectangle(self.cv, color, thickness, line_type, shift)

    @property
    def shape(self) -> tuple:
        return self.cv.shape

    @property
    def dimensions(self) -> tuple:
        return int(self.width), int(self.height)

    @property
    def width(self) -> int:
        return self.shape[1]

    @property
    def height(self) -> int:
        return self.shape[0]

    @property
    def gray(self):
        return cv2.cvtColor(self.cv, cv2.COLOR_BGR2GRAY)

    @property
    def cv(self):
        return self._images

    @property
    def buffer(self):
        return cv2.imencode(".png", self.cv)[1]


class find_contour(object):

    def __init__(self, difference):
        self._difference = difference
        self._contours = imutils.grab_contours(
            cv2.findContours(self._thresh.copy(), cv2.RETR_EXTERNAL, cv2.CHAIN_APPROX_SIMPLE)
        )

    @property
    def _thresh(self):
        return cv2.threshold(self._difference, 0, 255, cv2.THRESH_BINARY_INV | cv2.THRESH_OTSU)[1]

    def __iter__(self):
        for contour in self._contours:
            yield cv2.boundingRect(contour)


__all__ = [
    "open_images", "find_contour"
]