Mercurial Hosting > traffic-intelligence
comparison python/cvutils.py @ 893:ff92801e5c54
updated hog to scikit-image 0.13 (needed to add a block_norm attribute in classifier.cfg)
author | Nicolas Saunier <nicolas.saunier@polymtl.ca> |
---|---|
date | Tue, 30 May 2017 16:10:18 -0400 |
parents | 1fdafa9f6bf4 |
children | 0c1fed9e8862 |
comparison
equal
deleted
inserted
replaced
892:f766fe0995f4 | 893:ff92801e5c54 |
---|---|
603 | 603 |
604 if skimageAvailable: | 604 if skimageAvailable: |
605 from skimage.feature import hog | 605 from skimage.feature import hog |
606 from skimage import color, transform | 606 from skimage import color, transform |
607 | 607 |
608 def HOG(image, rescaleSize = (64, 64), orientations=9, pixelsPerCell=(8, 8), cellsPerBlock=(2, 2), visualize=False, normalize=False): | 608 def HOG(image, rescaleSize = (64, 64), orientations=9, pixelsPerCell=(8,8), cellsPerBlock=(2,2), blockNorm='L1', visualize=False, normalize=False): |
609 bwImg = color.rgb2gray(image) | 609 bwImg = color.rgb2gray(image) |
610 inputImg = transform.resize(bwImg, rescaleSize) | 610 inputImg = transform.resize(bwImg, rescaleSize) |
611 features = hog(inputImg, orientations, pixelsPerCell, cellsPerBlock, visualize, normalize) | 611 features = hog(inputImg, orientations, pixelsPerCell, cellsPerBlock, blockNorm, visualize, normalize) |
612 if visualize: | 612 if visualize: |
613 from matplotlib.pyplot import imshow, figure, subplot | 613 from matplotlib.pyplot import imshow, figure, subplot |
614 hogViz = features[1] | 614 hogViz = features[1] |
615 features = features[0] | 615 features = features[0] |
616 figure() | 616 figure() |
618 imshow(inputImg) | 618 imshow(inputImg) |
619 subplot(1,2,2) | 619 subplot(1,2,2) |
620 imshow(hogViz) | 620 imshow(hogViz) |
621 return float32(features) | 621 return float32(features) |
622 | 622 |
623 def createHOGTrainingSet(imageDirectory, classLabel, rescaleSize = (64, 64), orientations=9, pixelsPerCell=(8, 8), cellsPerBlock=(2, 2), visualize=False, normalize=False): | 623 def createHOGTrainingSet(imageDirectory, classLabel, rescaleSize = (64,64), orientations=9, pixelsPerCell=(8,8), blockNorm='L1', cellsPerBlock=(2, 2), visualize=False, normalize=False): |
624 inputData = [] | 624 inputData = [] |
625 for filename in listdir(imageDirectory): | 625 for filename in listdir(imageDirectory): |
626 img = imread(imageDirectory+filename) | 626 img = imread(imageDirectory+filename) |
627 features = HOG(img, rescaleSize, orientations, pixelsPerCell, cellsPerBlock, visualize, normalize) | 627 features = HOG(img, rescaleSize, orientations, pixelsPerCell, cellsPerBlock, blockNorm, visualize, normalize) |
628 inputData.append(features) | 628 inputData.append(features) |
629 | 629 |
630 nImages = len(inputData) | 630 nImages = len(inputData) |
631 return array(inputData, dtype = float32), array([classLabel]*nImages) | 631 return array(inputData, dtype = float32), array([classLabel]*nImages) |
632 | 632 |