Esempio n. 1
0
 def __init__(self):
     self.env = simpy.Environment()
     self.db = database.data()
     self.db.load_sql()
     self.lines = {}
     self.stores = {}
     self.log = pd.DataFrame()
Esempio n. 2
0
 def __init__(self):
     self.env = simpy.Environment()
     self.db = database.data()
     self.db.load_sql()
     self.lines = {}
     self.stores = {}
     self.log = pd.DataFrame()
Esempio n. 3
0
def results(request):
    
    # On lance l'algorithme des mariages stables sur l'ensemble des ecoles et 
    # etudiants inscrits
    d = data()
    guyprefers = d.guyprefers
    galprefers = d.galprefers
    capacity = d.capacity
    engaged, rejected = matchmaker(guyprefers, galprefers, capacity)
    
    #On affiche le resultat et on transmet l'information a la partie HTML
    print(engaged)
    
    c = {'engaged': engaged,
         'rejected': rejected,
        }
    return render_to_response(r'results.html', c)
def main():
    # argument for input video/image/calibration
    ap = argparse.ArgumentParser()
    ap.add_argument("-v", "--video", help="path to video file")

    ap.add_argument("-i", "--image", help="Path to the image")

    ap.add_argument("-c", "--calibration", help="image or video or camera")
    args = vars(ap.parse_args())

    if args.get("calibration", True):
        imgOriginalScene = cv2.imread(args["calibration"])
        if imgOriginalScene is None:
            print("Please check again the path of image or argument !")

        imgOriginalScene = imutils.resize(imgOriginalScene, width=640)
        cal.calibration(imgOriginalScene)
        return

    if args.get("video", True):
        camera = cv2.VideoCapture(args["video"])
        if camera is None:
            print("   Please check again the path of video or argument !")
        loop = True

    elif args.get("image", True):
        #imgOriginalScene = cv2.imread(args["image"])
        imgOriginalScene = cv2.imread("tes_plat_indo/B6703WJF.jpg")
        if imgOriginalScene is None:
            print("   Please check again the path of image or argument !")
        loop = False
    else:
        #camera = cv2.VideoCapture("rtsp://*****:*****@192.168.0.159:554/PSIA/streaming/channels/101")
        camera = cv2.VideoCapture(
            "rtsp://192.168.0.10:554/user=admin&password=&channel=1&stream=0.sdp?"
        )
        #camera = cv2.VideoCapture("rtsp://*****:*****@192.168.0.26:554/PSIA/streaming/channels/301")
        #camera = cv2.VideoCapture(0)
        loop = True

    # add knn library for detect chars
    blnKNNTrainingSuccessful = DetectChars.loadKNNDataAndTrainKNN(
    )  # attempt KNN training

    if blnKNNTrainingSuccessful == False:  # if KNN training was not successful
        print(
            "\nerror: KNN traning was not successful\n")  # show error message
        return
    count = 0
    # not very important, just iterating for license array haha
    license = []
    VER = np.zeros(VERIF)
    for x in VER:
        license.append("")
    numlicense = ""
    knn = 0

    # Looping for Video
    while (loop):
        # grab the current frame
        (grabbed, frame) = camera.read()
        #frame = camera.read()
        if args.get("video") and not grabbed:
            break
        # resize the frame and convert it to grayscale
        imgOriginalScene = imutils.resize(frame)
        imgGrayscale, imgThresh = pp.preprocess(imgOriginalScene)
        cv2.imshow("threshold", imgThresh)
        #imgOriginalScene = imutils.transform (imgOriginalScene)
        imgOriginalScene, licenses = searching(imgOriginalScene, loop)

        # only save 5 same license each time

        license[count + 1] = licenses
        nums = license[VERIF - 1]
        if (license[count] == license[count + 1]):
            license[count] = license[count + 1]
            count = count + 1
        elif (license[count] != license[count + 1]):
            coba = license[count + 1]
            count = 0
            license[count] = coba
        if count == (VERIF - 1):
            '''
            plateAlloc = "       "
            numstring = ""
            numbers = sum(c.isdigit() for c in nums)
            words   = sum(c.isalpha() for c in nums)

            for c in nums:
                numstring.append()
            '''

            global plat
            plat = "         "
            plat = list(plat)
            numstring = ""
            numstring = list(numstring)
            alphastring = ""
            alphastring = list(alphastring)
            numbers = sum(c.isdigit() for c in nums)
            words = sum(c.isalpha() for c in nums)

            for i in nums:
                #nums = np.array(nums)
                #nums = list(nums)
                if i.isalpha():
                    #nums[i] = np.array(nums[i])
                    alphastring.append(i)
                elif i.isdigit():
                    #nums[i] = np.array(nums[i])
                    numstring.append(i)

            print(nums)
            print(numstring)
            print(alphastring)

            #add numbers

            a = 2
            for b in numstring:
                plat[a] = b
                a += 1

            #add front letter(s)

            c = 0
            sumfront = sum(c.isalpha() for c in nums[0:2])
            if (sumfront == 1):
                for d in nums[0:1]:
                    plat[c] = d
                    c += 1
            elif (sumfront == 2):
                for d in nums[0:2]:
                    plat[c] = d
                    c += 1

            #add back letter(s)

            e = -3
            sumback = sum(e.isalpha() for e in nums[-3:])
            if (sumback == 1):
                for f in nums[-1:]:
                    plat[e] = f
                    e += 1
            elif (sumback == 2):
                for f in nums[-2:]:
                    plat[e] = f
                    e += 1
            elif (sumback == 3):
                for f in nums[-3:]:
                    plat[e] = f
                    e += 1

            plat = ''.join(plat)

            if (license[VERIF - 1] == ""):
                print("no characters were detected\n")
            else:
                #if number license same, not be saved

                if (numlicense == license[VERIF - 1]):
                    print("still = " + numlicense + "\n")
                elif (len(nums) <= 9 and nums[0] >= 'A' and nums[0] <= 'Z'
                      and numbers <= 4 and words <= 5):

                    numlicense = license[VERIF - 1]
                    #print("A new license plate read from image = " + license[VERIF-1] + "\n")
                    print("A new license plate read from image = " + plat +
                          "\n")
                    #cv2.imshow(license[VERIF-1], imgOriginalScene)
                    # cv2.imshow(plat, imgOriginalScene)
                    insertdata = data(numlicense)
                    if check(numlicense):
                        ts = time.time()
                        timestamp = datetime.datetime.fromtimestamp(
                            ts).strftime('%Y-%m-%d')
                        timestamp2 = datetime.datetime.fromtimestamp(
                            ts).strftime('%H:%M:%S')

                        #Ganti Path sesuai dengan laptop masing2 heheh
                        namefile = "/var/www/html/MonitoringDashboard/hasil_parksystem/" + license[
                            VERIF - 1] + timestamp + timestamp2 + ".png"
                        cv2.imwrite(namefile, imgOriginalScene)

                        #Hapus bagian ini untuk tidak menggunakan sensor dan mengirim mqtt
                        #broker="192.168.8.120"
                        #port=1883
                        #client1= paho.Client("control1")                           #create client object
                        #client1.connect(broker,port)                                 #establish connection
                        #ret= client1.publish("xiaomi/to/write",'{"cmd": "write",  "model": "plug",  "sid": "158d0002365abb",  "data": {"status": "on"}}')
                        # broker="192.168.1.151"
                        # port=1883
                        # client1= paho.Client("control1")                           #create client object
                        # client1.connect(broker,port)                                 #establish connection
                        # client1.publish("alpr/mqtt","0")
                        # os.system('spd-say "Welcome to Graha Sumber Prima Elektronik"')
            count = 0

        #determine plate regions

        # global plateRegion
        # plateRegion = ""
        # plateDic = {'B':"Jakarta", 'D':"Bandung", 'L':"Surabaya", 'A':"Banten", 'E':"Cirebon", 'G':"Pekalongan", 'H':"Semarang"}
        # for i, j in plateDic.items():
        #     if (plat[0] == i):
        #         plateRegion = j

        #and nums[0] >= 'A' and nums[0] <= 'Z' and nums[-1] >= 'A' and nums[-1] <= 'Z'
        '''
        global plateRegion
        if (len(nums) >= 5 and len(nums) <= 9 and nums[0] == 'B'):
            plateRegion = "Jakarta"
        elif (len(nums) >= 5 and len(nums) <= 9 and nums[0] == 'D'):
            plateRegion = "Bandung"
        elif (len(nums) >= 5 and len(nums) <= 9 and nums[0] == 'L'):
            plateRegion = "Surabaya"
        elif (len(nums) >= 5 and len(nums) <= 9 and nums[0] == 'E'):
            plateRegion = "Bandung"
        elif (len(nums) >= 5 and len(nums) <= 9 and nums[0] == 'L'):
            plateRegion = "Surabaya"
        elif (len(nums) >= 5 and len(nums) <= 9 and nums[0] == 'D'):
            plateRegion = "Bandung"
        elif (len(nums) >= 5 and len(nums) <= 9 and nums[0] == 'L'):
            plateRegion = "Surabaya"
        elif (len(nums) >= 5 and len(nums) <= 9 and nums[0] == 'D'):
            plateRegion = "Bandung"
        elif (len(nums) >= 5 and len(nums) <= 9 and nums[0] == 'L'):
            plateRegion = "Surabaya"
        elif (len(nums) >= 5 and len(nums) <= 9 and nums[0] == 'D'):
            plateRegion = "Bandung"
        elif (len(nums) >= 5 and len(nums) <= 9 and nums[0] == 'L'):
            plateRegion = "Surabaya"
        elif (len(nums) >= 5 and len(nums) <= 9 and nums[0] == 'D'):
            plateRegion = "Bandung"
        elif (len(nums) >= 5 and len(nums) <= 9 and nums[0] == 'L'):
            plateRegion = "Surabaya"

        else:
            plateRegion = "Who knows?"

        '''

        #print(license)
        # re-show scene image
        #imgOriginalScene = cv2.blur(imgOriginalScene,(12,12))
        cv2.putText(
            imgOriginalScene,
            "Press 's' to save frame to be 'save.png', for calibrating",
            (10, 30),
            cv2.FONT_HERSHEY_SIMPLEX,
            0.5, (255, 255, 255),
            1,
            bottomLeftOrigin=False)
        #drawRedRectangleAroundPlate(imgOriginalScene, imgOriginalScene)

        #cv2.rectangle(imgOriginalScene,((imgOriginalScene.shape[1]/2-230),(imgOriginalScene.shape[0]/2-80)),((imgOriginalScene.shape[1]/2+230),(imgOriginalScene.shape[0]/2+80)),SCALAR_GREEN,3)
        cv2.rectangle(imgOriginalScene,
                      ((int(imgOriginalScene.shape[1] / 2 - 230)),
                       (int(imgOriginalScene.shape[0] / 2 - 80))),
                      ((int(imgOriginalScene.shape[1] / 2 + 230)),
                       (int(imgOriginalScene.shape[0] / 2 + 80))),
                      SCALAR_GREEN, 3)

        cv2.imshow("imgOriginalScene", imgOriginalScene)
        #cv2.imshow("ori", frame)

        key = cv2.waitKey(5) & 0xFF
        if key == ord('s'):
            knn = str(knn)
            savefileimg = "calib_knn/img_" + knn + ".png"
            savefileThr = "calib_knn/Thr_" + knn + ".png"
            #cv2.saveimage("save.png", imgOriginalScene)
            cv2.imwrite(savefileimg, frame)
            cv2.imwrite(savefileThr, imgThresh)
            print("image save !")
            knn = int(knn)
            knn = knn + 1
        if key == 27:  # if the 'q' key is pressed, stop the loop
            break
            camera.release()  # cleanup the camera and close any open windows

    # For image only
    if (loop == False):
        imgOriginalScene = imutils.resize(imgOriginalScene, width=2000)
        cv2.imshow("original", imgOriginalScene)
        imgGrayscale, imgThresh = pp.preprocess(imgOriginalScene)
        cv2.imshow("threshold", imgThresh)
        #imgOriginalScene = imutils.transform (imgOriginalScene)
        imgOriginalScene, license = searching(imgOriginalScene, loop)
        #imgOriginalScene = imutils.detransform(imgOriginalScene)

        cv2.waitKey(0)
    cv2.waitKey(0)
    cv2.destroyAllWindows()
    return
Esempio n. 5
0
def alpr(frame, sess, detection_graph):
    # add knn library for detect chars
    blnKNNTrainingSuccessful = DetectChars.loadKNNDataAndTrainKNN()             # attempt KNN training

    if blnKNNTrainingSuccessful == False:                                       # if KNN training was not successful
        print("\nerror: KNN traning was not successful\n")                      # show error message
        return
    count = 0
    # not very important, just iterating for license array haha
    license = []
    VER = np.zeros(VERIF)
    for x in VER:
        license.append("")
    numlicense = ""
    knn = 0
    loop=True

    # resize the frame and convert it to grayscale
    imgOriginalScene  = imutils.resize(frame)
    imgGrayscale, imgThresh = pp.preprocess(imgOriginalScene)
    #cv2.imshow("threshold", imgThresh)
    #imgOriginalScene = imutils.transform (imgOriginalScene)
    imgOriginalScene, licenses = searching(imgOriginalScene,loop)

    # only save 5 same license each time

    license[count+1] = licenses
    nums = license[VERIF-1]
    if (license[count] == license[count+1]):
        license[count]=license[count+1]
        count = count + 1
    elif (license[count] != license[count+1]):
        coba = license[count+1]
        count = 0
        license[count] = coba
    if count == (VERIF-1):

        '''
        plateAlloc = "       "
        numstring = ""
        numbers = sum(c.isdigit() for c in nums)
        words   = sum(c.isalpha() for c in nums)

        for c in nums:
            numstring.append()
        '''

        global plat
        plat = "         "
        plat = list(plat)
        numstring = ""
        numstring = list(numstring)
        alphastring = ""
        alphastring = list(alphastring)
        numbers = sum(c.isdigit() for c in nums)
        words   = sum(c.isalpha() for c in nums)

        for i in nums:
            #nums = np.array(nums)
            #nums = list(nums)
            if i.isalpha():
                #nums[i] = np.array(nums[i])
                alphastring.append(i)
            elif i.isdigit():
                #nums[i] = np.array(nums[i])
                numstring.append(i)

        print(nums)
        print(numstring)
        print(alphastring)

        #add numbers

        a = 2
        for b in numstring:
            plat[a] = b
            a+=1

        #add front letter(s)

        c = 0
        sumfront = sum(c.isalpha() for c in nums[0:2])
        if (sumfront == 1):
            for d in nums[0:1]:
                plat[c] = d
                c+=1
        elif (sumfront == 2):
            for d in nums[0:2]:
                plat[c] = d
                c+=1

        #add back letter(s)

        e = -3
        sumback = sum(e.isalpha() for e in nums[-3:])
        if (sumback == 1):
            for f in nums[-1:]:
                plat[e] = f
                e+=1
        elif (sumback == 2):
            for f in nums[-2:]:
                plat[e] = f
                e+=1
        elif (sumback == 3):
            for f in nums[-3:]:
                plat[e] = f
                e+=1

        plat = ''.join(plat)

        if (license[VERIF-1] == ""):
            print("no characters were detected\n")
        else:
            #if number license same, not be saved

            if (numlicense == license[VERIF-1]):
                print("still = " + numlicense + "\n")
            elif (len(nums) <= 9 and nums[0] >= 'A' and nums[0] <= 'Z' and numbers <= 4 and words <= 5):

                numlicense = license[VERIF-1]
                print("A new license plate read from image = " + plat + "\n")

                insertdata= data(numlicense)
                if check(numlicense):
                    ts = time.time()
                    timestamp = datetime.datetime.fromtimestamp(ts).strftime('%Y-%m-%d')
                    timestamp2 = datetime.datetime.fromtimestamp(ts).strftime('%H:%M:%S')

                    #Ganti Path sesuai dengan laptop masing2 heheh
                    namefile = "/var/www/html/MonitoringDashboard/hasil_parksystem/"+ license[VERIF-1] + timestamp + timestamp2 + ".png"
                    cv2.imwrite(namefile, imgOriginalScene)

                    #Hapus bagian ini untuk tidak menggunakan sensor dan mengirim mqtt
                    #broker="192.168.8.120"
                    #port=1883
                    #client1= paho.Client("control1")                           #create client object
                    #client1.connect(broker,port)                                 #establish connection
                    #ret= client1.publish("xiaomi/to/write",'{"cmd": "write",  "model": "plug",  "sid": "158d0002365abb",  "data": {"status": "on"}}')
                    # broker="192.168.1.151"
                    # port=1883
                    # client1= paho.Client("control1")                           #create client object
                    # client1.connect(broker,port)                                 #establish connection
                    # client1.publish("alpr/mqtt","0")
                    # os.system('spd-say "Welcome to Graha Sumber Prima Elektronik"')
        count = 0

    cv2.putText(imgOriginalScene,"Press 's' to save frame to be 'save.png', for calibrating",(10,30),cv2.FONT_HERSHEY_SIMPLEX, 0.5,(255,255,255),1,bottomLeftOrigin = False)

    cv2.rectangle(imgOriginalScene,((int(imgOriginalScene.shape[1]/2-230)),(int(imgOriginalScene.shape[0]/2-80))),((int(imgOriginalScene.shape[1]/2+230)),(int(imgOriginalScene.shape[0]/2+80))),SCALAR_GREEN,3)

    try:
        return dict(imgOriginalScenes=imgOriginalScene)
    except:
        return {}
Esempio n. 6
0
from flask import Flask
from flask import render_template
from flask import request
from flask import session
from flask import redirect
from flask import url_for
from database import data
import json
import os
import re

app = Flask(__name__)
app.secret_key = os.urandom(16)

# Set database
db = data()


# Convert a list to a comma separated string
def li_to_str(li):
    st = ""
    if li != []:
        st = ', '.join(li)
    return st


# Process user's answers to form
def processform(f):
    selections = {}

    for key in f.keys():
Esempio n. 7
0
import unittest
import match
import copy
import random
from database import data

# mode TEST
TEST = False

d = data()
guyprefers = d.guyprefers
galprefers = d.galprefers
capacity = d.capacity


class TestDeCase(unittest.TestCase):
    """Test la fiabilite du match"""
    def setUp(self):
        self.engaged, self.rejected = match.matchmaker(guyprefers, galprefers, capacity)
    
    def test_1_check_stability(self):
        """Verifie que la stabilite du match"""
        self.assertTrue(match.check(self.engaged, guyprefers, galprefers))
        print('Engagement stability check PASSED'
          if match.check(self.engaged, guyprefers, galprefers) else 'Engagement stability check FAILED')
        print()

    def test_2_check_instability(self):
        """Verifie l'instabilite du match si l'on introduit volontairement une erreur"""
        for _ in range(10):
            gals = self.engaged.keys()
Esempio n. 8
0
def main():
    # argument for input video/image/calibration
    ap = argparse.ArgumentParser()
    ap.add_argument("-v", "--video", help="path to video file")

    ap.add_argument("-i", "--image", help="Path to the image")

    ap.add_argument("-c", "--calibration", help="image or video or camera")
    args = vars(ap.parse_args())

    if args.get("calibration", True):
        imgOriginalScene = cv2.imread(args["calibration"])
        if imgOriginalScene is None:
            print("Please check again the path of image or argument !")

        imgOriginalScene = imutils.resize(imgOriginalScene, width=640)
        cal.calibration(imgOriginalScene)
        return

    if args.get("video", True):
        camera = cv2.VideoCapture(args["video"])
        if camera is None:
            print("   Please check again the path of video or argument !")
        loop = True

    elif args.get("image", True):
        imgOriginalScene = cv2.imread("tes_plat_indo/B6703WJF.jpg")
        if imgOriginalScene is None:
            print("   Please check again the path of image or argument !")
        loop = False
    else:
        #  0 digunakan untuk camera laptop, 1 untuk camera external
        camera = cv2.VideoCapture(0)
        loop = True

    # add knn library for detect chars
    blnKNNTrainingSuccessful = DetectChars.loadKNNDataAndTrainKNN(
    )  # attempt KNN training

    if blnKNNTrainingSuccessful == False:  # if KNN training was not successful
        print(
            "\nerror: KNN traning was not successful\n")  # show error message
        return
    count = 0
    # not very important, just iterating for license array haha
    license = []
    VER = np.zeros(VERIF)
    for x in VER:
        license.append("")
    numlicense = ""
    susi = ""
    knn = 0

    # Looping for Video
    while (loop):
        # grab the current frame
        (grabbed, frame) = camera.read()
        #frame = camera.read()
        if args.get("video") and not grabbed:
            break
        # resize the frame and convert it to grayscale
        imgOriginalScene = imutils.resize(frame)
        imgGrayscale, imgThresh = pp.preprocess(imgOriginalScene)
        cv2.imshow("threshold", imgThresh)
        # imgOriginalScene = imutils.transform (imgOriginalScene)
        imgOriginalScene, licenses = searching(imgOriginalScene, loop)

        # only save 5 same license each time

        license[count + 1] = licenses
        nums = license[VERIF - 1]
        if (license[count] == license[count + 1]):
            license[count] = license[count + 1]
            count = count + 1
        elif (license[count] != license[count + 1]):
            coba = license[count + 1]
            count = 0
            license[count] = coba
        if count == (VERIF - 1):

            global plat
            plat = "         "
            plat = list(plat)
            numstring = ""
            numstring = list(numstring)
            alphastring = ""
            alphastring = list(alphastring)
            numbers = sum(c.isdigit() for c in nums)
            words = sum(c.isalpha() for c in nums)

            for i in nums:
                if i.isalpha():
                    alphastring.append(i)
                elif i.isdigit():
                    numstring.append(i)

            print(nums)
            print(numstring)
            print(alphastring)

            #add numbers

            a = 2
            for b in numstring:
                plat[a] = b
                a += 1

            #add front letter(s)

            c = 0
            sumfront = sum(c.isalpha() for c in nums[0:2])
            if (sumfront == 1):
                for d in nums[0:1]:
                    plat[c] = d
                    c += 1
            elif (sumfront == 2):
                for d in nums[0:2]:
                    plat[c] = d
                    c += 1

            #add back letter(s)

            e = -3
            sumback = sum(e.isalpha() for e in nums[-3:])
            if (sumback == 1):
                for f in nums[-1:]:
                    plat[e] = f
                    e += 1
            elif (sumback == 2):
                for f in nums[-2:]:
                    plat[e] = f
                    e += 1
            elif (sumback == 3):
                for f in nums[-3:]:
                    plat[e] = f
                    e += 1

            plat = ''.join(plat)

            if (license[VERIF - 1] == ""):
                print("no characters were detected\n")
            else:
                #if number license same, not be saved
                if (numlicense == license[VERIF - 1]):
                    print("still = " + numlicense + "\n")
                elif (len(nums) <= 9 and nums[0] >= 'A' and nums[0] <= 'Z'
                      and numbers <= 4 and words <= 5):

                    numlicense = license[VERIF - 1]
                    print(license[VERIF - 1])
                    print(numlicense)
                    print("A new license plate read from image = " + plat +
                          "\n")

                    insertdata = data(numlicense)
                    print(insertdata)
                    if check(numlicense):
                        ts = time.time()
                        timestamp = datetime.datetime.fromtimestamp(
                            ts).strftime('%Y-%m-%d')
                        timestamp2 = datetime.datetime.fromtimestamp(
                            ts).strftime('%H:%M:%S')

                        #Ganti Path sesuai dengan laptop masing2
                        namefile = "/Documents/" + license[
                            VERIF - 1] + timestamp + timestamp2 + ".png"
                        cv2.imwrite(namefile, imgOriginalScene)

            count = 0

        cv2.putText(
            imgOriginalScene,
            "Press 's' to save frame to be 'save.png', for calibrating",
            (10, 30),
            cv2.FONT_HERSHEY_SIMPLEX,
            0.5, (255, 255, 255),
            1,
            bottomLeftOrigin=False)
        #drawRedRectangleAroundPlate(imgOriginalScene, imgOriginalScene)

        #cv2.rectangle(imgOriginalScene,((imgOriginalScene.shape[1]/2-230),(imgOriginalScene.shape[0]/2-80)),((imgOriginalScene.shape[1]/2+230),(imgOriginalScene.shape[0]/2+80)),SCALAR_GREEN,3)
        cv2.rectangle(imgOriginalScene,
                      ((int(imgOriginalScene.shape[1] / 2 - 230)),
                       (int(imgOriginalScene.shape[0] / 2 - 80))),
                      ((int(imgOriginalScene.shape[1] / 2 + 230)),
                       (int(imgOriginalScene.shape[0] / 2 + 80))),
                      SCALAR_GREEN, 3)

        cv2.imshow("imgOriginalScene", imgOriginalScene)

        key = cv2.waitKey(5) & 0xFF
        if key == ord('s'):
            knn = str(knn)
            savefileimg = "calib_knn/img_" + knn + ".png"
            savefileThr = "calib_knn/Thr_" + knn + ".png"
            #cv2.saveimage("save.png", imgOriginalScene)
            cv2.imwrite(savefileimg, frame)
            cv2.imwrite(savefileThr, imgThresh)
            print("image save !")
            knn = int(knn)
            knn = knn + 1
        if key == 27:  # if the 'q' key is pressed, stop the loop
            break
            camera.release()  # cleanup the camera and close any open windows

    # For image only
    if (loop == False):
        imgOriginalScene = imutils.resize(imgOriginalScene, width=2000)
        cv2.imshow("original", imgOriginalScene)
        imgGrayscale, imgThresh = pp.preprocess(imgOriginalScene)
        cv2.imshow("threshold", imgThresh)
        #imgOriginalScene = imutils.transform (imgOriginalScene)
        imgOriginalScene, license = searching(imgOriginalScene, loop)
        #imgOriginalScene = imutils.detransform(imgOriginalScene)

        cv2.waitKey(0)
    cv2.waitKey(0)
    cv2.destroyAllWindows()
    return