This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import os | |
import numpy as np | |
from tensorflow.keras.preprocessing.image import load_img, img_to_array | |
from sklearn.model_selection import train_test_split | |
from tensorflow.keras.utils import to_categorical | |
import matplotlib.pyplot as plt | |
# Definir o caminho do diretório onde as imagens estão armazenadas | |
image_dir = 'caminho/para/imagens' |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
def contar_veiculos(imagem): | |
# Chama a função pré-treinada para detectar os veículos | |
veiculos_detectados = detectar_veiculos(imagem) | |
# Retorna o número de veículos detectados | |
return len(veiculos_detectados) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import tensorflow as tf | |
from tensorflow.keras import layers, models | |
# Definir a arquitetura da CNN | |
def criar_modelo_cnn(): | |
modelo = models.Sequential() | |
# Primeira camada convolucional | |
modelo.add(layers.Conv2D(32, (3, 3), activation='relu', input_shape=(224, 224, 3))) # Exemplo de imagem de 224x224x3 | |
modelo.add(layers.MaxPooling2D((2, 2))) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
def calcular_velocidade_media(dados): | |
# Inicializar variáveis para somar a distância total e o tempo total | |
distancia_total = 0 | |
tempo_total = 0 | |
# Iterar sobre a lista de dados | |
for dado in dados: | |
distancia_total += dado['distancia'] | |
tempo_total += dado['tempo'] | |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import torch | |
from torchvision import transforms | |
from PIL import Image | |
import matplotlib.pyplot as plt | |
# Função para realizar data augmentation | |
def augmentacao_imagem(imagem): | |
# Definindo uma sequência de transformações | |
transformacao = transforms.Compose([ | |
transforms.RandomRotation(degrees=30), # Rotaciona a imagem até 30 graus |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import torch | |
from torch.utils.data import Dataset, DataLoader | |
from torchvision import transforms | |
from PIL import Image | |
import os | |
# Definir a classe do Dataset personalizado | |
class VehicleDataset(Dataset): | |
def __init__(self, imagens_dir, rotulos_file, transform=None): | |
""" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import cv2 | |
import numpy as np | |
from matplotlib import pyplot as plt | |
# Carregar a imagem de tráfego | |
imagem = cv2.imread('caminho/para/imagem_de_trafego.jpg') | |
# Converter a imagem para escala de cinza | |
imagem_cinza = cv2.cvtColor(imagem, cv2.COLOR_BGR2GRAY) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import pandas as pd | |
from sklearn.model_selection import train_test_split | |
from sklearn.linear_model import LogisticRegression | |
from sklearn.preprocessing import StandardScaler | |
from sklearn.metrics import accuracy_score | |
def prever_congestionamento(df): | |
""" | |
Previsão de congestionamento com base em dados históricos de tráfego. | |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import numpy as np | |
import pandas as pd | |
import matplotlib.pyplot as plt | |
def suavizar_serie_temporal(dados, janela=3): | |
""" | |
Aplica um filtro de suavização (média móvel) a uma série temporal de dados. | |
Args: | |
dados (pd.Series ou list): A série temporal de dados de tráfego. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import numpy as np | |
import cv2 | |
import seaborn as sns | |
import matplotlib.pyplot as plt | |
def gerar_mapa_calor(imagem, coordenadas_veiculos, tamanho_mapa=(500, 500), raio=15): | |
""" | |
Gera um mapa de calor baseado nas coordenadas dos veículos detectados. | |
Args: |
OlderNewer