-
-
Notifications
You must be signed in to change notification settings - Fork 56.5k
modifiedLaplacian Same code working in C++ ... not working in Python #16807
Copy link
Copy link
Closed
Labels
question (invalid tracker)ask questions and other "no action" items here: https://forum.opencv.orgask questions and other "no action" items here: https://forum.opencv.org
Description
opencv-python 4.2.0.32
import cv2
import glob
import numpy as np
def modifiedLaplacian(img):
''''LAPM' algorithm (Nayar89)'''
M = np.array([-1, 2, -1])
G = cv2.getGaussianKernel(ksize=3, sigma=-1)
Lx = cv2.sepFilter2D(src=img, ddepth=cv2.CV_64F, kernelX=M, kernelY=G)
Ly = cv2.sepFilter2D(src=img, ddepth=cv2.CV_64F, kernelX=G, kernelY=M)
FM = np.abs(Lx) + np.abs(Ly)
return cv2.mean(FM)[0]
mylist = glob.glob("/home/ashutosh/Desktop/blur_dataset/images/*.jpg")
for item in mylist:
crop_img = cv2.imread(item)
lm = modifiedLaplacian(crop_img)
print(item+"========"+str(lm))
Output
Traceback (most recent call last):
File "is_blur.py", line 17, in <module>
lm = modifiedLaplacian(crop_img)
File "is_blur.py", line 9, in modifiedLaplacian
Lx = cv2.sepFilter2D(src=img, ddepth=cv2.CV_64F, kernelX=M, kernelY=G)
cv2.error: OpenCV(4.2.0) /io/opencv/modules/imgproc/src/filter.dispatch.cpp:1450: error: (-215:Assertion failed) kernelX.type() == kernelY.type() && (kernelX.cols == 1 || kernelX.rows == 1) && (kernelY.cols == 1 || kernelY.rows == 1) in function 'sepFilter2D'
opencv-c++ | latest github
double modifiedLaplacian(const cv::Mat& src)
{
cv::Mat M = (cv::Mat_<double>(3, 1) << -1, 2, -1);
cv::Mat G = cv::getGaussianKernel(3, -1, CV_64F);
cv::Mat Lx;
cv::sepFilter2D(src, Lx, CV_64F, M, G);
cv::Mat Ly;
cv::sepFilter2D(src, Ly, CV_64F, G, M);
cv::Mat FM = cv::abs(Lx) + cv::abs(Ly);
double focusMeasure = cv::mean(FM).val[0];
return focusMeasure;
}
This is working fine !
Reactions are currently unavailable
Metadata
Metadata
Assignees
Labels
question (invalid tracker)ask questions and other "no action" items here: https://forum.opencv.orgask questions and other "no action" items here: https://forum.opencv.org