Untitled
unknown
plain_text
a month ago
5.2 kB
3
Indexable
Never
import cv2 import numpy as np import os import random import time # Kullanıcı tarafından belirlenen parametreler speed_level = 1 object_count = 6 display_duration = 60 # Türev parametreler canvas_w, canvas_h = 1100, 600 object_size = 100 object_spacing = 10 emoji_folder = 'emojiler/' feedback_folder = 'D.Y/' background_color = (255, 255, 255) frame_color = (211, 211, 211) # Hız ayarları speed_settings = { 1: 750, 2: 500, 3: 250 } # Kullanıcı seçimine göre hız speed = speed_settings[speed_level] # Emojileri yükleyen fonksiyon def load_emojis(emoji_folder): emojis = [] for file_name in os.listdir(emoji_folder): if file_name.endswith('.png'): emoji_path = os.path.join(emoji_folder, file_name) img = cv2.imread(emoji_path, cv2.IMREAD_UNCHANGED) if img is not None and img.shape[2] == 4: emojis.append(img) else: print(f"Failed to load: {file_name}") return emojis # Resmi tuval üzerine bindirme fonksiyonu def overlay_image(background, img, position): x, y = position h, w = img.shape[:2] if y + h > background.shape[0] or x + w > background.shape[1]: return alpha_img = img[:, :, 3] / 255.0 alpha_bg = 1.0 - alpha_img for c in range(0, 3): background[y:y+h, x:x+w, c] = (alpha_img * img[:, :, c] + alpha_bg * background[y:y+h, x:x+w, c]) # Kullanıcı seçim kontrolü ve geri bildirim fonksiyonu def check_selection(selected_index, correct_index, selected_emojis, question): if selected_index == correct_index: feedback_img = cv2.imread(os.path.join(feedback_folder, 'dogru.png'), cv2.IMREAD_UNCHANGED) correct = True else: feedback_img = cv2.imread(os.path.join(feedback_folder, 'yanlis.png'), cv2.IMREAD_UNCHANGED) correct = False feedback_frame = np.full((canvas_h, canvas_w, 3), background_color, dtype=np.uint8) overlay_image(feedback_frame, feedback_img, ((canvas_w - feedback_img.shape[1]) // 2, (canvas_h - feedback_img.shape[0]) // 2)) if not correct: correct_img = selected_emojis[correct_index] overlay_image(feedback_frame, correct_img, ((canvas_w - correct_img.shape[1]) // 2, canvas_h - correct_img.shape[0] - 50)) cv2.imshow("Feedback", feedback_frame) cv2.waitKey(2000) cv2.destroyWindow("Feedback") # Rastgele soru ve seçenekleri gösteren fonksiyon def ask_question(selected_emojis): questions = [ "Hangi nesne yanındaydı?", "İlk nesne neydi?", "Son nesne neydi?", "Ekrana en çok gelen nesne neydi?", "İlk nesnenin sağında ne vardı?", "Son nesnenin solunda ne vardı?" ] question = random.choice(questions) correct_index = random.randint(0, len(selected_emojis) - 1) question_frame = np.full((canvas_h, canvas_w, 3), background_color, dtype=np.uint8) cv2.putText(question_frame, question, (50, 50), cv2.FONT_HERSHEY_SIMPLEX, 1, (0, 0, 0), 2, cv2.LINE_AA) for i, emoji in enumerate(selected_emojis): resized_emoji = cv2.resize(emoji, (object_size, object_size), interpolation=cv2.INTER_AREA) x = 100 + i * (object_size + 50) y = canvas_h // 2 overlay_image(question_frame, resized_emoji, (x, y)) cv2.imshow("Question", question_frame) selected_index = cv2.waitKey(0) - ord('1') # Kullanıcının tuşa basmasını bekler (1, 2, 3, ...) cv2.destroyWindow("Question") check_selection(selected_index, correct_index, selected_emojis, question) # Emojileri gösteren fonksiyon def emoji_display(): emojis = load_emojis(emoji_folder) if not emojis: print("Failed to load emojis!") return start_time = time.time() end_time = start_time + display_duration shown_emojis = [] while time.time() < end_time: frame = np.full((canvas_h, canvas_w, 3), background_color, dtype=np.uint8) selected_emojis = random.sample(emojis, object_count) shown_emojis.extend(selected_emojis) frame_height = object_size + 2 * object_spacing frame_width = (object_size + object_spacing) * object_count - object_spacing start_x = (canvas_w - frame_width) // 2 start_y = (canvas_h - frame_height) // 2 cv2.rectangle(frame, (start_x, start_y), (start_x + frame_width, start_y + frame_height), frame_color, -1) for i, emoji in enumerate(selected_emojis): resized_emoji = cv2.resize(emoji, (object_size, object_size), interpolation=cv2.INTER_AREA) x = start_x + i * (object_size + object_spacing) y = start_y + object_spacing overlay_image(frame, resized_emoji, (x, y)) cv2.imshow("Emoji Display", frame) if cv2.waitKey(speed) & 0xFF == ord('q'): cv2.destroyAllWindows() return cv2.destroyAllWindows() ask_question(shown_emojis) emoji_display()
Leave a Comment