|
import os |
|
import math |
|
import time |
|
import numpy as np |
|
|
|
class timer(): |
|
def __init__(self): |
|
self.acc = 0 |
|
self.tic() |
|
|
|
def tic(self): |
|
self.t0 = time.time() |
|
|
|
def toc(self, restart=False): |
|
diff = time.time() - self.t0 |
|
if restart: self.t0 = time.time() |
|
return diff |
|
|
|
def hold(self): |
|
self.acc += self.toc() |
|
|
|
def release(self): |
|
ret = self.acc |
|
self.acc = 0 |
|
|
|
return ret |
|
|
|
def reset(self): |
|
self.acc = 0 |
|
|
|
def quantize(img, rgb_range): |
|
pixel_range = 255 / rgb_range |
|
return img.mul(pixel_range).clamp(0, 255).round().div(pixel_range) |
|
|