各位,能帮我看一下这个报错怎么解决吗?
错误如下:
Traceback (most recent call last):
File "F:\imageprocessingproject\tuxiangchuli\改进zernike.py", line 36, in <module>
cv2.imwrite("C:/Users/LYX/Desktop/tuxiangchuli/zer-da.jpg", result1)
cv2.error: OpenCV(4.7.0) :-1: error: (-5:Bad argument) in function 'imwrite'
> Overload resolution failed:
> - img is not a numerical tuple
> - Expected Ptr<cv::UMat> for argument 'img'
代码如下:
import cv2
import numpy as np
# Load image
img = cv2.imread("C:/Users/LYX\Desktop/tuxiangchuli/gary-da.jpg", 0)
# Compute Zernike moments
moments = cv2.moments(img)
cx = int(moments['m10']/moments['m00'])
cy = int(moments['m01']/moments['m00'])
M20 = moments['m20']/moments['m00']
M02 = moments['m02']/moments['m00']
M11 = moments['m11']/moments['m00']
# Compute Laplacian of Gaussian
laplacian = cv2.Laplacian(img, -1)
# Compute Zernike-Laplacian
zernike_laplacian = cv2.filter2D(laplacian, -1, cv2.getGaussianKernel(5, 1.5), cv2.BORDER_REPLICATE)
# Apply mask to zero out negative values
mask = np.zeros_like(zernike_laplacian)
mask[zernike_laplacian >= 0] = 1
# Apply mask to input image
result = cv2.bitwise_and(img, img, mask=mask)
# Apply adaptive thresholding
threshold_type = cv2.THRESH_BINARY + cv2.THRESH_OTSU
threshold_level =0.1
result1 = cv2.threshold(result, threshold_level, 255, threshold_type)
# Save result
cv2.imwrite("C:/Users/LYX/Desktop/tuxiangchuli/zer-da.jpg", result1)