cv2.eigen(hessian)

cv2.eigen(hessian)

ret,eigenVal,eigenVec= cv2.eigen(hessian)
返回值ret表示矩阵是否存在特征值,,eigenVal表示特征值, eigenVec表示特征向量

例子

import cv2
import os
img = cv2.imread("./1.png")
gray_origin = cv2.cvtColor(img, cv2.COLOR_BGR2GRAY)
gray = cv2.GaussianBlur(gray_origin, (5, 5), 0)
Ix = cv2.Scharr(gray, cv2.CV_32F, 1, 0,)
Iy = cv2.Scharr(gray, cv2.CV_32F, 0, 1)
Ixx = cv2.Scharr(Ix, cv2.CV_32F, 1, 0)
Ixy = cv2.Scharr(Ix, cv2.CV_32F, 0, 1)
Iyy = cv2.Scharr(Iy, cv2.CV_32F, 0, 1)
Iyx = cv2.Scharr(Iy, cv2.CV_32F, 1, 0)
# Hessian矩阵
row = gray_origin.shape[0]
col = gray_origin.shape[1]
for i in range(col):
    for j in range(row):
        if gray_origin[j, i] > 200:
            hessian = np.zeros((2, 2), np.float32)
            hessian[0, 0] = Ixx[j, i]
            hessian[0, 1] = Ixy[j, i]
            hessian[1, 0] = Iyx[j, i]
            hessian[1, 1] = Iyy[j, i]
            ret, eigenVal, eigenVec = cv2.eigen(hessian) # 返回特征值/特征向量
            print(cv2.eigen(hessian))

结果

(True, array([[ -6061.65],
       [-15946.35]], dtype=float32), array([[-0.55642134,  0.83090025],
       [ 0.83090025,  0.55642134]], dtype=float32))
(True, array([[-10306.799],
       [-17689.201]], dtype=float32), array([[-0.44061038,  0.89769846],
       [ 0.89769846,  0.44061038]], dtype=float32))
(True, array([[ -8120.189],
       [-14191.811]], dtype=float32), array([[-0.40943143,  0.9123409 ],
       [ 0.9123409 ,  0.40943143]], dtype=float32))
(True, array([[-14783.798],
       [-26528.203]], dtype=float32), array([[ 0.42065722,  0.9072196 ],
       [ 0.9072196 , -0.42065722]], dtype=float32))

你可能感兴趣的:(激光条纹中心提取,计算机视觉,opencv,c++)