我目前正在尝试设计一个 Node.js 代码,它能够判断图像是否模糊。为了实现这一目标,我从这个问题中获得了灵感。所以我需要做的是计算矩阵拉普拉斯(这就是我们所说的?),然后计算方差。
我用 OpenCV 做这件事没有问题(使用opencv4nodejs):
# load image
_cvImg = cv.imread _file
# get grayscale image
_cvImgGray =_cvImg.bgrToGray()
# Compute laplacian
_laplacian = _cvImgGray.laplacian(cv.CV_8U)
# Get the standard deviation
_meanStdDev = _laplacian.meanStdDev()
_stddevarray = _meanStdDev.stddev.getDataAsArray()
_stdDeviation = _stddevarray[0]
# Get the variation
_variation = Math.pow(_stdDeviation, 2)
Run Code Online (Sandbox Code Playgroud)
但现在,我正在使用 Tensorflow.js,它确实不太容易......这是我尝试做的:
# load image
_cvImg = cv.imread _file
#convert frame to a tensor
try
_data = new Uint8Array(_frame.cvtColor(cv.COLOR_BGR2RGB).getData().buffer)
_tensorFrame = tfjs.tensor3d(_data, [_frame.rows, _frame.cols, 3])
catch _err
@log.error "Error …Run Code Online (Sandbox Code Playgroud)