Python、OpenCV 3.1、HOGを使用した有用な検出に問題があります。私はエラーなしで実行する作業コードを持っていますが、訓練されたHOG/SVMの組み合わせはテストイメージで検出できません。OpenCVを使用したPythonでのHOGトレーニングと検出
OpenCVの例と他のスタックオーバーフローの議論から私は以下のアプローチを開発しました。すべての試験において
win_size = (64, 64)
block_size = (16, 16)
block_stride = (8, 8)
cell_size = (8, 8)
nbins = 9
deriv_aperture = 1
win_sigma = 4.
histogram_norm_type = 0
l2_hys_threshold = 2.0000000000000001e-01
gamma_correction = 0
nlevels = 64
hog = cv2.HOGDescriptor(win_size,
block_size,
block_stride,
cell_size,
nbins,
deriv_aperture,
win_sigma,
histogram_norm_type,
l2_hys_threshold,
gamma_correction,
nlevels)
window_stride = (8, 8)
padding = (8, 8)
locations = ((0, 0),)
histograms = []
# not showing the loop here but
# create histograms for 600 positive and 600 negative images
# all images are of size 64x64
histograms.append(np.transpose(hog.compute(roi, window_stride, padding, locations)))
training_data = np.concatenate(histograms)
classifications = np.array([1] * 600 + [0] * 600)
svm = cv2.ml.SVM_create()
svm.setType(cv2.ml.SVM_C_SVC)
svm.setKernel(cv2.ml.SVM_LINEAR)
svm.setC(0.01)
svm.setTermCriteria((cv2.TermCriteria_MAX_ITER, 100, 1e-6))
svm.train(training_data, cv2.ml.ROW_SAMPLE, classifications)
# testing
test_img = cv2.imread('test_image.jpg')
svmvec = svm.getSupportVectors()[0]
rho = -svm.getDecisionFunction(0)[0]
svmvec = np.append(svmvec, rho)
hog.setSVMDetector(svmvec)
found, w = hog.detectMultiScale(test_img)
、found
は画像の中心に単一の矩形であり、正のテスト画像のどこにあるかに配置されていません。
Stack Overflowの回答と他のOpenCVのサンプルとディスカッションに基づいて、さまざまな組み合わせのパラメータを試しました。彼らの誰も結果を変更しません。
問題の詳細でよく組織された説明は報われるべきです。 ** svm.getSupportVectors()[0] **のみを使用する理由を尋ねることができますか? – 3yanlis1bos