Exemplo n.º 1
0
class TestRunner(object):

    resDirectory = Config.get('PATHS', 'resDir')
    photoDirectory = Config.get('PATHS', 'photoDir')
    logoDirectory = Config.get('PATHS', 'logoDir')

    def __init__(self):
        self.detector, self.matcher = init('sift', False)

    def testPrepare(self, imgPath):
        kp, desc = prepare(imgPath, self.detector, 960, 720)
        print kp, desc
        print 'Preparing DONE'

    def testSerialize(self, imgPath):
        kp, desc = prepare(imgPath, self.detector, 960, 720)
        print 'Preparing DONE'
        print '... serialize kp'
        serialize(kp, 'test_serial_kp.pick')
        print '... serialize desc'
        serialize(desc, 'test_serial_desc.pick')
        print 'Serializing DONE'
        print '... unserialize kp'
        kp2 = unserialize('test_serial_kp.pick')
        print '... unserialize desc'
        desc2 = unserialize('test_serial_desc.pick')
        print 'Unserializing DONE'
Exemplo n.º 2
0
def runAll(img, imgPath, N):
    '''
    Поиск в изображении image логотипов
    возвращает первые N самых релевантных логотипов по img или imgPath

    :param img - изображение, в котором будет производится поиск логотипов
    :param imgPath - путь до изображения, в котором будет производится поиск логотипов
    :param N - количество возвращаемых логотипов
    
    :return [<Result>, ...]
    '''
    if not img and not imgPath:
        raise Exception('img and imgPath is None')
    detector, matcher = init('sift', False)
    if imgPath:
        kp2, desc2 = prepare(imgPath, detector, Config.get('PHOTOS', 'w'),
                             Config.get('PHOTOS', 'h'))
    else:
        kp2, desc2 = prepareByFile(img, detector, Config.get('PHOTOS', 'w'),
                                   Config.get('PHOTOS', 'h'))
    logoObjects = getAllLogos()
    bestLogoObjectByCompany = None
    bestLogoObjects = []
    for logoObject in logoObjects:
        print logoObject['photoPath']
        print 'GET SERIAL DATA'
        kp1, desc1 = getSearialData(logoObject['kpFilePath'],
                                    logoObject['descFilePath'])
        print 'MATCHING'
        result = match(kp1, desc1, kp2, desc2, detector, matcher)
        print 'RESULT'
        print result
        logoObject['result'] = result
        logoObject['runk'] = getRunk(logoObject['result']['res'],
                                     logoObject['result']['inliers'],
                                     logoObject['result']['matched'])
        print 'RUNK = %s' % logoObject['runk']
        if not logoObject['runk'] == 0:
            if bestLogoObjectByCompany:
                if logoObject['companyId'] == bestLogoObjectByCompany[
                        'companyId']:
                    if logoObject['runk'] > bestLogoObjectByCompany['runk']:
                        bestLogoObjectByCompany = logoObject
                else:
                    addResult(bestLogoObjects, bestLogoObjectByCompany, N)
                    bestLogoObjectByCompany = logoObject
            else:
                bestLogoObjectByCompany = logoObject

    if bestLogoObjectByCompany:
        addResult(bestLogoObjects, bestLogoObjectByCompany, N)
    result = [
        Result(logo['logoId'], logo['companyId'], logo['photoPath'])
        for logo in bestLogoObjects
    ]

    return result
Exemplo n.º 3
0
    def close_session(cls):
        if not Config.getSessionID():
            return

        iface = cls.get_interface('FABLIK_BASE')

        inputVar = iface.create_variable('RequestCloseSession', session_id=Config.getSessionID())

        result = iface.call('closeSession', inputVar)

        if result.ret_code != 0:
            message = MESSAGES.get(result.ret_code, result.ret_message)
            raise Exception(message)
Exemplo n.º 4
0
def runAll (img, imgPath, N):
    '''
    Поиск в изображении image логотипов
    возвращает первые N самых релевантных логотипов по img или imgPath

    :param img - изображение, в котором будет производится поиск логотипов
    :param imgPath - путь до изображения, в котором будет производится поиск логотипов
    :param N - количество возвращаемых логотипов
    
    :return [<Result>, ...]
    '''
    if not img and not imgPath:
        raise Exception('img and imgPath is None')
    detector, matcher = init('sift', False)
    if imgPath :
        kp2, desc2 = prepare(imgPath, detector, Config.get('PHOTOS','w'), Config.get('PHOTOS','h'))
    else :
        kp2, desc2 = prepareByFile(img, detector, Config.get('PHOTOS','w'), Config.get('PHOTOS','h'))
    logoObjects = getAllLogos()
    bestLogoObjectByCompany = None
    bestLogoObjects = []
    for logoObject in logoObjects:
        print logoObject['photoPath']
        print 'GET SERIAL DATA' 
        kp1, desc1 = getSearialData(logoObject['kpFilePath'],logoObject['descFilePath'])
        print 'MATCHING'
        result = match(kp1, desc1, kp2, desc2, detector, matcher)
        print 'RESULT'
        print result
        logoObject['result'] = result
        logoObject['runk'] = getRunk(logoObject['result']['res'], logoObject['result']['inliers'], logoObject['result']['matched'])
        print 'RUNK = %s' % logoObject['runk']
        if not logoObject['runk'] == 0:
            if bestLogoObjectByCompany:
                if logoObject['companyId'] == bestLogoObjectByCompany['companyId']:
                    if logoObject['runk'] > bestLogoObjectByCompany['runk']:
                        bestLogoObjectByCompany = logoObject
                else:
                    addResult(bestLogoObjects, bestLogoObjectByCompany, N)
                    bestLogoObjectByCompany = logoObject
            else:
                bestLogoObjectByCompany = logoObject

    if bestLogoObjectByCompany:
        addResult(bestLogoObjects, bestLogoObjectByCompany, N)
    result = [Result(logo['logoId'],
                   logo['companyId'],
                   logo['photoPath']) for logo in bestLogoObjects]

    return result
Exemplo n.º 5
0
    def onRemoveDepartment(self):
        dep_id = self.treeWraper.getCurrentItem('id')
        if not dep_id:
            curr = self._widgets.departmentsTree.currentItem()
            if not curr:
                return
            p = curr.parent()
            p.removeChild(curr)
            return

        yes = self.askQuestion(self.tr('Do you realy want delete this department?'))
        if not yes:
            return

        in_var = self.mgt_interface.create_variable('RequestDeleteDepartment')

        in_var.session_id = Config.getSessionID()
        in_var.department_id = dep_id

        ret = self.mgt_interface.call('deleteDepartment', in_var)

        if ret.ret_code != 0:
            self.errorMessage(ret.ret_message)
            return

        self.informationMessage(self.tr('Department is deleted from database'))

        self.syncTree()
Exemplo n.º 6
0
    def authenticate(cls, username, password):
        iface = cls.get_interface('FABLIK_BASE')
        inputVar = iface.create_variable('RequestAuthenticate', login=username, password=password)

        result = iface.call('authenticate', inputVar)

        if result.ret_code != 0:
            message = MESSAGES.get(result.ret_code, result.ret_message)
            raise Exception(message)

        Config.setSessionID( result.session_id )
        Config.USER_NAME = username
        Config.USER_PASSWORD = password

        Config.ismod = True
        Config.save_config()

        cls.load_interfaces(iface)
Exemplo n.º 7
0
    def close_cursor(cls, cursor_obj):
        inputVar = cls.interface.create_variable("RequestCloseCursor")

        inputVar.session_id = Config.getSessionID()
        inputVar.cursor_sid = cursor_obj.get_cursor_sid()

        result = cls.interface.call("closeCursor", inputVar)

        if result.ret_code != 0:
            raise Exception(result.ret_message)

        cursor_obj.closed = True
Exemplo n.º 8
0
    def load_interfaces(cls, base_iface):
        inputVar = base_iface.create_variable('RequestGetInterfaces', session_id=Config.getSessionID())

        result = base_iface.call('getInterfaces', inputVar)

        if result.ret_code != 0:
            message = MESSAGES.get(result.ret_code, result.ret_message)
            raise Exception(message)

        if len(result.interface_list) == 0:
            return

        for interface in result.interface_list.interface:
            cls.interfaces[interface.sid] = interface.url
Exemplo n.º 9
0
    def fetch_cursor(cls, cursor_obj, offset, fetch_count):
        inputVar = cls.interface.create_variable("RequestGetCursorData")

        inputVar.session_id = Config.getSessionID()
        inputVar.cursor_sid = cursor_obj.get_cursor_sid()
        inputVar.offset = offset
        inputVar.fetch_count = fetch_count

        result = cls.interface.call("getCursorData", inputVar)

        if result.ret_code != 0:
            raise Exception(result.ret_message)

        col_descriptions = cursor_obj.get_col_descriptions()

        return cls.__perform_data(result.row_list, col_descriptions)
Exemplo n.º 10
0
    def make_cursor(cls, query_sid, **filter_list):
        inputVar = cls.interface.create_variable("RequestCreateCursor")

        inputVar.session_id = Config.getSessionID()
        inputVar.sql_query_sid = query_sid

        for filter_name in filter_list:
            filter_var = cls.interface.create_variable("filter")
            filter_var.name = filter_name
            filter_var.value = filter_list[filter_name]
            inputVar.filter_list.filter.append(filter_var)

        result = cls.interface.call("createCursor", inputVar)

        if result.ret_code != 0:
            raise Exception(result.ret_message)

        return Cursor(result.cursor_sid, result.row_description)
Exemplo n.º 11
0
    def onApplyDepartment(self):
        wl = self._widgets

        dep_id = self.treeWraper.getCurrentItem('id')
        dep_name = wl.depNameEdit.text()
        dep_sid = wl.depSIDEdit.text()
        dep_descr = wl.depDescriptionEdit.text()

        if dep_name == '':
            self.errorMessage(self.tr('Departmnent name must be not empty!'))
            return

        if dep_sid == '':
            self.errorMessage(self.tr('Department SID must be not empty'))
            return

        if dep_id:
            in_var = self.mgt_interface.create_variable('RequestUpdateDepartment')
            in_var.department_id = dep_id
        else:
            in_var = self.mgt_interface.create_variable('RequestCreateDepartment')

        in_var.session_id = Config.getSessionID()
        in_var.sid = dep_sid
        in_var.parent_id = self.treeWraper.getCurrentItem('parent_id')
        in_var.name = dep_name
        in_var.description = dep_descr

        if dep_id:
            method = 'updateDepartment'
        else:
            method = 'createDepartment'

        ret = self.mgt_interface.call(method, in_var)

        if ret.ret_code != 0:
            self.errorMessage(ret.ret_message)
            return

        self.informationMessage(self.tr('Department is saved in database'))

        self.syncTree()
Exemplo n.º 12
0
    def __load_form_by_sid(cls, form_sid, checksum=''):
        iface = Client.get_interface('FABLIK_BASE')
        inputVar = iface.create_variable('RequestGetForm')

        inputVar.session_id = Config.getSessionID()
        inputVar.form_sid = form_sid
        inputVar.checksum = checksum

        result = iface.call('getForm', inputVar)

        if result.ret_code != 0:
            raise Exception(result.ret_message)

        if result.form_source:
            print 'cache is not found or not valid. Creating...'
            form_source = base64.decodestring(result.form_source)
            f = open(os.path.join(cls.__cache_dir, '%s.ffc'%(form_sid)), 'wb')
            f.write(form_source)
            f.close()

        return result.form_permission
Exemplo n.º 13
0
    def select(cls, query_sid, **filter_list):
        inputVar = cls.interface.create_variable("RequestExecuteQuery")

        inputVar.session_id = Config.getSessionID()
        inputVar.sql_query_sid = query_sid

        for filter_name in filter_list:
            filter_var = cls.interface.create_variable("filter")
            filter_var.name = filter_name
            filter_var.value = filter_list[filter_name]
            inputVar.filter_list.filter.append(filter_var)

        result = cls.interface.call("executeQuery", inputVar)

        if result.ret_code != 0:
            raise Exception(result.ret_message)

        col_descriptions = {}
        for col_desc in result.row_description.column_description:
            col_descriptions[col_desc.num] = Column(col_desc.type, col_desc.name)

        return cls.__perform_data(result.row_list, col_descriptions)
Exemplo n.º 14
0
            LogManager.info('Menu cache %s is not loaded. Details: %s' %(self.__menu_cache_file,e))
        finally:
            if f is not None:
                f.close()

        self.__menu.sort(cmp=my_cmp)
        md5 = hashlib.md5()
        for item in self.__menu:
            item.update_checksum(md5)

        menu_checksum = md5.hexdigest()

        iface = Client.get_interface('FABLIK_BASE')
        inputVar = iface.create_variable('RequestGetMainMenu')

        inputVar.session_id = Config.getSessionID()
        inputVar.checksum = menu_checksum
        inputVar.lang_sid = Config.getLangSid()

        result = iface.call('getMainMenu', inputVar)

        if result.ret_code != 0:
            raise Exception(result.ret_message)

        if len(result.menu_list) == 0:
            LogManager.info('Menu cache is valid. Use it')
            return

        self.__menu = []
        for item in result.menu_list[0]:
            menuitem = MenuItem(item.id, item.help, item.name, item.form_sid, 0, item.parent_id, item.shortcut)
Exemplo n.º 15
0
    def __load_form_lang(cls, form_path):
        lang_sid = Config.getLangSid()

        lang_file = 'translate_%s.qm' % lang_sid

        mainWindow.loadTranslateFile(lang_file, os.path.join(form_path,'lang'))