我了解gabor内核的概念以及如何将其用于识别方向边缘。所以我想用它来识别图像中的条形码行。
但是,当我使用gabor内核过滤图像时,总是得到空白/黑色结果。您能否提供有关我需要做些什么的反馈,以使Gabor识别图像中的垂直线,即产生垂直边缘处具有白色的结果?
import cv2
import numpy as np
def deginrad(degree):
radiant = 2*np.pi/360 * degree
return radiant
def main():
src = cv2.imread('./images/barcode1.jpg', cv2.IMREAD_GRAYSCALE)
# Introduce consistency in width
const_width = 300
aspect = float(src.shape[0]) / float(src.shape[1])
src = cv2.resize(src, (const_width, int(const_width * aspect)))
src = cv2.GaussianBlur(src, (7,7), 0)
# Apply gabor kernel to identify vertical edges
g_kernel = cv2.getGaborKernel((9,9), 8, deginrad(0), 5, 0.5, 0, ktype=cv2.CV_32F)
gabor = cv2.filter2D(src, cv2.CV_8UC3, g_kernel)
# Visual the gabor kernel
h, w = g_kernel.shape[:2]
g_kernel = cv2.resize(g_kernel, (20*w, 20*h), interpolation=cv2.INTER_CUBIC)
cv2.imshow('src', src)
cv2.imshow('gabor', gabor) # gabor is just black
cv2.imshow('gabor kernel', g_kernel)
cv2.waitKey(0)
if __name__ == "__main__":
main()