Ejemplo n.º 1
0
	def __init__(self, useSIFT = False, useHamming = True, ratio = 0.7, minMatches = 40):
		# store whether or not SIFT should be used as the feature
		# detector and extractor
		self.useSIFT = useSIFT
		self.useHamming = useHamming
		self.ratio = ratio
		self.minMatches = minMatches
		# if SIFT is to be used, then update the parameters
		if useSIFT:
			self.minMatches = 50

		self.cd = CoverDescriptor(useSIFT = useSIFT)
		self.cv = CoverMatcher(self.cd, ratio = ratio, minMatches = minMatches, useHamming = useHamming)
Ejemplo n.º 2
0

# Converts np.array to TEXT when inserting
sqlite3.register_adapter(numpy.ndarray, adapt_array)

# Converts TEXT to np.array when selecting
sqlite3.register_converter("array", convert_array)

ap = argparse.ArgumentParser()
args = vars(ap.parse_args())

useSIFT = False
useHamming = True

# initialize the cover descriptor and cover matcher
cd = CoverDescriptor(useSIFT=useSIFT)
conn = sqlite3.connect('db', detect_types=sqlite3.PARSE_DECLTYPES)
cur = conn.cursor()

c = conn.cursor()

for imgPath in glob.glob("newimages/*.png"):

    # load the query image, convert it to grayscale, and
    # extract keypoints and descriptors
    cover = cv2.imread(imgPath)
    gray = cv2.cvtColor(cover, cv2.COLOR_BGR2GRAY)
    (kps, descs) = CoverDescriptor.describe(cd, gray)

    c.execute(
        'INSERT INTO images(filename,keypoints,descriptors) VALUES(?,?,?)',
# otherwise, load the video
else:
    camera = cv2.VideoCapture(args["video"])

# initialize the database dictionary of covers
db = {}

# loop over the database, CSV file is opened and each line looped over.
# The db dictionary is updated with the unique filename of the book as the key and
# the title of the book and author as the value.
for l in csv.reader(open(args["db"])):
    # update the database using the image ID as the key
    db[l[0]] = l[1:]

# initialize the cover descriptor and cover matcher
cd = CoverDescriptor()
cv = CoverMatcher(cd, glob.glob(args["empaques"] + "/*.png"))

#########################################################################################################

# keep looping
while True:
    # grab the current frame
    (grabbed, frame) = camera.read()

    # if we are viewing a video and we did not grab a
    # frame, then we have reached the end of the video
    if args.get("video") and not grabbed:
        break

    gray = cv2.cvtColor(frame, cv2.COLOR_BGR2GRAY)