예제 #1
0
def f4():
    digit4 = time[0:24, 41:50]
    write_digit4=cv2.imwrite(path+"/images_written/digit4.jpg",digit4)
    read = cv2.imread(path+"/images_written/digit4.jpg",cv2.IMREAD_GRAYSCALE)
    resized = cv2.resize(read, (28, 28), interpolation=cv2.INTER_LINEAR)
    write_digit4 = cv2.imwrite(path+"/images_written/digit4.jpg", resized)
    binary_convert(path+"/images_written/digit4.jpg")
    center(path+"/images_written/digit4.jpg", "digit4.jpg")
    digit4 = cv2.imread(path+"/images_written/digit4.jpg", cv2.IMREAD_GRAYSCALE)
    digit4 = cv2.resize(digit4, (28, 28), interpolation=cv2.INTER_LINEAR)

    digit4 = digit4.reshape(1, 28, 28, 1)
    predict4 = digit_model.predict(digit4)
    actual_prediction4=np.argmax(predict4, axis=1)

    actual_prediction[3] = actual_prediction4

    return
예제 #2
0
def f3():
    digit3 = time[0:24, 32:40]
    write_digit3=cv2.imwrite(path+"/images_written/digit3.jpg",digit3)
    read = cv2.imread(path+"/images_written/digit3.jpg",cv2.IMREAD_GRAYSCALE)
    resized = cv2.resize(read, (28, 28), interpolation=cv2.INTER_LINEAR)
    write_digit3 = cv2.imwrite(path+"/images_written/digit3.jpg", resized)
    binary_convert(path+"/images_written/digit3.jpg")
    center(path+"/images_written/digit3.jpg", "digit3.jpg")
    digit3 = cv2.imread(path+"/images_written/digit3.jpg", cv2.IMREAD_GRAYSCALE)
    digit3 = cv2.resize(digit3, (28, 28), interpolation=cv2.INTER_LINEAR)

    digit3 = digit3.reshape(1, 28, 28, 1)
    predict3 = digit_model.predict(digit3)
    actual_prediction3=np.argmax(predict3, axis=1)

    actual_prediction[2] = actual_prediction3

    return
예제 #3
0
def f2():
    digit2 = time[0:24, 19:28]
    write_digit2=cv2.imwrite(path+"/images_written/digit2.jpg",digit2)
    read = cv2.imread(path+"/images_written/digit2.jpg",cv2.IMREAD_GRAYSCALE)
    resized = cv2.resize(read, (28, 28), interpolation=cv2.INTER_LINEAR)
    write_digit2 = cv2.imwrite(path+"/images_written/digit2.jpg", resized)
    binary_convert(path+"/images_written/digit2.jpg")
    center(path+"/images_written/digit2.jpg", "digit2.jpg")
    digit2 = cv2.imread(path+"/images_written/digit2.jpg", cv2.IMREAD_GRAYSCALE)
    digit2 = cv2.resize(digit2, (28, 28), interpolation=cv2.INTER_LINEAR)

    digit2 = digit2.reshape(1, 28, 28, 1)
    predict2 = digit_model.predict(digit2)
    actual_prediction2=np.argmax(predict2, axis=1)

    actual_prediction[1] = actual_prediction2

    return
예제 #4
0
def f1():
    digit1 = time[0:24, 10:19]
    write_digit1=cv2.imwrite(path+"/images_written/digit1.jpg",digit1)
    read = cv2.imread(path+"/images_written/digit1.jpg",cv2.IMREAD_GRAYSCALE)
    resized = cv2.resize(read, (28, 28), interpolation=cv2.INTER_LINEAR)
    write_digit1 = cv2.imwrite(path+"/images_written/digit1.jpg", resized)
    binary_convert(path+"/images_written/digit1.jpg")
    center(path+"/images_written/digit1.jpg", "digit1.jpg")
    digit1 = cv2.imread(path+"/images_written/digit1.jpg", cv2.IMREAD_GRAYSCALE)
    digit1 = cv2.resize(digit1, (28, 28), interpolation=cv2.INTER_LINEAR)

    digit1 = digit1.reshape(1, 28, 28, 1)
    predict1 = digit_model.predict(digit1)
    actual_prediction1=np.argmax(predict1, axis=1)

    actual_prediction[0] = actual_prediction1

    return
예제 #5
0
             (255, 255, 0), 2)
    #Adicionando linha para 30px abaixo da geral
    cv2.line(frame, (xy1[0], posL + offset), (xy2[0], posL + offset),
             (255, 255, 0), 2)
    #Contador para diferenciar as pessoas
    i = 0
    #Percorendo o array do contorno
    for cntrs in contours:
        #Calculando X, Y, a largura e a altura
        (x, y, w, h) = cv2.boundingRect(cntrs)
        #Calculando a área
        area = cv2.contourArea(cntrs)
        #Criando um filtro da área
        if int(area) > 2500:
            #Calculando o centro do retangulo
            centro = center(x, y, w, h)
            #Definindo o id da pessoa com base na quantidade de pessoas na imagem
            cv2.putText(frame, str(i), (x + 5, y + 15),
                        cv2.FONT_HERSHEY_SIMPLEX, 0.5, (0, 255, 255), 2)
            #Circulo no meio do quadrado
            cv2.circle(frame, centro, 4, (0, 0, 255), -1)
            #Retangulo ao redor do objeto
            cv2.rectangle(frame, (x, y), (x + w, y + h), (0, 255, 0), 2)

            if len(detects) <= i:
                detects.append([])
            if centro[1] > posL - offset and centro[1] < posL + offset:
                detects[i].append(centro)
            else:
                detects[i].clear()
            #Passando um valor, caso exista algo na imagem
예제 #6
0
def process_video():
    # print("f**k");input()

    timefromfe=request.data.decode('UTF-8')

    currentframe=convert2(timefromfe)*framerate


    cap.set(cv2.CAP_PROP_POS_FRAMES,currentframe)

    success, frame = cap.read()
    if success == False:
        print(success)

    original_frame=cv2.imwrite(path+"/images_written/frametest.jpg",frame)   ## save current frame
    read_orig=cv2.imread(path+"/images_written/frametest.jpg")
    time = read_orig[55:80, 930:990]
    colon = time[0:24, 28:32]
    write_colon=cv2.imwrite(path+"/images_written/colon_video.jpg",colon) ## save colon position to predict
    binary_convert_colon(path+"/images_written/colon_video.jpg")
    read_bw_colon = cv2.imread(path+"/images_written/colon_video.jpg", cv2.IMREAD_GRAYSCALE)
    colon_resized = cv2.resize(read_bw_colon, (28, 28), interpolation=cv2.INTER_LINEAR)
    colon_reshaped = colon_resized.reshape(1, 28, 28, 1)
    predictions = model.predict(colon_reshaped)
    actual_predictions=np.argmax(predictions, axis=1)
    if actual_predictions[0]==1:
        t1 = Thread(target=f1)
        t2 = Thread(target=f2)
        t3 = Thread(target=f3)
        t4 = Thread(target=f4)

        t1.start()
        t2.start()
        t3.start()
        t4.start()


        ##Predict first digit in format ##:##
        digit1 = time[0:24, 10:19]
        write_digit1=cv2.imwrite(path+"/images_written/digit1.jpg",digit1)
        read = cv2.imread(path+"/images_written/digit1.jpg",cv2.IMREAD_GRAYSCALE)
        resized = cv2.resize(read, (28, 28), interpolation=cv2.INTER_LINEAR)
        write_digit1 = cv2.imwrite(path+"/images_written/digit1.jpg", resized)
        binary_convert(path+"/images_written/digit1.jpg")
        center(path+"/images_written/digit1.jpg", "digit1.jpg")
        digit1 = cv2.imread(path+"/images_written/digit1.jpg", cv2.IMREAD_GRAYSCALE)
        digit1 = cv2.resize(digit1, (28, 28), interpolation=cv2.INTER_LINEAR)

        digit1 = digit1.reshape(1, 28, 28, 1)
        predict1 = digit_model.predict(digit1)
        actual_prediction1=np.argmax(predict1, axis=1)

#         #Predict second digit in format ##:##
        digit2 = time[0:24, 19:28]
        write_digit2=cv2.imwrite(path+"/images_written/digit2.jpg",digit2)
        read = cv2.imread(path+"/images_written/digit2.jpg",cv2.IMREAD_GRAYSCALE)
        resized = cv2.resize(read, (28, 28), interpolation=cv2.INTER_LINEAR)
        write_digit2 = cv2.imwrite(path+"/images_written/digit2.jpg", resized)
        binary_convert(path+"/images_written/digit2.jpg")
        center(path+"/images_written/digit2.jpg", "digit2.jpg")
        digit2 = cv2.imread(path+"/images_written/digit2.jpg", cv2.IMREAD_GRAYSCALE)
        digit2 = cv2.resize(digit2, (28, 28), interpolation=cv2.INTER_LINEAR)

        digit2 = digit2.reshape(1, 28, 28, 1)
        predict2 = digit_model.predict(digit2)
        actual_prediction2=np.argmax(predict2, axis=1)

#         #Predict third digit in format ##:##
        digit3 = time[0:24, 32:40]
        write_digit3=cv2.imwrite(path+"/images_written/digit3.jpg",digit3)
        read = cv2.imread(path+"/images_written/digit3.jpg",cv2.IMREAD_GRAYSCALE)
        resized = cv2.resize(read, (28, 28), interpolation=cv2.INTER_LINEAR)
        write_digit3 = cv2.imwrite(path+"/images_written/digit3.jpg", resized)
        binary_convert(path+"/images_written/digit3.jpg")
        center(path+"/images_written/digit3.jpg", "digit3.jpg")
        digit3 = cv2.imread(path+"/images_written/digit3.jpg", cv2.IMREAD_GRAYSCALE)
        digit3 = cv2.resize(digit3, (28, 28), interpolation=cv2.INTER_LINEAR)

        digit3 = digit3.reshape(1, 28, 28, 1)
        predict3 = digit_model.predict(digit3)
        actual_prediction3=np.argmax(predict3, axis=1)

#         #Predict fourth digit in format ##:##
        digit4 = time[0:24, 41:50]
        write_digit4=cv2.imwrite(path+"/images_written/digit4.jpg",digit4)
        read = cv2.imread(path+"/images_written/digit4.jpg",cv2.IMREAD_GRAYSCALE)
        resized = cv2.resize(read, (28, 28), interpolation=cv2.INTER_LINEAR)
        write_digit4 = cv2.imwrite(path+"/images_written/digit4.jpg", resized)
        binary_convert(path+"/images_written/digit4.jpg")
        center(path+"/images_written/digit4.jpg", "digit4.jpg")
        digit4 = cv2.imread(path+"/images_written/digit4.jpg", cv2.IMREAD_GRAYSCALE)
        digit4 = cv2.resize(digit4, (28, 28), interpolation=cv2.INTER_LINEAR)

        digit4 = digit4.reshape(1, 28, 28, 1)
        predict4 = digit_model.predict(digit4)
        actual_prediction4=np.argmax(predict4, axis=1)

        t1.join()
        t2.join()
        t3.join()
        t4.join()

        time_game=str(actual_prediction1[0])+str(actual_prediction2[0])+":"+str(actual_prediction3[0])+str(actual_prediction4[0])


        return {"time":time_game}
    return {"game started": False}
예제 #7
0
def services(data):
    c.center(data.getComunalServices())
    s.serv(data.getHouseHold(), data.getEntities())
    kn.knoweledge(data.getGeneralCitizen())