我正在尝试实现这个版本的定向梯度直方图(HOG)。我的代码如下。我的代码中唯一的区别是我曾经opencv
读取图像并将其转换为灰度。
import cv2
import matplotlib.pyplot as plt
from skimage.feature import hog
from skimage import data, color, exposure
filename = 'match1/hockey15.jpg'
im = cv2.imread(filename)
gr = cv2.cvtColor(im, cv2.COLOR_BGR2GRAY)
print im.shape
image = gr
fd, hog_image = hog(image, orientations=8, pixels_per_cell=(16, 16),
cells_per_block=(1, 1), visualise=True)
fig, (ax1, ax2) = plt.subplots(1, 2, figsize=(8, 4), sharex=True, sharey=True)
ax1.axis('off')
ax1.imshow(image, cmap=plt.cm.gray)
ax1.set_title('Input image')
ax1.set_adjustable('box-forced')
# Rescale histogram for better display
hog_image_rescaled = exposure.rescale_intensity(hog_image, in_range=(0, 0.02))
ax2.axis('off')
ax2.imshow(hog_image_rescaled, cmap=plt.cm.gray)
ax2.set_title('Histogram of Oriented Gradients') …
Run Code Online (Sandbox Code Playgroud) python image-processing scikit-image histogram-of-oriented-gradients
我正在尝试使用 SVM-HOG 管道在 python 中使用 OpenCV 进行行人检测。
\n我有很多不同尺寸的图像,有些很小(例如21\xc3\x9732),有些较大(例如127\xc3\x97264)。
\n我首先将我的 HOG 描述符定义为hog = cv2.HOGDescriptor()
\n当我通过调用计算 HOG 特征时,h = hog.compute(image)
我发现当图像小于 64*128 时,描述符将无法计算特征,相反,它只是终止程序。
原始论文使用了 64*128 大小的图像,但我认为它还指出可以使用具有相同长宽比(1:2)的图像(如果我错了,请纠正我)。
\n我的问题是 64*128 是 HOG 描述符可以计算特征的最小尺寸吗?因为我尝试在调整为 32*64 的图像上计算 HOG 特征,但它不起作用。
\n\nfor entries in os.listdir(dir_path):\n if entries.endswith(".jpg"):\n img = cv2.imread(os.path.join(test_path, entries))\n rects, scores = hog.detectMultiScale(img, winStride=(4,4), padding=(8,8), scale=1.05)\n sc = [score[0] for score in scores]\n for i in range(len(rects)):\n r = rects[i]\n rects[i][2] = r[0]+r[2]\n rects[i][3] = r[1]+r[3]\n pick …
Run Code Online (Sandbox Code Playgroud)