예제 #1
0
def main():
    """runs unit test procedure.
    """
    conf = Fconfig(CONFIG_FILE)
    db_name = conf.get_db_name()
    print "adding to database"
    add_test(db_name)
    print "removing from database"
    del_test(db_name)
예제 #2
0
def main():
    """runs open alpr with system call,
    prints output."""
    img_path = '/home/kivi/Downloads/plaka.jpg'
    conf_path = 'config.ini'
    conf = Fconfig(conf_path)
    alpr_cmd = conf.get_config('CMD')['run']
    alpr_cmd = alpr_cmd.format(plate_img=img_path)
    reader = PlateRead(img_path, conf_path)
    result = reader.openalpr_run()
    print result
예제 #3
0
 def __init__(self, img_path, conf_path):
     """Initializer function
     :img_path: str
         path of image to process
     :conf_path: str
         path to config file which contains
         hard-coded parts
     """
     self.img_path = img_path
     self.result = []
     self.conf = Fconfig(conf_path)
예제 #4
0
def main():
    """runs open alpr with system call,
    prints output."""
    img_path = '/home/kivi/Downloads/plaka.jpg'
    conf_path = 'config.ini'
    conf = Fconfig(conf_path)
    alpr_cmd = conf.get_config('CMD')['run']
    alpr_cmd = alpr_cmd.format(plate_img=img_path)
    reader = PlateRead(img_path, conf_path)
    result = reader.openalpr_run()
    print result
예제 #5
0
파일: frouter.py 프로젝트: jeremyz/pyevenja
        def test1Name(self):
            self.assertEquals(router1.start( None, "testezlog.xml"),RET_OK)
            strH = FstringHash()
            strH.setString( "TEST00")

            #// TEST Name from file
            self.assertEquals(router1.equals( strH),True)

            #// TEST from node config
            conf = Fconfig()
            conf.startXml( "testezlog.xml")
            router2.start( None, conf.getCurrent())
            self.assertEquals(router2.equals( strH),True)
            router1.end()
            router2.end()
예제 #6
0
 def __init__(self, img_path, conf_path):
     """Initializer function
     :img_path: str
         path of image to process
     :conf_path: str
         path to config file which contains
         hard-coded parts
     """
     self.img_path = img_path
     self.result = []
     self.conf = Fconfig(conf_path)
예제 #7
0
class PlateRead(object):

    """Plate Reader Class. Process image
    file and returns plate with confidence
    level"""

    def __init__(self, img_path, conf_path):
        """Initializer function
        :img_path: str
            path of image to process
        :conf_path: str
            path to config file which contains
            hard-coded parts
        """
        self.img_path = img_path
        self.result = []
        self.conf = Fconfig(conf_path)

    def openalpr_run(self):
        """runs openalpr and returns results in array.
        :file_path: str
            file path to read
        :returns: array
            [[plate, confidence], [], ...]
        """
        plate = ''
        confidence = ''
        alpr_cmd = self.conf.get_config('CMD')['run']
        alpr_cmd = alpr_cmd.format(plate_img=self.img_path)
        print alpr_cmd
        proc = subprocess.Popen([alpr_cmd], \
                stdout=subprocess.PIPE, shell=True)
        (out, err) = proc.communicate()
        out_lines = out.split('\n')
        for idx, line in enumerate(out_lines):
            if idx != 0 and idx != len(out_lines) - 1:
                plate = line.split()[ALPR_INDEX['plate']]
                confidence = line.split()[ALPR_INDEX['confidence']]
                self.result.append(
                        {'conf': confidence, 'plate': plate}
                        )
        return self.result

    def plate_check(self):
        """
        returns: bool
            whether plate exist in database
        returns: arr
            openalr estimates
        """
        result = self.openalpr_run()
        result_info = {}
        if len(result) == 0:
            result_info['conf'] = '0'
            result_info['plate'] = 'NoN'
            return False, result_info

        for val in result:
            state, plate = PlateRead.tr_plate_check(str(val['plate']))
            if state:
                rows = self.db_check(plate)
            else:
                rows = []
            if len(rows) != 0:
                result_info = rows[0]
                return True, result_info
        result_info = result[0]
        return False, result_info

    @staticmethod
    def tr_plate_check(plate):
        """Turkey's plate number in format of.
        int(2 char) string(varies) int(varies)
        :plate: string
        :returns: bool
            whether plate is valid for Turkey
        :returns: str
            fixed plate number
        """
        plate = list(plate)
        if str(plate[0]) == 'O':
            plate[0] = '0'
        if str(plate[1]) == 'O':
            plate[1] = '0'
        try:
            val = int(plate[0])
        except ValueError:
            return False, ''
        try:
            val = int(plate[1])
        except ValueError:
            return False, ''

        i = 2
        str_end = -1
        while i < len(plate) and str_end == -1:
            try:
                val = int(str(plate[i]))
                str_end = i
            except ValueError:
                pass
            i += 1

        for i in range(str_end, len(plate)):
            if plate[i] == 'O':
                plate[i] = '0'
            else:
                try:
                    val = int(plate[i])
                except ValueError:
                    return False, ''
        return True, ''.join(plate)

    def db_check(self, plate):
        """ checks database to seek plate.
        :plate: str
            plate number
        """
        db_name = ''
        db_name = self.conf.get_db_name()
        records = CarRecorder({}, db_name)
        rows = records.get_plate_records(plate, 'car_info')
        return rows
예제 #8
0
파일: frouter.py 프로젝트: jeremyz/pyevenja
 def end(self):
     """/** Deploy the end() until the port. */"""
     for I in range(self.listHash.getCount()):
         self.listHash.get(I).end()
     return Fconfig.endXml(self)
예제 #9
0
파일: fport.py 프로젝트: jeremyz/pyevenja
 def __str__(self):
     return "\t"+Fconfig.__str__(self)+\
             " Fport - parent : "+str(self.parent)+\
             " - Viewer : "+str(self.viewer)+\
             " - freeEvenData : "+str(self.freeEvenData.getCount())+"\n"
예제 #10
0
파일: fport.py 프로젝트: jeremyz/pyevenja
 def __init__(self):
     Fconfig.__init__(self)        # force constructor
     self.parent = None        #/** Router this port is connected to and receives from */
     self.viewer = None        #/** Enable to view the datas inside the port (evenDoor or evenBoard). */
     self.freeEvenData = FlistHash()    #/** List of Free and Available evenDatas (faster than new and delete ;) */
예제 #11
0
class PlateRead(object):
    """Plate Reader Class. Process image
    file and returns plate with confidence
    level"""
    def __init__(self, img_path, conf_path):
        """Initializer function
        :img_path: str
            path of image to process
        :conf_path: str
            path to config file which contains
            hard-coded parts
        """
        self.img_path = img_path
        self.result = []
        self.conf = Fconfig(conf_path)

    def openalpr_run(self):
        """runs openalpr and returns results in array.
        :file_path: str
            file path to read
        :returns: array
            [[plate, confidence], [], ...]
        """
        plate = ''
        confidence = ''
        alpr_cmd = self.conf.get_config('CMD')['run']
        alpr_cmd = alpr_cmd.format(plate_img=self.img_path)
        print alpr_cmd
        proc = subprocess.Popen([alpr_cmd], \
                stdout=subprocess.PIPE, shell=True)
        (out, err) = proc.communicate()
        out_lines = out.split('\n')
        for idx, line in enumerate(out_lines):
            if idx != 0 and idx != len(out_lines) - 1:
                plate = line.split()[ALPR_INDEX['plate']]
                confidence = line.split()[ALPR_INDEX['confidence']]
                self.result.append({'conf': confidence, 'plate': plate})
        return self.result

    def plate_check(self):
        """
        returns: bool
            whether plate exist in database
        returns: arr
            openalr estimates
        """
        result = self.openalpr_run()
        result_info = {}
        if len(result) == 0:
            result_info['conf'] = '0'
            result_info['plate'] = 'NoN'
            return False, result_info

        for val in result:
            state, plate = PlateRead.tr_plate_check(str(val['plate']))
            if state:
                rows = self.db_check(plate)
            else:
                rows = []
            if len(rows) != 0:
                result_info = rows[0]
                return True, result_info
        result_info = result[0]
        return False, result_info

    @staticmethod
    def tr_plate_check(plate):
        """Turkey's plate number in format of.
        int(2 char) string(varies) int(varies)
        :plate: string
        :returns: bool
            whether plate is valid for Turkey
        :returns: str
            fixed plate number
        """
        plate = list(plate)
        if str(plate[0]) == 'O':
            plate[0] = '0'
        if str(plate[1]) == 'O':
            plate[1] = '0'
        try:
            val = int(plate[0])
        except ValueError:
            return False, ''
        try:
            val = int(plate[1])
        except ValueError:
            return False, ''

        i = 2
        str_end = -1
        while i < len(plate) and str_end == -1:
            try:
                val = int(str(plate[i]))
                str_end = i
            except ValueError:
                pass
            i += 1

        for i in range(str_end, len(plate)):
            if plate[i] == 'O':
                plate[i] = '0'
            else:
                try:
                    val = int(plate[i])
                except ValueError:
                    return False, ''
        return True, ''.join(plate)

    def db_check(self, plate):
        """ checks database to seek plate.
        :plate: str
            plate number
        """
        db_name = ''
        db_name = self.conf.get_db_name()
        records = CarRecorder({}, db_name)
        rows = records.get_plate_records(plate, 'car_info')
        return rows