mirror of
https://github.com/opencv/opencv.git
synced 2024-11-28 13:10:12 +08:00
Merge pull request #10663 from jmlich:master
* hogsvm compatibility with python3
This commit is contained in:
parent
b97b650ab3
commit
7a472d85ef
12
samples/python/tutorial_code/ml/py_svm_opencv/hogsvm.py
Normal file → Executable file
12
samples/python/tutorial_code/ml/py_svm_opencv/hogsvm.py
Normal file → Executable file
@ -1,3 +1,5 @@
|
||||
#!/usr/bin/env python
|
||||
|
||||
import cv2 as cv
|
||||
import numpy as np
|
||||
|
||||
@ -44,8 +46,8 @@ test_cells = [ i[50:] for i in cells]
|
||||
|
||||
###### Now training ########################
|
||||
|
||||
deskewed = [map(deskew,row) for row in train_cells]
|
||||
hogdata = [map(hog,row) for row in deskewed]
|
||||
deskewed = [list(map(deskew,row)) for row in train_cells]
|
||||
hogdata = [list(map(hog,row)) for row in deskewed]
|
||||
trainData = np.float32(hogdata).reshape(-1,64)
|
||||
responses = np.repeat(np.arange(10),250)[:,np.newaxis]
|
||||
|
||||
@ -60,12 +62,12 @@ svm.save('svm_data.dat')
|
||||
|
||||
###### Now testing ########################
|
||||
|
||||
deskewed = [map(deskew,row) for row in test_cells]
|
||||
hogdata = [map(hog,row) for row in deskewed]
|
||||
deskewed = [list(map(deskew,row)) for row in test_cells]
|
||||
hogdata = [list(map(hog,row)) for row in deskewed]
|
||||
testData = np.float32(hogdata).reshape(-1,bin_n*4)
|
||||
result = svm.predict(testData)[1]
|
||||
|
||||
####### Check Accuracy ########################
|
||||
mask = result==responses
|
||||
correct = np.count_nonzero(mask)
|
||||
print correct*100.0/result.size
|
||||
print(correct*100.0/result.size)
|
||||
|
Loading…
Reference in New Issue
Block a user