Skip to content

Instantly share code, notes, and snippets.

@samos123
Created May 28, 2015 15:29
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save samos123/885f9fe87c8fa5abf78f to your computer and use it in GitHub Desktop.
Save samos123/885f9fe87c8fa5abf78f to your computer and use it in GitHub Desktop.
spark-extract-sift-features.py
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