【发布时间】:2018-04-28 15:24:15
【问题描述】:
嗨,我在 python 中运行这个模糊检测代码(来源:https://www.pyimagesearch.com/2015/09/07/blur-detection-with-opencv/)
# import the necessary packages
from imutils import paths
import argparse
import cv2
def variance_of_laplacian(image):
# compute the Laplacian of the image and then return the focus
# measure, which is simply the variance of the Laplacian
return cv2.Laplacian(image, cv2.CV_64F).var()
# loop over the input images
for imagePath in paths.list_images("images/"):
# load the image, convert it to grayscale, and compute the
# focus measure of the image using the Variance of Laplacian
# method
image = cv2.imread(imagePath)
gray = cv2.cvtColor(image, cv2.COLOR_BGR2GRAY)
fm = variance_of_laplacian(gray)
text = "Not Blurry"
# if the focus measure is less than the supplied threshold,
# then the image should be considered "blurry"
if fm < 100:
text = "Blurry"
# show the image
cv2.putText(image, "{}: {:.2f}".format(text, fm), (10, 30),
cv2.FONT_HERSHEY_SIMPLEX, 0.8, (0, 0, 255), 3)
cv2.imshow("Image", image)
print("{}: {:.2f}".format(text, fm))
key = cv2.waitKey(0)
使用这个 2173 x 3161 的输入文件 input image
这是输出显示 the output image 图片已放大,未完整显示。
在源代码中,他们使用 450 x 600 px 的输入图像: input in source code 这是输出: output in source code
我认为图像的像素会影响输出。那么,我怎样才能得到像源代码中的输出一样的输出到所有图像? 我必须调整输入图像的大小吗?如何?但如果我这样做我怕会影响他的模糊效果
【问题讨论】:
-
你试过
cv2.resize()吗?您可以使用它来显示输出图像的外观。cv2.resize(image, (0,0), fx=0.5, fy=0.5) -
为什么不直接创建一个带有
WINDOW_NORMAL标志的namedWindow? (docs) 然后你会得到一个可调整大小的窗口,它可以缩放图像以适应它。添加WINDOW_KEEPRATIO进行缩放以保留图像的纵横比。 -
如何实现?
-
@DanMa 的意思是在
cv2.imshow("Image", image)之前使用cv2.namedWindow("Image", cv2.WINDOW_NORMAL)。使用它,您将能够随意调整输出窗口的大小。
标签: python opencv image-processing spyder imshow