confuse = zeros((n, n)) for i in range(len(test_labels)): confuse[class_ind[res[i]], class_ind[test_labels[i]]] += 1 print('Confusion matrix for') print(classnames) print(confuse) filelist_train = get_imagelist('../data/gesture/train') filelist_test = get_imagelist('../data/gesture/test') imlist = filelist_train + filelist_test # process images at fixed size (50,50) for filename in imlist: featfile = filename[:-3] + 'dsift' dsift.process_image_dsift(filename, featfile, 10, 5, resize=(50, 50)) features, labels = read_gesture_features_labels('../data/gesture/train/') test_features, test_labels = read_gesture_features_labels('../data/gesture/test/') classnames = unique(labels) # test kNN k = 1 knn_classifier = knn.KnnClassifier(labels, features) res = array([knn_classifier.classify(test_features[i], k) for i in range(len(test_labels))]) # accuracy acc = sum(1.0 * (res == test_labels)) / len(test_labels) print('Accuracy:', acc) print_confusion(res, test_labels, classnames)
# -*- coding: utf-8 -*- from PCV.localdescriptors import sift, dsift from pylab import * from PIL import Image dsift.process_image_dsift('../data/empire.jpg','empire.dsift',90,40,True) l,d = sift.read_features_from_file('empire.dsift') im = array(Image.open('../data/empire.jpg')) sift.plot_features(im,l,True) title('dense SIFT') show()
# -*- coding: utf-8 -*- from PCV.localdescriptors import sift, dsift from pylab import * from PIL import Image dsift.process_image_dsift('gesture/empire.jpg', 'empire.dsift', 90, 40, True) l, d = sift.read_features_from_file('empire.dsift') im = array(Image.open('gesture/empire.jpg')) sift.plot_features(im, l, True) title('dense SIFT') show()
# -*- coding: utf-8 -*- import os from PCV.localdescriptors import sift, dsift from pylab import * from PIL import Image imlist = [ '../data/gesture/train/A-uniform01.ppm', '../data/gesture/train/B-uniform01.ppm', '../data/gesture/train/C-uniform01.ppm', '../data/gesture/train/Five-uniform01.ppm', '../data/gesture/train/Point-uniform01.ppm', '../data/gesture/train/V-uniform01.ppm' ] figure() for i, im in enumerate(imlist): dsift.process_image_dsift(im, im[:-3] + '.dsift', 90, 40, True) l, d = sift.read_features_from_file(im[:-3] + 'dsift') dirpath, filename = os.path.split(im) im = array(Image.open(im)) #显示手势含义title titlename = filename[:-14] subplot(2, 3, i + 1) sift.plot_features(im, l, True) title(titlename) show()
from PIL import Image from pylab import * from numpy import * from PCV.localdescriptors import dsift, sift """ This is the dense SIFT illustration, it will reproduce the plot in Figure 8-2. """ dsift.process_image_dsift('../data/empire.jpg', 'empire.sift', 90, 40, True) l, d = sift.read_features_from_file('empire.sift') im = array(Image.open('../data/empire.jpg')) sift.plot_features(im, l, True) show()
class_ind = dict([(classnames[i],i) for i in range(n)]) confuse = zeros((n,n)) for i in range(len(test_labels)): confuse[class_ind[res[i]],class_ind[test_labels[i]]] += 1 print 'Confusion matrix for' print classnames print confuse filelist_train = get_imagelist('../data/gesture/train') filelist_test = get_imagelist('../data/gesture/test') imlist=filelist_train+filelist_test # process images at fixed size (50,50) for filename in imlist: featfile = filename[:-3]+'dsift' dsift.process_image_dsift(filename,featfile,10,5,resize=(50,50)) features,labels = read_gesture_features_labels('../data/gesture/train/') test_features,test_labels = read_gesture_features_labels('../data/gesture/test/') classnames = unique(labels) # test kNN k = 1 knn_classifier = knn.KnnClassifier(labels,features) res = array([knn_classifier.classify(test_features[i],k) for i in range(len(test_labels))]) # accuracy acc = sum(1.0*(res==test_labels)) / len(test_labels) print 'Accuracy:', acc print_confusion(res,test_labels,classnames)
# -*- coding: utf-8 -*- from PCV.localdescriptors import sift, dsift from pylab import * from PIL import Image dsift.process_image_dsift('../data/empire.jpg', 'empire.dsift', 90, 40, True) l, d = sift.read_features_from_file('empire.dsift') im = array(Image.open('../data/empire.jpg')) sift.plot_features(im, l, True) title('dense SIFT') show()
# -*- coding: utf-8 -*- import os from PCV.localdescriptors import sift, dsift from pylab import * from PIL import Image imlist = [ 'gesture/image2/B-uniform01.jpg', 'gesture/image2/F-uniform01.jpg', 'gesture/image2/G-uniform01.jpg', 'gesture/image2/L-uniform01.jpg', 'gesture/image2/O-uniform01.jpg', 'gesture/image2/V-uniform01.jpg' ] figure() for i, im in enumerate(imlist): print(im) dsift.process_image_dsift(im, im[:-3] + 'dsift', 10, 5, True) l, d = sift.read_features_from_file(im[:-3] + 'dsift') dirpath, filename = os.path.split(im) im = array(Image.open(im)) #显示手势含义title titlename = filename[:-14] subplot(2, 3, i + 1) sift.plot_features(im, l, True) title(titlename) show()
from PIL import Image from pylab import * from numpy import * from PCV.localdescriptors import dsift, sift """ This is the dense SIFT illustration, it will reproduce the plot in Figure 8-2. """ dsift.process_image_dsift('../data/empire.jpg', 'empire.sift', 90, 40, True) l,d = sift.read_features_from_file('empire.sift') im = array(Image.open('../data/empire.jpg')) sift.plot_features(im, l, True) show()
# -*- coding: utf-8 -*- import os from PCV.localdescriptors import sift, dsift from pylab import * from PIL import Image imlist=['../data/gesture/train/A-uniform01.ppm','../data/gesture/train/B-uniform01.ppm', '../data/gesture/train/C-uniform01.ppm','../data/gesture/train/Five-uniform01.ppm', '../data/gesture/train/Point-uniform01.ppm','../data/gesture/train/V-uniform01.ppm'] figure() for i, im in enumerate(imlist): dsift.process_image_dsift(im,im[:-3]+'.dsift',90,40,True) l,d = sift.read_features_from_file(im[:-3]+'dsift') dirpath, filename=os.path.split(im) im = array(Image.open(im)) #显示手势含义title titlename=filename[:-14] subplot(2,3,i+1) sift.plot_features(im,l,True) title(titlename) show()