Ejemplo n.º 1
0
def main():
    #Init the system:
    res = sysLogin()
    if res == False:
        print('> Login failed!')
        return False
    
    #Connect to database:
    res, conn, cur= psq.login_database_Default()
    if res == False:
        print('> Connect database failed!')
        return False

    #Load model for AI modules:
    yoloPlate, characterRecognition = pr.sysInit_Default()
    
    os.chdir(DEFAULT_WORKSPACE)
    lstImg = [name for name in os.listdir() if name.endswith('.jpg') 
                                            or name.endswith('.jpeg')
                                            or name.endswith('.png')
                                            or name.endswith('.raw')]
    
    parking = ParkingTable(conn, cur)
    history = HistoryTable(conn,cur)
    for imgName in lstImg:
        # Load image, recognize the plate number:
        choice = input('> Press [ENTER] to load img:')
        if choice == '0':
            print('> Exiting...')
            break
        RFID = getRFID()
        PlateImgURL = getImg(imgName, show=True)
        _,PlateNumber = pr.plateRecog(PlateImgURL, yoloPlate, characterRecognition, show=False)
        ParkingLotID = getParkingLotID()
        CheckInTime = DT.now()
        StaffID = getStaffID()
        print(StaffID)
        CameraID = getCameraID()
        # cv2.waitKey(0)
        choice = input('> Press [ENTER] to allow vehicles in:')
        cv2.destroyAllWindows()
        if choice == '0':
            print('> Canceled!')
            continue
        # Insert to ParkingTable:
        res = parking.insert(RFID, ParkingLotID, PlateNumber, PlateImgURL, CheckInTime)
        if res != True:
            print('> Cannot allow vehicles to come in <%s> parking lot'%(ParkingLotID))    
        else:
            print('> Inserted parking')
            # Insert to HistoryTable: 
            res = history.insert(RFID, ParkingLotID, PlateNumber, PlateImgURL, StaffID, CameraID, True, CheckInTime)
            if res != True:
                print('> Cannot add history')
            else:
                print('> Inserted History')
Ejemplo n.º 2
0
        def run(self):
            if exit_status == True:
                return True
            ###########################################################################
            #Init the AI Core system:

            ## 1) Connect to database:
            ret, conn, cur = psq.login_database(database, username, password,
                                                host, port)
            if ret == True:
                print('> Logged in successful to <%s>' % (username))
            else:
                print('> Error: Log in error to <%s>' % (username))
                ## Emit signal for the Message Box:
                # Ready for termination.
                ui.sig.terminate_sig.emit(
                    'Error: Log in error to <' + username + '>', 'error',
                    str(ret))

                print('>Exit...')
                return False
            parking = ParkingTable(conn, cur)
            history = HistoryTable(conn, cur)

            ## 2) Load model for AI modules:
            yoloPlate, characterRecognition = pr.sysInit_Default()
            if yoloPlate == False:
                print('> Error: loading database for AI Core')
                ## Emit signal for the Message Box:
                # Ready for termination.
                ui.sig.terminate_sig.emit(
                    '> Error: loading database for AI Core', 'error',
                    str(characterRecognition))
                return False

            os.chdir(DEFAULT_WORKSPACE)
            ## 3) Simulate the data for recognition:
            lstImg = [
                name for name in os.listdir()
                if name.endswith('.jpg') or name.endswith('.jpeg')
                or name.endswith('.png') or name.endswith('.raw')
            ]

            ## 4) Get Information of the working session:
            StaffID = getStaffID()
            ui.lbStaffDesc.setText(StaffID)
            ParkingLotID = getParkingLotID()
            ui.lbParkingLotDesc.setText(ParkingLotID)
            CameraID = getCameraID()
            ui.lbCameraDesc.setText(CameraID)

            for imgName in lstImg:
                global semaphore, skip_plate, state
                # Load image, recognize the plate number:
                ui.lbEntranceImg.setPixmap(QtGui.QPixmap(""))
                ui.lbRFIDDesc.setText("")

                ui.lbPlateNumberDesc.setText('Press [Enter]')
                print('> Press [ENTER] to load img:')
                ui.setNotifications('Press [ENTER] to get new car.')
                state = SCAN_STATE
                semaphore = 0
                while semaphore == 0:
                    if exit_status == True:
                        return True
                    # print('.')
                    # time.sleep(3)
                ui.setNotifications('Please wait...')
                RFID = getRFID()
                ui.lbRFIDDesc.setText(RFID)
                PlateImgURL = getImg(imgName, ui, show=True)
                _, PlateNumber = pr.plateRecog(PlateImgURL,
                                               yoloPlate,
                                               characterRecognition,
                                               show=False)
                ui.lbPlateNumberDesc.setText(PlateNumber)

                print('Plate number:', PlateNumber)

                CheckInTime = DT.now()

                state = DATABASE_STATE
                # choice = input('> Press [ENTER] to allow vehicles in:')
                print('> Press [ENTER] to allow vehicles in:')
                ui.setNotifications('Please Check the plate number again\n'
                                    'Press [ENTER] to allow vehicles in\n'
                                    'Press [SKIP] to reject vehicles')
                semaphore = 0
                while semaphore == 0:
                    if skip_plate == True:
                        # skip_plate = False
                        break
                    if exit_status == True:
                        return True
                    # print('.')
                    # time.sleep(3)
                if skip_plate == True:
                    print('> Skipping plate <%s>' % (PlateNumber))
                    ui.setNotifications('Skipped plate <' + PlateNumber + '>')
                    skip_plate = False
                    continue
                ui.setNotifications('Please wait...')
                # Insert to ParkingTable:
                PlateNumber = ui.lbPlateNumberDesc.text()

                res = parking.insert(RFID, ParkingLotID, PlateNumber,
                                     PlateImgURL, CheckInTime)
                if res != True:
                    print(
                        '> Cannot allow vehicles to come in <%s> parking lot' %
                        (ParkingLotID))
                else:
                    print('> Inserted parking')
                    # Insert to HistoryTable:
                    res = history.insert(RFID, ParkingLotID, PlateNumber,
                                         PlateImgURL, StaffID, CameraID, True,
                                         CheckInTime)
                    if res != True:
                        print('> Cannot add history')
                    else:
                        print('> Inserted History')

                ui.lbPlateNumberDesc.setText('Press [Enter]')
Ejemplo n.º 3
0
def main():
    #Init the system:
    res = sysLogin()
    if res == False:
        print('> Login failed!')
        return False

    #Connect to database:
    res, conn, cur = psq.login_database_Default()
    if res == False:
        print('> Connect database failed!')
        return False
    yoloPlate, characterRecognition = pr.sysInit_Default()

    os.chdir(DEFAULT_WORKSPACE)
    lstImg = [
        name for name in os.listdir()
        if name.endswith('.jpg') or name.endswith('.jpeg')
        or name.endswith('.png') or name.endswith('.raw')
    ]
    parking = ParkingTable(conn, cur)
    history = HistoryTable(conn, cur)
    tshow = threading.Thread(target=imshow)
    tshow.start()
    for imgName in lstImg:
        choice = input('> Press [ENTER] to load img:')
        if choice == '0':
            print('> Exiting...')
            break

        RFID = getRFID()
        ParkingLotID = getParkingLotID()
        columns = 'platenumber, plateimgurl'
        conditions = "rfid='" + RFID + "' and parkinglotid='" + ParkingLotID + "'"
        records = parking.select(columns, conditions)
        if len(records) == 0:
            print('> Cannot find any match <rfid:%s> in <%s>' %
                  (RFID, ParkingLotID))
            continue
        # record = records[0]
        inPlateNumber = records[0][0]
        print('in:' + inPlateNumber)
        inPlateImgURL = records[0][1]

        inImg = cv2.imread(inPlateImgURL)
        outImg = cv2.imread(imgName)
        _, outPlateNumber = pr.plateRecog(imgName,
                                          yoloPlate,
                                          characterRecognition,
                                          show=False)
        print('out:', outPlateNumber)

        img_to_show.append([inImg, 'in'])
        img_to_show.append([outImg, 'out'])
        global show_flag
        show_flag = True
        # cv2.waitKey(0)
        if inPlateNumber == outPlateNumber:
            print('> Plate Number matched!')
        else:
            print('> Plate Number not matched!')
            choice = input('> Press [ENTER] to cancel')
            if choice != '0':
                cv2.destroyAllWindows()
                print('> Cancelled!')
                continue
        choice = input('> Press [ENTER] ')
        cv2.destroyAllWindows()
        res = parking.delete(RFID, ParkingLotID)
        if res != True:
            print('> Cannot allow vehicles to come out <%s> parking lot' %
                  (ParkingLotID))
        else:
            print('> Delete parking')
        outPlateImgURL = getImg(imgName, show=False)
        StaffID = getStaffID()
        CameraID = getCameraID()
        CheckInTime = DT.now()
        res = history.insert(RFID, ParkingLotID, outPlateNumber,
                             outPlateImgURL, StaffID, CameraID, False,
                             CheckInTime)
        if res != True:
            print('> Cannot add history')
        else:
            print('> Inserted History')
    global show_ret
    show_ret = True
Ejemplo n.º 4
0
        def run(self):
            if exit_status == True:
                return True
            ###########################################################################
            #Init the AI Core system:

            ## 1) Connect to database:
            ret, conn, cur = psq.login_database(database, username, password,
                                                host, port)
            if ret == True:
                print('> Logged in successful to <%s>' % (username))
            else:
                print('> Error: Log in error to <%s>' % (username))
                ## Emit signal for the Message Box:
                # Ready for termination.
                ui.sig.terminate_sig.emit(
                    'Error: Log in error to <' + username + '>', 'error',
                    str(ret))

                print('>Exit...')
                return False
            parking = ParkingTable(conn, cur)
            history = HistoryTable(conn, cur)

            ## 2) Load model for AI modules:
            yoloPlate, characterRecognition = pr.sysInit_Default()
            if yoloPlate == False:
                print('> Error: loading database for AI Core')
                ## Emit signal for the Message Box:
                # Ready for termination.
                ui.sig.terminate_sig.emit(
                    '> Error: loading database for AI Core', 'error',
                    str(characterRecognition))
                return False

            os.chdir(DEFAULT_WORKSPACE)
            ## 3) Simulate the data for recognition:
            lstImg = [
                name for name in os.listdir()
                if name.endswith('.jpg') or name.endswith('.jpeg')
                or name.endswith('.png') or name.endswith('.raw')
            ]

            ## 4) Get Information of the working session:
            StaffID = getStaffID(sysconfig)
            ui.lbStaffDesc.setText(StaffID)
            ParkingLotID = getParkingLotID(sysconfig)
            ui.lbParkingLotDesc.setText(ParkingLotID)
            CameraID = getCameraID(sysconfig)
            ui.lbCameraDesc.setText(CameraID)

            for imgName in lstImg:
                global semaphore, skip_plate, state
                # Load image, recognize the plate number:
                ui.lbEntranceImg.setPixmap(QtGui.QPixmap(""))
                ui.lbEntranceImg_2.setPixmap(QtGui.QPixmap(""))
                ui.lbRFIDDesc.setText("")

                ui.lbPlateNumberDesc.setText('Press [Enter]')
                print('> Press [ENTER] to load img:')
                ui.setNotifications('Press [ENTER] to get new car.')
                state = SCAN_STATE
                semaphore = 0
                while semaphore == 0:
                    if exit_status == True:
                        return True

                ui.setNotifications('Please wait...')
                RFID = getRFID(lstRFID)
                ui.lbRFIDDesc.setText(RFID)

                ###############################################################
                ## Retrive Plate number from the database:
                columns = 'platenumber, plateimgurl'
                conditions = "rfid='" + RFID + "' and parkinglotid='" + ParkingLotID + "'"
                records = parking.select(columns, conditions)
                if len(records) == 0:
                    print('> Cannot find any match <rfid:%s> in <%s>' %
                          (RFID, ParkingLotID))
                    continue

                inPlateNumber = records[0][0]
                print('in:' + inPlateNumber)
                inPlateImgURL = records[0][1]

                inImg = cv2.imread(inPlateImgURL)
                outImg = cv2.imread(imgName)
                outPlateImgURL = getImg(imgName, ui, show=False)

                _, outPlateNumber = pr.plateRecog(imgName,
                                                  yoloPlate,
                                                  characterRecognition,
                                                  show=False)

                imshow(ui.lbEntranceImg, inImg)
                imshow(ui.lbEntranceImg_2, outImg)

                ui.lbPlateNumberDesc.setText(outPlateNumber)

                print('out:', outPlateNumber)

                CheckInTime = DT.now()

                state = DATABASE_STATE

                if inPlateNumber == outPlateNumber:
                    print('> Plate Number matched!')
                    message = '> Plate Number matched!'
                else:
                    print('> Plate Number NOT matched!')
                    message = '> Plate Number NOT matched!'
                print('> Press [ENTER] to allow vehicles in:')
                ui.setNotifications(message +
                                    '\nPlease Check the plate number again\n'
                                    'Press [ENTER] to allow vehicles out\n'
                                    'Press [SKIP] to reject vehicles')
                semaphore = 0
                while semaphore == 0:
                    if skip_plate == True:
                        # skip_plate = False
                        break
                    if exit_status == True:
                        return True
                    # print('.')
                    # time.sleep(3)
                if skip_plate == True:
                    print('> Skipping plate <%s>' % (outPlateNumber))
                    ui.setNotifications('Skipped plate <' + outPlateNumber +
                                        '>')
                    skip_plate = False
                    continue
                ui.setNotifications('Please wait...')
                # Insert to ParkingTable:
                outPlateNumber = ui.lbPlateNumberDesc.text()

                res = parking.delete(RFID, ParkingLotID)
                if res != True:
                    print(
                        '> Cannot allow vehicles to come OUT <%s> parking lot'
                        % (ParkingLotID))
                else:
                    print('> Deleted parking')
                    # Insert to HistoryTable:
                    res = history.insert(RFID, ParkingLotID, outPlateNumber,
                                         outPlateImgURL, StaffID, CameraID,
                                         False, CheckInTime)
                    if res != True:
                        print('> Cannot add history')
                    else:
                        print('> Inserted History')

                ui.lbPlateNumberDesc.setText('Press [Enter]')