Created
March 12, 2025 18:50
-
-
Save samuellangajr/e06e1ab3f59693ad8e2e8e8827ab8faf to your computer and use it in GitHub Desktop.
Escreva um script que use a biblioteca OpenCV para aplicar detecção de bordas em uma imagem de tráfego e exiba o resultado.
This file contains hidden or 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) | |
| # Aplicar o filtro de Canny para detecção de bordas | |
| bordas = cv2.Canny(imagem_cinza, 100, 200) | |
| # Exibir a imagem original e a imagem com as bordas detectadas | |
| plt.figure(figsize=(10, 5)) | |
| # Exibir imagem original | |
| plt.subplot(1, 2, 1) | |
| plt.imshow(cv2.cvtColor(imagem, cv2.COLOR_BGR2RGB)) | |
| plt.title('Imagem Original') | |
| plt.axis('off') | |
| # Exibir imagem com bordas detectadas | |
| plt.subplot(1, 2, 2) | |
| plt.imshow(bordas, cmap='gray') | |
| plt.title('Detecção de Bordas') | |
| plt.axis('off') | |
| plt.tight_layout() | |
| plt.show() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment