├── README.md ├── adlandirma.py ├── vericekme.py ├── main.py └── simple_facerec.py /README.md: -------------------------------------------------------------------------------- 1 | 2 | # Terör Arananlar Uygulaması 3 | 4 | EGM'nin www.terorarananlar.pol.tr sitesinde bulunan terör suçlularını kamera veya videodan tespit eden ve bilgilerini getiren yüz tanıma uygulamasıdır. 5 | 6 | ## Özellikler 🛠️ 7 | 8 | - EGM'nin Terör Arananlar Sitesinden Veri Çekme 9 | - Kameradan Anlık Yüz Tespiti 10 | - Videodan Yüz Tespiti 11 | - Doğrulama ve Tanıma 12 | 13 | 14 | ## Ekler ➕ 15 | 16 | Ben bu projeyi Terör Suçlularını tespit etmek üzere kullandım. Sizler görselleri ve içeriği değiştirerek farklı amaçlar için kullanabilirsiniz. 17 | 18 | 19 | ## Açıklamalı Kod Haritası 📌 20 | 21 | ![Uygulama Ekran Görüntüsü](https://drive.google.com/uc?export=view&id=1UPkokEH-NlQhiod3O1QK44plQY2Hm8zG) 22 | 23 | 24 | -------------------------------------------------------------------------------- /adlandirma.py: -------------------------------------------------------------------------------- 1 | #Dosya isimlerinizi türkçe karakterlere uygun hale getirmek için bu kodu çalıştırabilirsiniz 2 | import os 3 | 4 | def replace_turkish_characters(directory): 5 | # Türkçe karakterlerin yerine geçecek İngilizce karakterlerin sözlüğü 6 | turkish_to_english = { 7 | 'ı': 'i', 8 | 'ğ': 'g', 9 | 'ü': 'u', 10 | 'ş': 's', 11 | 'ö': 'o', 12 | 'ç': 'c', 13 | 'İ': 'I', 14 | 'Ğ': 'G', 15 | 'Ü': 'U', 16 | 'Ş': 'S', 17 | 'Ö': 'O', 18 | 'Ç': 'C' 19 | } 20 | 21 | # Klasördeki her dosya için işlem yap 22 | for filename in os.listdir(directory): 23 | # Dosya adında Türkçe karakter varsa 24 | if any(char in turkish_to_english.keys() for char in filename): 25 | # Yeni dosya adını oluştur 26 | new_filename = ''.join(turkish_to_english.get(char, char) for char in filename) 27 | # Eski dosyanın adını yeni adla değiştir 28 | os.rename(os.path.join(directory, filename), os.path.join(directory, new_filename)) 29 | 30 | # Klasördeki resimlerin bulunduğu dizini belirt 31 | directory = "images/" 32 | # Türkçe karakterleri İngilizce karakterlerle değiştir 33 | replace_turkish_characters(directory) 34 | -------------------------------------------------------------------------------- /vericekme.py: -------------------------------------------------------------------------------- 1 | #Data.json dosyasından veri çekmek için bu kodu çalıştırabilirsiniz. 2 | 3 | import os 4 | import json 5 | import urllib3 6 | import requests 7 | 8 | 9 | def download_and_save_image(data): 10 | adi = data["Adi"] 11 | soyadi = data["Soyadi"] 12 | t_orgut_adi = data["TOrgutAdi"] 13 | t_kategori_adi = data["TKategoriAdi"] 14 | ilk_gorsel_url = "https://www.terorarananlar.pol.tr" + data["IlkGorselURL"] 15 | urllib3.disable_warnings() 16 | #Bütün kategorileri çekmek için bu kısımı aktif edin 17 | #response = requests.get(ilk_gorsel_url, verify=False) 18 | 19 | #Kategorisine göre filtrelemek için bu kısımı aktif edin 20 | if t_kategori_adi == "kırmızı": 21 | response = requests.get(ilk_gorsel_url, verify=False) 22 | 23 | # İlk görselin adını oluştur 24 | dosya_adi = f"{adi} {soyadi}, {t_orgut_adi}, {t_kategori_adi}.jpeg" 25 | 26 | #Terör örgütlerinden isimlerinde bulunan '/' sembolünü hata vermemesi için '_' ile değiştir 27 | dosya_adi = dosya_adi.replace("/", "_") 28 | 29 | 30 | 31 | # İndirme başarılıysa 32 | if response.status_code == 200: 33 | # Görseli kaydet 34 | with open(dosya_adi, "wb") as f: 35 | f.write(response.content) 36 | print(f"{dosya_adi} başarıyla kaydedildi.") 37 | else: 38 | print("Görsel indirilemedi.") 39 | 40 | 41 | # JSON dosyasını oku 42 | with open("data.json", "r", encoding="utf-8") as f: 43 | veri = json.load(f) 44 | 45 | # Her bir girdi için işlem yap 46 | for item in veri: 47 | download_and_save_image(item) 48 | -------------------------------------------------------------------------------- /main.py: -------------------------------------------------------------------------------- 1 | import cv2 2 | from simple_facerec import SimpleFacerec 3 | 4 | 5 | 6 | 7 | #Dosyalardan yüz encode 8 | sfr = SimpleFacerec() 9 | sfr.load_encoding_images("images/") 10 | 11 | #Kameradan yüz tespiti için bu kısmı aktif edin 12 | #cap = cv2.VideoCapture(0) 13 | #cap.set(cv2.CAP_PROP_FRAME_WIDTH, 1920) 14 | #cap.set(cv2.CAP_PROP_FRAME_HEIGHT, 1080) 15 | 16 | #Videodan yüz tespiti için bu kısmı aktif edin 17 | cap = cv2.VideoCapture("video1.mp4") 18 | 19 | 20 | while True: 21 | ret, frame = cap.read() 22 | 23 | #Yüz tespiti 24 | face_locations, face_names = sfr.detect_known_faces(frame) 25 | for face_loc, name in zip(face_locations, face_names): 26 | y1, x2, y2, x1 = face_loc[0], face_loc[1], face_loc[2], face_loc[3] 27 | 28 | if "," in name: 29 | # İsim metnini virgülle böl 30 | name_parts = name.split(',') 31 | isim = name_parts[0] 32 | isim = isim.split(' ') 33 | 34 | #Aranması var ise çerçeveyi kırmızı yap 35 | color = (0, 0, 255) 36 | cv2.rectangle(frame, (x1, y1), (x2, y2), (color), 4) 37 | 38 | cv2.rectangle(frame, (15, y1-20), (350 , y1+80), (0, 0, 0), cv2.FILLED) 39 | cv2.rectangle(frame, (x1, y2 - 35), (x2, y2), (color), cv2.FILLED) 40 | cv2.putText(frame, "Aranan", (x1 + 6, y2 - 10), cv2.FONT_HERSHEY_DUPLEX, 1, (0, 0, 0), 2) 41 | cv2.putText(frame, "Adi Soyadi: " + name_parts[0], (20, y1), cv2.FONT_HERSHEY_COMPLEX, 0.7, (255, 255, 255), 1) 42 | cv2.putText(frame, "Orgut: " + name_parts[1], (20, y1+35), cv2.FONT_HERSHEY_COMPLEX, 0.7, (255, 255, 255), 1) 43 | cv2.putText(frame, "Aranma Kodu: ", (20, y1+70), cv2.FONT_HERSHEY_COMPLEX, 0.7, (255, 255, 255), 1) 44 | cv2.putText(frame, name_parts[2], (190, y1+70), cv2.FONT_HERSHEY_COMPLEX, 0.7, (0, 0, 255), 1) 45 | 46 | # Tespit edilen kişinin resmini göster 47 | img_path = "images/" + name + ".jpeg" 48 | img = cv2.imread(img_path) 49 | if img is not None: 50 | # Resmi kare boyutuna getir 51 | img = cv2.resize(img, (70, 100)) 52 | 53 | # Resmi kameradan gelen görüntüye7 yerleştir 54 | frame[y1+105:y1+105+img.shape[0], 20:20+img.shape[1]] = img 55 | 56 | else: 57 | # Çerçeve ve rengi 58 | color = (0, 200, 0) 59 | cv2.rectangle(frame, (x1, y1), (x2, y2), (color), 4) 60 | 61 | cv2.imshow("Frame", frame) 62 | 63 | key = cv2.waitKey(1) 64 | if key == ord('q'): 65 | break 66 | 67 | cap.release() 68 | cv2.destroyAllWindows() -------------------------------------------------------------------------------- /simple_facerec.py: -------------------------------------------------------------------------------- 1 | import face_recognition 2 | import cv2 3 | import os 4 | import glob 5 | import numpy as np 6 | 7 | class SimpleFacerec: 8 | def __init__(self): 9 | self.known_face_encodings = [] 10 | self.known_face_names = [] 11 | 12 | # Resize frame for a faster speed 13 | self.frame_resizing = 0.25 14 | 15 | def load_encoding_images(self, images_path): 16 | """ 17 | Load encoding images from path 18 | :param images_path: 19 | :return: 20 | """ 21 | # Load Images 22 | images_path = glob.glob(os.path.join(images_path, "*.*")) 23 | 24 | print("{} encoding images found.".format(len(images_path))) 25 | sayac = 0 26 | # Store image encoding and names 27 | for img_path in images_path: 28 | img = cv2.imread(img_path) 29 | rgb_img = cv2.cvtColor(img, cv2.COLOR_BGR2RGB) 30 | 31 | # Get the filename only from the initial file path. 32 | basename = os.path.basename(img_path) 33 | (filename, ext) = os.path.splitext(basename) 34 | # Get encoding 35 | try: 36 | sayac +=1 37 | img_encoding = face_recognition.face_encodings(rgb_img)[0] 38 | except IndexError: 39 | print("Yüz Verisi Bulunamadı", img_path) 40 | #Yüz verisi bulunamayan görsellerin kaldırılmaması için bu kısmı pasif hale getirin. 41 | os.remove(img_path) 42 | print("Resim Kaldırıldı") 43 | sayac +=1 44 | continue 45 | 46 | # Store file name and file encoding 47 | self.known_face_encodings.append(img_encoding) 48 | self.known_face_names.append(filename) 49 | print("Encoding images loaded") 50 | 51 | def detect_known_faces(self, frame): 52 | small_frame = cv2.resize(frame, (0, 0), fx=self.frame_resizing, fy=self.frame_resizing) 53 | # Find all the faces and face encodings in the current frame of video 54 | # Convert the image from BGR color (which OpenCV uses) to RGB color (which face_recognition uses) 55 | rgb_small_frame = cv2.cvtColor(small_frame, cv2.COLOR_BGR2RGB) 56 | face_locations = face_recognition.face_locations(rgb_small_frame) 57 | face_encodings = face_recognition.face_encodings(rgb_small_frame, face_locations) 58 | 59 | face_names = [] 60 | for face_encoding in face_encodings: 61 | # See if the face is a match for the known face(s) 62 | matches = face_recognition.compare_faces(self.known_face_encodings, face_encoding) 63 | name = "Unknown" 64 | 65 | 66 | 67 | 68 | # # If a match was found in known_face_encodings, just use the first one. 69 | # if True in matches: 70 | # first_match_index = matches.index(True) 71 | # name = known_face_names[first_match_index] 72 | 73 | # Or instead, use the known face with the smallest distance to the new face 74 | face_distances = face_recognition.face_distance(self.known_face_encodings, face_encoding) 75 | best_match_index = np.argmin(face_distances) 76 | if matches[best_match_index]: 77 | name = self.known_face_names[best_match_index] 78 | face_names.append(name) 79 | 80 | # Convert to numpy array to adjust coordinates with frame resizing quickly 81 | face_locations = np.array(face_locations) 82 | face_locations = face_locations / self.frame_resizing 83 | return face_locations.astype(int), face_names 84 | --------------------------------------------------------------------------------