Created
May 28, 2015 15:29
-
-
Save samos123/885f9fe87c8fa5abf78f to your computer and use it in GitHub Desktop.
spark-extract-sift-features.py
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
from __future__ import print_function | |
import sys | |
import os | |
import cv2 | |
import numpy as np | |
def extract_sift_features_opencv(imgfile_imgbytes): | |
imgfilename, imgbytes = imgfile_imgbytes | |
nparr = np.fromstring(buffer(imgbytes), np.uint8) | |
img = cv2.imdecode(nparr, 1) | |
gray = cv2.cvtColor(img,cv2.COLOR_BGR2GRAY) | |
sift = cv2.xfeatures2d.SIFT_create() | |
kp, descriptors = sift.detectAndCompute(gray, None) | |
# with open("/tmp/test-sam", 'w') as f: | |
# f.write("%s : %s" % (imgfilename, descriptors), file=f) | |
return (imgfilename, descriptors) | |
if __name__ == "__main__": | |
from pyspark import SparkContext | |
sc = SparkContext(appName="feature_extractor") | |
seqFilePath = sys.argv[1] | |
images = sc.sequenceFile(seqFilePath) | |
images_sift = images.map(extract_sift_features_opencv) | |
test = images_sift.collectAsMap() | |
print(test.keys()) | |
print("done") | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment