class TradeWorker(object): def __init__(self): # This block initializes the lists, that you need to trade. self.all_item_classes = set() self.in_buy_item_classes = set() self.in_sell_item_classes = set() self.in_freeze_item_classes = set() self.in_check_item_classes = set() self.controller = TradeWorkerController(self) self.executor = Executor() self.searcher = Searcher() # Initializes controller, executor and checker_items_prices threads. self.checker_price_thread = threading.Thread(target=self.searcher.start, name='SearcherThread', kwargs={'output_queue': self.controller.get_input_queue()}) self.executor_thread = threading.Thread(target=self.executor.start, name='ExecutorThread', kwargs={'output_queue': self.controller.get_input_queue()}) self.trade_worker_controller_thread = threading.Thread(target=self.controller.start_routing, name='TradeWorkerControllerThread') self.__start() def __start(self): self.__load_start_data() self.__start_threads() self.__start_main_event_loop() def __load_start_data(self): # This is temporary block. It's necessary before checker and executor was finale finished. self.all_item_classes = set(ItemClass.get_default_itemclass_list()[:200]) self.in_buy_item_classes = set(list(self.all_item_classes)[5:50]) self.in_sell_item_classes = set(list(self.all_item_classes)[51:100]) self.refresh_in_check_item_classes() self.controller.set_output_queue_searcher(self.searcher.get_input_queue()) self.controller.set_output_queue_executor(self.executor.get_input_queue()) def __start_threads(self): # Start threads. self.trade_worker_controller_thread.start() # self.checker_price_thread.start() self.executor_thread.start() def __start_main_event_loop(self): while True: print 'Generate new loop!' # self.search_trade_value_item_classes() self.controller.output_queue_executor.put(1) time.sleep(10) def search_trade_value_item_classes(self): for item_class in self.in_check_item_classes: task = CheckProfitTradeTask(item_class) self.controller.get_output_queue_searcher().put(task) def refresh_in_check_item_classes(self): self.in_check_item_classes = self.all_item_classes - self.in_buy_item_classes - self.in_sell_item_classes
def search(): if request.method == "POST": results_arr = [] img_path = request.form.get("img") try: import cv2 d = Descriptor((8, 12, 3)) query = cv2.imread("static/images/" + img_path) features = d.describe(query) searcher = Searcher("index.csv") results = searcher.search(features) for (score, id) in results: results_arr.append({"image": str(id), "score": str(score)}) return jsonify(results=(results_arr[::-1][:5])) except: return jsonify({"sorry": "Sorry, something went wrong! Please try again."})
def search(): if request.method == 'POST': results_arr = [] img_path = request.form.get('img') try: import cv2 d = Descriptor((8, 12, 3)) query = cv2.imread('static/images/' + img_path) features = d.describe(query) searcher = Searcher('index.csv') results = searcher.search(features) for (score, id) in results: results_arr.append({'image': str(id), 'score': str(score)}) return jsonify(results=(results_arr[::-1][:5])) except: return jsonify( {'sorry': 'Sorry, something went wrong! Please try again.'})
def __init__(self): # This block initializes the lists, that you need to trade. self.all_item_classes = set() self.in_buy_item_classes = set() self.in_sell_item_classes = set() self.in_freeze_item_classes = set() self.in_check_item_classes = set() self.controller = TradeWorkerController(self) self.executor = Executor() self.searcher = Searcher() # Initializes controller, executor and checker_items_prices threads. self.checker_price_thread = threading.Thread(target=self.searcher.start, name='SearcherThread', kwargs={'output_queue': self.controller.get_input_queue()}) self.executor_thread = threading.Thread(target=self.executor.start, name='ExecutorThread', kwargs={'output_queue': self.controller.get_input_queue()}) self.trade_worker_controller_thread = threading.Thread(target=self.controller.start_routing, name='TradeWorkerControllerThread') self.__start()
help="Engine to use for searching." " Defaults to google ", default="google") searcher.add_argument("-l", "--num-links", dest="number_of_links", help="Number of links to return. " "Defaults to 20", default=20, type=int) # analizer related options analizer = parser.add_argument_group('analizer') analizer.add_argument("-k", "--keyword", dest="keyword", required=True, help="Sentence to search on the web") analizer.add_argument("-e", "--engine", dest="engine", type=str, help="Engine to use for searching." " Defaults to google ", default="google") analizer.add_argument("-l", "--num-links", dest="number_of_links", help="Number of links to return. " "Defaults to 20", default=20, type=int) args = parser.parse_args() g = Searcher(args.keyword, engine=args.engine, number_of_links=args.number_of_links) print args links = g.get_links()
default=20, type=int) # analizer related options analizer = parser.add_argument_group('analizer') analizer.add_argument("-k", "--keyword", dest="keyword", required=True, help="Sentence to search on the web") analizer.add_argument("-e", "--engine", dest="engine", type=str, help="Engine to use for searching." " Defaults to google ", default="google") analizer.add_argument("-l", "--num-links", dest="number_of_links", help="Number of links to return. " "Defaults to 20", default=20, type=int) args = parser.parse_args() g = Searcher(args.keyword, engine=args.engine, number_of_links=args.number_of_links) print args links = g.get_links()
from descriptor.descriptor import Descriptor from searcher.searcher import Searcher import argparse import cv2 ap = argparse.ArgumentParser() ap.add_argument('-i', '--index', required = True, help = 'Path to computed computed index') ap.add_argument('-q', '--query', required = True, help = 'Path to query image') ap.add_argument('-r', '--result', required = True, help = 'Path to picture database') args = vars(ap.parse_args()) d = Descriptor((8, 12, 3)) query = cv2.imread(args['query']) query = cv2.resize(query, (540, 360), cv2.INTER_AREA) features = d.describe(query) searcher = Searcher(args['index']) results = searcher.search(features) cv2.imshow('Query', query) for (score, id) in results: result = cv2.imread(args['result'] + '/' + str(id)) result = cv2.resize(result, (540, 360), cv2.INTER_AREA) cv2.imshow('Result', result) cv2.waitKey(0)