# import the necessary packages
import os
import numpy as np
import cv2
from matplotlib import pyplot as plt

# MAIN FUNCTION OF SCRIPT: loads a set of photos and gets SIFT & SURF keypoints
# Photo Structure: [FILENAME,PHOTO,GRAYSCALE_PHOTO,KEYPOINTS_SIFT,KEYPOINTS_SURF]
def main():
	photos = loadimages()				# load photos from folder

	for photo in photos:
		findsiftfeatures(photo)			# find sift features and save keypoints
		findsurffeatures(photo)			# find surf features and save keypoints

# LOAD PHOTOS FROM FOLDER & SAVE IN A LIST [FILENAME,PHOTO,GRAYSCALE_PHOTO]
def loadimages():
	photos = [] 						# create "photos" list
	photosdir = "photos"				# set folder name ("photosdir")

	for filename in os.listdir(photosdir):
		image = cv2.imread(os.path.join(photosdir,filename))	#read photo
		gray = cv2.cvtColor(image,cv2.COLOR_BGR2GRAY)			#convert to grayscale
		photos.append([filename, image, gray])					#append in a list of photos

	return photos

# FIND SIFT FEATURES FOR A PHOTO
def findsiftfeatures(photo):
	sift = cv2.xfeatures2d.SIFT_create()
	(kps,sift) = sift.detectAndCompute(photo[2],None)
	photo.append(kps)

# FIND SURF FEATURES FOR A PHOTO
def findsurffeatures(photo):
	surf = cv2.xfeatures2d.SURF_create()
	(kps,surf) = surf.detectAndCompute(photo[2],None)
	photo.append(kps)

# SHOW IMAGE FILE
def showimage(image):
	cv2.imshow('image',image)
	cv2.waitKey(0)

main()



# *************************************************** NOTES ********************************************************

# SYSTEM
# * load virtual environment: source cv/bin/activate
# * mv ~/Desktop/Yelp/various/train_photos/IMAGEFILE ~/Desktop/Yelp/photos/

# PYTHON
# * Find length: len(DATATYPE)

# * List: Homogenous(contains same types)	!!THE MOST CONVENIENT AND FLEXIBLE !!
# 	Tuple: Immutable(if created, nothing can be added) & Heterogenous(can contain different types)
#	Set: --einai sunola opote an exeis ena stoixeio sto sunolo den mporeis na baleis 2o idio --, Example Application: it can be used to find a distinct set of words
#	Dictionary: Works like a hashmap

# * Find item in nested list: photos[i][j]
# * Print concatenation (string & int): print "Hello ",x," ",y," World"


#Show Keypoints: showimage(cv2.drawKeypoints(photo[2],kps,None,None,flags=cv2.DRAW_MATCHES_FLAGS_DRAW_RICH_KEYPOINTS))

@@ -601,17 +601,16 @@
 %5B%5D %09%09%09%09%09
-%09
 # create
@@ -624,16 +624,16 @@
 s%22 list%0A
+
 %09photosd
@@ -838,17 +838,16 @@
 2GRAY)%09%09
-%09
 #convert
@@ -900,18 +900,16 @@
 , gray%5D)
-%09%09
 %09%09%09#appe
@@ -1378,925 +1378,11 @@
 0)%0A%0A
+
 main()%0A
-%0A%0A%0A# *************************************************** NOTES ********************************************************%0A%0A# SYSTEM%0A# * load virtual environment: source cv/bin/activate%0A# * mv ~/Desktop/Yelp/various/train_photos/IMAGEFILE ~/Desktop/Yelp/photos/%0A%0A# PYTHON%0A# * Find length: len(DATATYPE)%0A%0A# * List: Homogenous(contains same types)%09!!THE MOST CONVENIENT AND FLEXIBLE !!%0A# %09Tuple: Immutable(if created, nothing can be added) & Heterogenous(can contain different types)%0A#%09Set: --einai sunola opote an exeis ena stoixeio sto sunolo den mporeis na baleis 2o idio --, Example Application: it can be used to find a distinct set of words%0A#%09Dictionary: Works like a hashmap%0A%0A# * Find item in nested list: photos%5Bi%5D%5Bj%5D%0A# * Print concatenation (string & int): print %22Hello %22,x,%22 %22,y,%22 World%22%0A%0A%0A#Show Keypoints: showimage(cv2.drawKeypoints(photo%5B2%5D,kps,None,None,flags=cv2.DRAW_MATCHES_FLAGS_DRAW_RICH_KEYPOINTS))%0A

Remove personal notes from script