使用 HOG 获取图像描述符但 hog.compute 总是返回 0.0 [英] Using HOG to get image descriptors but hog.compute always returns 0.0

查看:73
本文介绍了使用 HOG 获取图像描述符但 hog.compute 总是返回 0.0的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

64x64 图像尝试使用 OpenCV 在 Python 中做一些简单的事情.使用 HOG 获取特征向量.但我得到了所有 0.0.我已经尝试了一些图像相同的结果.

64x64 image Trying to use OpenCV to do something simple in Python. Using HOG to get the feature vector. But I get all 0.0. I've tried a few images same result.

import cv2
image = cv2.imread("D:\\skhan\\research\\data\\face\\test.jpg",cv2.IMREAD_COLOR)
image = cv2.cvtColor(image, cv2.COLOR_BGR2GRAY)
winSize = (64,64)
blockSize = (16,16)
blockStride = (8,8)
cellSize = (8,8)
nbins = 9
derivAperture = 1
winSigma = 4.0
histogramNormType = 0
L2HysThreshold = 2.0000000000000001e-01
gammaCorrection = 0
nlevels = 64
hog = cv2.HOGDescriptor(winSize,blockSize,blockStride,cellSize,nbins,derivAperture,winSigma,histogramNormType,L2HysThreshold,gammaCorrection,nlevels)
winStride = (8,8)
padding = (8,8)
locations = ((10,20),)
hist = hog.compute(image,winStride,padding,locations)

推荐答案

简单地使用 hist = hog.compute(image) 给出非零结果.

Simply using hist = hog.compute(image) gives a non-zero result.

默认winstride、padding、locations是空元组.但是,如果您坚持使用 winstride 等,那么您的图像是 64x64 并且您的窗口大小 (winsize) 是 64x64,添加一个 8x8 winstride不会导致图像上的窗口重叠,因此您的输出用零填充.

By default winstride, padding, locations are empty tuples. However, if you are firm on using winstride, etc your image is 64x64 and your window size (winsize) is 64x64, adding a 8x8 winstride will cause no overlapping of the window on the image, hence your output is filled with zeros.

澄清一下,winsize 是在整个图像上运行的滑动窗口的大小.由于图像和滑动窗口的大小相同,由于计算 HoG 特征的方式,将不会创建任何特征,这就是您看到零的原因.

To clarify, winsize is the size of the sliding window that is run across the entire image. Since the size of the image and the sliding window is the same, due to the manner in which HoG features are calculated, there will be no features created, which is why you're seeing zeros.

这篇关于使用 HOG 获取图像描述符但 hog.compute 总是返回 0.0的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆