Skip to content

Görüntü işleme #123

@Erobaba6565

Description

@Erobaba6565

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()

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions