Reimplemented stuff using opencv functions