Normalize line endings and whitespace

This commit is contained in:
OpenCV Buildbot
2012-10-17 11:12:04 +04:00
committed by Andrey Kamaev
parent 0442bca235
commit 81f826db2b
1511 changed files with 258678 additions and 258624 deletions

28
samples/python2/facerec_demo.py Normal file → Executable file
View File

@@ -41,7 +41,7 @@ def normalize(X, low, high, dtype=None):
"""Normalizes a given array in X to a value between low and high."""
X = np.asarray(X)
minX, maxX = np.min(X), np.max(X)
# normalize to [0...1].
# normalize to [0...1].
X = X - float(minX)
X = X / float((maxX - minX))
# scale to [low...high].
@@ -54,14 +54,14 @@ def normalize(X, low, high, dtype=None):
def read_images(path, sz=None):
"""Reads the images in a given folder, resizes images on the fly if size is given.
Args:
path: Path to a folder with subfolders representing the subjects (persons).
sz: A tuple with the size Resizes
sz: A tuple with the size Resizes
Returns:
A list [X,y]
X: The images, which is a Python list of numpy arrays.
y: The corresponding labels (the unique number of the subject, person) in a Python list.
"""
@@ -85,7 +85,7 @@ def read_images(path, sz=None):
raise
c = c+1
return [X,y]
if __name__ == "__main__":
# This is where we write the images, if an output_dir is given
# in command line:
@@ -99,7 +99,7 @@ if __name__ == "__main__":
# Now read in the image data. This must be a valid path!
[X,y] = read_images(sys.argv[1])
# Convert labels to 32bit integers. This is a workaround for 64bit machines,
# because the labels will truncated else. This will be fixed in code as
# because the labels will truncated else. This will be fixed in code as
# soon as possible, so Python users don't need to know about this.
# Thanks to Leo Dirac for reporting:
y = np.asarray(y, dtype=np.int32)
@@ -115,10 +115,10 @@ if __name__ == "__main__":
# so we use np.asarray to turn them into NumPy lists to make
# the OpenCV wrapper happy:
model.train(np.asarray(X), np.asarray(y))
# We now get a prediction from the model! In reality you
# should always use unseen images for testing your model.
# But so many people were confused, when I sliced an image
# off in the C++ version, so I am just using an image we
# We now get a prediction from the model! In reality you
# should always use unseen images for testing your model.
# But so many people were confused, when I sliced an image
# off in the C++ version, so I am just using an image we
# have trained with.
#
# model.predict is going to return the predicted label and
@@ -126,7 +126,7 @@ if __name__ == "__main__":
[p_label, p_confidence] = model.predict(np.asarray(X[0]))
# Print it:
print "Predicted label = %d (confidence=%.2f)" % (p_label, p_confidence)
# Cool! Finally we'll plot the Eigenfaces, because that's
# Cool! Finally we'll plot the Eigenfaces, because that's
# what most people read in the papers are keen to see.
#
# Just like in C++ you have access to all model internal
@@ -144,9 +144,9 @@ if __name__ == "__main__":
cv2.imshow("mean", mean_resized)
else:
cv2.imwrite("%s/mean.png" % (out_dir), mean_resized)
# Turn the first (at most) 16 eigenvectors into grayscale
# Turn the first (at most) 16 eigenvectors into grayscale
# images. You could also use cv::normalize here, but sticking
# to NumPy is much easier for now.
# to NumPy is much easier for now.
# Note: eigenvectors are stored by column:
for i in xrange(min(len(X), 16)):
eigenvector_i = eigenvectors[:,i].reshape(X[0].shape)