In [8]:
import cv2
import os
class Position(object):
def __init__(self, x=0, y=0, extra={}):
self.x = x
self.y = y
self.extra = extra
class Rectangle(object):
def __init__(self, left=0, top=0, right=None, bottom=None, width='100%', height='100%'):
pass
In [9]:
class FileNotExistsException(Exception):
pass
class ImageFormatException(Exception):
pass
In [10]:
class Image(object):
def __init__(self, filename=None, data=None, format=None, cvobj=None):
self._cvobj = None
if filename is not None:
if not os.path.exists(filename):
raise FileNotExistsException('filename: "%s"' % filename)
self._cvobj = cv2.imread(filename)
if self._cvobj is None:
raise ImageFormatException("Canot recognize image format")
def show(self):
pass
def save(self, filename):
pass
def rect(self):
return Rectangle()
def crop(self, rect):
return Image(cvobj=self._cvobj)
#Image(filename='oo')
In [ ]: