def test_copyToNpArray(self): floatVec = hogc.makeTestFloatVec() npFloatVec = np.zeros((len(floatVec)+2), dtype=np.float32) hogc.copyToNpArray(floatVec, 2, npFloatVec) for i in range(0, len(floatVec)): self.assertTrue(almostEqual(npFloatVec[i+2], floatVec[i])) pass pass
def hog(img, hogScheme, aHistTemplate, smAngle, smMag, descriptor): #print img.width, img.height imgCopy = cv2.resize(img, (128, 64)) numpyImg = np.asarray(imgCopy) hogc.gammaCorrect(numpyImg, 2.2, True) #normalizedImg = normalizeImage(numpyImg) convertedImg = cv2.cvtColor( numpyImg, cv2.COLOR_BGR2GRAY) h = convertedImg.shape[0] w = convertedImg.shape[1] assert(descriptor.shape[0] == hogScheme.numBlocksVertical * hogScheme.numBlocksHorizontal * hogScheme.numCellsInUnitPerSide * hogScheme.numCellsInUnitPerSide * 9) assert(descriptor.dtype == np.float32) hog = hogc.Hog(hogScheme, hogc.Hog.BlockGaussianWeightingPolicy.YesGaussian, hogc.Hog.BlockNormalizationPolicy.L2Normalization) for r in range(0, hogScheme.numBlocksVertical): for c in range(0, hogScheme.numBlocksHorizontal): histVec = hogc.FloatVec() hog.computeBlock( convertedImg,aHistTemplate, r, c, smAngle, smMag, False, histVec) hogc.copyToNpArray(histVec, (r*15 +c)*36, descriptor) return