Пример #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)
Пример #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(?,?,?)',
Пример #3
0
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 default parameters using BRISK is being used
useSIFT = args["sift"] > 0
useHamming = args["sift"] == 0
ratio = 0.7
minMatches = 40

# if SIFT is to be used, then update the parameters
if useSIFT:
    minMatches = 50

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

# load the query image, convert it to grayscale, and extract
# keypoints and descriptors
queryImage = cv2.imread(args["query"])
gray = cv2.cvtColor(queryImage, cv2.COLOR_BGR2GRAY)
(queryKps, queryDescs) = cd.describe(gray)

# try to match the book cover to a known database of images
results = cv.search(queryKps, queryDescs)
# 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)
Пример #5
0
ap.add_argument("-c", "--covers", required = True,
	help = "path to the directory that contains our book covers")
ap.add_argument("-q", "--query", required = True,
	help = "path to the query book cover")
args = vars(ap.parse_args())

# initialize the database dictionary of covers
db = {}

# loop over the database
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["covers"] + "/*.png"))

# load the query image, convert it to grayscale, and extract
# keypoints and descriptors
queryImage = cv2.imread(args["query"])
gray = cv2.cvtColor(queryImage, cv2.COLOR_BGR2GRAY)
(queryKps, queryDescs) = cd.describe(gray)

# try to match the book cover to a known database of images
results = cv.search(queryKps, queryDescs)

# show the query cover
cv2.imshow("Query", queryImage)

# check to see if no results were found
Пример #6
0
# whether cropping is being performed or not
refPt = []
cropping = False

# 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"))


def click_search(event, x, y, flags, param):

    if event == cv2.EVENT_LBUTTONDOWN:
        print "Buscando .... "
    elif event == cv2.EVENT_LBUTTONUP:

        # grab the current frame
        (grabbed, searched_image) = 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:
Пример #7
0
# 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(?,?,?)',
             (imgPath, kps, descs))

#    print(kps)
#    print(descs)
conn.commit()
conn.close()