Commit 7a472d85 authored by Jozef Mlich's avatar Jozef Mlich Committed by Alexander Alekhin

Merge pull request #10663 from jmlich:master

* hogsvm compatibility with python3
parent b97b650a
#!/usr/bin/env python
import cv2 as cv import cv2 as cv
import numpy as np import numpy as np
...@@ -44,8 +46,8 @@ test_cells = [ i[50:] for i in cells] ...@@ -44,8 +46,8 @@ test_cells = [ i[50:] for i in cells]
###### Now training ######################## ###### Now training ########################
deskewed = [map(deskew,row) for row in train_cells] deskewed = [list(map(deskew,row)) for row in train_cells]
hogdata = [map(hog,row) for row in deskewed] hogdata = [list(map(hog,row)) for row in deskewed]
trainData = np.float32(hogdata).reshape(-1,64) trainData = np.float32(hogdata).reshape(-1,64)
responses = np.repeat(np.arange(10),250)[:,np.newaxis] responses = np.repeat(np.arange(10),250)[:,np.newaxis]
...@@ -60,12 +62,12 @@ svm.save('svm_data.dat') ...@@ -60,12 +62,12 @@ svm.save('svm_data.dat')
###### Now testing ######################## ###### Now testing ########################
deskewed = [map(deskew,row) for row in test_cells] deskewed = [list(map(deskew,row)) for row in test_cells]
hogdata = [map(hog,row) for row in deskewed] hogdata = [list(map(hog,row)) for row in deskewed]
testData = np.float32(hogdata).reshape(-1,bin_n*4) testData = np.float32(hogdata).reshape(-1,bin_n*4)
result = svm.predict(testData)[1] result = svm.predict(testData)[1]
####### Check Accuracy ######################## ####### Check Accuracy ########################
mask = result==responses mask = result==responses
correct = np.count_nonzero(mask) correct = np.count_nonzero(mask)
print correct*100.0/result.size print(correct*100.0/result.size)
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment