Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Görüntü işleme #123

Open
Erobaba6565 opened this issue Dec 5, 2024 · 0 comments
Open

Görüntü işleme #123

Erobaba6565 opened this issue Dec 5, 2024 · 0 comments

Comments

@Erobaba6565
Copy link

import cv2
import numpy as np

Kamerayı başlat

camera = cv2.VideoCapture(0)

Şekilleri algılamak için sürekli döngü

while True:
# Kameradan görüntü al
ret, frame = camera.read()
if not ret:
break

# Görüntüyü gri tonlamaya çevir
gray = cv2.cvtColor(frame, cv2.COLOR_BGR2GRAY)

# Görüntüyü eşikle
_, threshold = cv2.threshold(gray, 127, 255, cv2.THRESH_BINARY)

# Şekilleri algılamak için kontürleri bul
contours, _ = cv2.findContours(threshold, cv2.RETR_TREE, cv2.CHAIN_APPROX_SIMPLE)

for contour in contours:
    # Kontur alanını kontrol ederek küçük nesneleri yok say
    if cv2.contourArea(contour) > 500:
        approx = cv2.approxPolyDP(contour, 0.02 * cv2.arcLength(contour, True), True)
        x = approx.ravel()[0]
        y = approx.ravel()[1]

        # Şekli belirle
        if len(approx) == 3:
            cv2.putText(frame, "Ucgen", (x, y), cv2.FONT_HERSHEY_SIMPLEX, 1, (0, 255, 0))
        elif len(approx) == 4:
            cv2.putText(frame, "Dikdortgen", (x, y), cv2.FONT_HERSHEY_SIMPLEX, 1, (0, 255, 0))
        elif len(approx) > 4:
            cv2.putText(frame, "Daire", (x, y), cv2.FONT_HERSHEY_SIMPLEX, 1, (0, 255, 0))

# Görüntüyü ekranda göster
cv2.imshow("Kamera", frame)

# 'q' tuşuna basıldığında çık
if cv2.waitKey(1) & 0xFF == ord('q'):
    break

camera.release()
cv2.destroyAllWindows()

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant