Exemplo 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)
Exemplo n.º 2
0
# 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)

# show the query cover
cv2.imshow("Query", queryImage)
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)
    # extracts his keypoints and local invariant descriptors from the query image
Exemplo n.º 4
0
	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
if len(results) == 0:
Exemplo n.º 5
0
import cv2

# initialize the default parameters using BRISK is being used
useSIFT = False
useHamming = True
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,
                  ratio=ratio,
                  minMatches=minMatches,
                  useHamming=useHamming)

# load the query image, convert it to grayscale, and extract
# keypoints and descriptors
queryImage = cv2.imread("queries/query02.png")
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
Exemplo n.º 6
0
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:
            print "No se pudo abrir el video"