Implement checking for loaded image
This commit is contained in:
parent
395729aca1
commit
64561d7be4
15
imgrate.py
15
imgrate.py
@ -2,15 +2,28 @@
|
||||
import cv2
|
||||
import numpy as np
|
||||
from argparse import ArgumentParser
|
||||
from functools import wraps
|
||||
|
||||
|
||||
def image_required(fun):
|
||||
@wraps(fun)
|
||||
def wrapper(self, *args, **kwargs):
|
||||
if self.image is None:
|
||||
raise RuntimeError('Method {}.{} requires an image!'
|
||||
.format(self.__class__.__name__, fun.__name__))
|
||||
return fun(self, *args, **kwargs)
|
||||
return wrapper
|
||||
|
||||
|
||||
class imgrate:
|
||||
def __init__(self, image=None):
|
||||
self.image = image
|
||||
|
||||
@image_required
|
||||
def laplacian_variance(self):
|
||||
return cv2.Laplacian(self.image, cv2.CV_64F).var()
|
||||
|
||||
@image_required
|
||||
def fdibm(self):
|
||||
F = np.fft.fft2(self.image)
|
||||
Fcentered = np.fft.fftshift(F)
|
||||
@ -28,4 +41,4 @@ if __name__ == '__main__':
|
||||
image = cv2.imread(args.images[0])
|
||||
grayscale = cv2.cvtColor(image, cv2.COLOR_BGR2GRAY)
|
||||
|
||||
print(imgrate(grayscale).fdibm())
|
||||
print(imgrate(grayscale).laplacian_variance())
|
Loading…
Reference in New Issue
Block a user