Example #1
0
 def testDictSearchWithIgnoreFiles(self):
     dictFile = "sampledict.txt"
     dictFilePath = os.path.join(testTempDir, dictFile)
     with open(dictFilePath, "wb") as f:
         f.write("%s\t%s\n" % ("abc", "the first 3 characters"))
     try:
         searcher = Searcher(testTempDir, ignoreFiles=["*.txt"])
         self.assertTrue(dictFile not in searcher.get_data_files())
     finally:
         os.remove(dictFilePath)
Example #2
0
 def testDictSearchWithIgnoreFiles(self):
     dictFile = "sampledict.txt"
     dictFilePath = os.path.join(testTempDir, dictFile)
     with open(dictFilePath, "wb") as f:
         f.write("%s\t%s\n" % ("abc", "the first 3 characters"))
     try:
         searcher = Searcher(testTempDir, ignoreFiles=["*.txt"])
         self.assertTrue(dictFile not in searcher.get_data_files())
     finally:
         os.remove(dictFilePath)
Example #3
0
 def testSearch(self):
     dictFile = "sampledict.txt"
     dictFilePath = os.path.join(testTempDir, dictFile)
     with open(dictFilePath, "wb") as f:
         f.write("%s\t%s\n" % ("abc", "the first 3 characters"))
     try:
         searcher = Searcher(testTempDir)
         d = searcher.search("abc")
         self.assertTrue(dictFile in d)
         self.assertTrue(d[dictFile].startswith("abc\t"))
     finally:
         os.remove(dictFilePath)
Example #4
0
 def testSearch(self):
     dictFile = "sampledict.txt"
     dictFilePath = os.path.join(testTempDir, dictFile)
     with open(dictFilePath, "wb") as f:
         f.write("%s\t%s\n" % ("abc", "the first 3 characters"))
     try:
         searcher = Searcher(testTempDir)
         d = searcher.search("abc")
         self.assertTrue(dictFile in d)
         self.assertTrue(d[dictFile].startswith("abc\t"))
     finally:
         os.remove(dictFilePath)
Example #5
0
 def testSort(self):
     dictFile = "sampledict.txt"
     dictFilePath = os.path.join(testTempDir, dictFile)
     with open(dictFilePath, "wb") as f:
         f.write("%s\t%s\n" % ("abc", "the 3 characters before 'def'"))
         f.write("%s\t%s\n" % ("def", "the 3 characters after 'abc'"))
     try:
         searcher = Searcher(testTempDir)
         normalD = searcher.search("def")
         self.assertTrue(dictFile in normalD)
         self.assertTrue(normalD[dictFile].startswith("abc\t"))
         d = searcher.search_raw("def",options=["--show-position"])
         d = searcher.sort_result_by_column(d, remove_position_str=True)
         sortedD = searcher.decode_result(d)
         self.assertTrue(dictFile in sortedD)
         self.assertTrue(sortedD[dictFile].startswith("def\t"))
     finally:
         os.remove(dictFilePath)
Example #6
0
 def testSort(self):
     dictFile = "sampledict.txt"
     dictFilePath = os.path.join(testTempDir, dictFile)
     with open(dictFilePath, "wb") as f:
         f.write("%s\t%s\n" % ("abc", "the 3 characters before 'def'"))
         f.write("%s\t%s\n" % ("def", "the 3 characters after 'abc'"))
     try:
         searcher = Searcher(testTempDir)
         normalD = searcher.search("def")
         self.assertTrue(dictFile in normalD)
         self.assertTrue(normalD[dictFile].startswith("abc\t"))
         d = searcher.search_raw("def", options=["--show-position"])
         d = searcher.sort_result_by_column(d, remove_position_str=True)
         sortedD = searcher.decode_result(d)
         self.assertTrue(dictFile in sortedD)
         self.assertTrue(sortedD[dictFile].startswith("def\t"))
     finally:
         os.remove(dictFilePath)
                required=True,
                help="Path to where the computed index will be stored")
ap.add_argument("-q", "--query", required=True, help="Path to the query image")
ap.add_argument("-r",
                "--result-path",
                required=True,
                help="Path to the result path")
args = vars(ap.parse_args())

# initialize the image descriptor
cd = ColorDescriptor((8, 12, 3))

# load the query image and describe it
query = cv2.imread(args["query"])
features = cd.describe(query)

# perform the search
searcher = Searcher(args["index"])
results = searcher.search(features)

# display the query
cv2.imshow("Query", query)
#win=plt.figure("search results")

# loop over the results
for (score, resultID) in results:
    # load the result image and display it
    result = cv2.imread(args["result_path"] + "/" + resultID)
    cv2.imshow("Result", result)
    cv2.waitKey(0)
Example #8
0
import bottle

bottleVersion = tuple([int(s) for s in bottle.__version__.split(".")[:2]])

from bottle import run, template, TEMPLATE_PATH
from bottle import route, request, static_file

from engine import Searcher
from _config import dataDir, ignoreFiles, moduleDir, historyDir
from _config import version
from history import *

templateDir = os.path.join(moduleDir, "view")
TEMPLATE_PATH.append(templateDir)

searcher = Searcher(dataDir, ignoreFiles)

initialOptions = {}
optionHistory = None

pathPattern = "<filename:path>" if bottleVersion >= (0,
                                                     10) else ":filename#.+#"


@route('/static/' + pathPattern)
def send_static(filename):
    return static_file(filename, root=os.path.join(moduleDir, "static"))


@route('/', method='get')
def index_get():
Example #9
0
def main():
    if len(sys.argv) == 1:
        sys.stdout.write("%s\n" % usage)
        sys.exit(0)
        
    searcher = Searcher(dataDir, ignoreFiles)

    if not searcher.get_data_files():
        sys.exit("""
No files in ./data directory.
(Installation is not completed. Put some utf-8 text files 
in ./data directory.)
"""[1:-1])
    
    queryOptionSet = set(["-i", "-w"] + ["-%d" % i for i in xrange(0, 10)])
    optionSortByColumn = None
    showPositionIsAppeared = False
    optionHistory = True
    
    opts, args = [], []
    for a in sys.argv[1:]:
        if a.startswith("-"):
            if a in ("-h", "--help"):
                sys.stdout.write("%s\n" % usage)
                sys.exit(0)
            elif a == "--version":
                sys.stdout.write("locdic.find %s\nsee http://www.remics.org/locdic/ for more information.\n" % version)
                sys.exit(0)
            elif a == "--sort-by-column":
                optionSortByColumn = True
            elif a == "--show-position":
                showPositionIsAppeared = True
                opts.append(a)
            elif a == "--no-history":
                optionHistory = False
            else:
                opts.append(a)
        else:
            args.append(a)
    
    if len(args) >= 2:
        sys.exit("error: too many command-line arguments")
        
    if optionSortByColumn and showPositionIsAppeared:
        sys.exit("error: options are mutually exclusive: --sort-by-column, --show-position")
    
    if optionHistory:
        d = datetime.datetime.today()
        add_to_history(args[0], [opt for opt in opts if opt in queryOptionSet], 
                d, "local")
        
    if optionSortByColumn:
        d = searcher.search_raw(args[0], options=opts + ["--show-position"])
        d = searcher.sort_result_by_column(d, remove_position_str=True)
        d = searcher.decode_result(d)
    else:
        d = searcher.search(args[0], options=opts)
    
    output = sys.stdout
    for f, r in sorted(d.items()):
        output.write("%s:\n" % f)
        output.write("%s\n" % r)