我正在实施哈里斯角检测并出现溢出错误:
harris.py:27: RuntimeWarning: overflow encountered in ubyte_scalars
Mat[0][1]=Ix[i][j]*Iy[i][j]
harris.py:28: RuntimeWarning: overflow encountered in ubyte_scalars
Mat[1][0]=Ix[i][j]*Iy[i][j]
这是整个源代码。错误来自哪里?因为 Ix.max 为 255,min 为 0。
import cv2
import numpy as np
im=cv2.imread('image.png', cv2.CV_LOAD_IMAGE_GRAYSCALE)
(M,N)=im.shape
print M
print N
Gx=np.array([[1, 0, -1],[ 2, 0, -2], [1, 0, -1]])
Gy=np.array([[1, 2, 1],[0, 0, 0],[-1, -2, -1]])
Ix=cv2.filter2D(im, -1, Gx)
Iy=cv2.filter2D(im, -1, Gy)
print np.max(Ix)
print np.min(Ix)
print np.max(Iy)
print np.min(Iy)
Mat=np.zeros((2,2), dtype='float64')
R=np.zeros((M,N), dtype='float64')
for i in range(M):
for j in range(N):
Mat[0][0]=Ix[i][j]**2
Mat[0][1]=Ix[i][j]*Iy[i][j]
Mat[1][0]=Ix[i][j]*Iy[i][j]
Mat[1][1]=Iy[i][j]**2
R[i][j]=np.linalg.det(Mat)-(np.matrix.trace(Mat))**2
cv2.imshow("Ix",Ix)
cv2.imshow("Iy",Iy)
cv2.imshow("R",R)
cv2.waitKey(0)