Mercurial Hosting > traffic-intelligence
comparison python/cvutils.py @ 959:4f32d82ca390
corrected error due to change in Hog (scikit image)
author | Nicolas Saunier <nicolas.saunier@polymtl.ca> |
---|---|
date | Thu, 24 Aug 2017 17:22:24 -0400 |
parents | 747a5c68bd3c |
children | 373e8ef6ee25 |
comparison
equal
deleted
inserted
replaced
958:747a5c68bd3c | 959:4f32d82ca390 |
---|---|
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), blockNorm='L1', visualize=False, normalize=False): | 608 def HOG(image, rescaleSize = (64, 64), orientations = 9, pixelsPerCell = (8,8), cellsPerBlock = (2,2), blockNorm = 'L1', visualize = False, transformSqrt = 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, blockNorm, visualize, normalize, True) | 611 features = hog(inputImg, orientations, pixelsPerCell, cellsPerBlock, blockNorm, visualize, transformSqrt, True) |
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), blockNorm='L1', 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, transformSqrt = 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, blockNorm, visualize, normalize) | 627 features = HOG(img, rescaleSize, orientations, pixelsPerCell, cellsPerBlock, blockNorm, visualize, transformSqrt) |
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 |