djkargil commited on
Commit
2188502
1 Parent(s): 59ef6b4

Upload Project 2.ipynb

Browse files
Files changed (1) hide show
  1. Project 2.ipynb +160 -0
Project 2.ipynb ADDED
@@ -0,0 +1,160 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ {
2
+ "cells": [
3
+ {
4
+ "cell_type": "code",
5
+ "execution_count": 1,
6
+ "id": "28222c2a",
7
+ "metadata": {},
8
+ "outputs": [
9
+ {
10
+ "name": "stdout",
11
+ "output_type": "stream",
12
+ "text": [
13
+ "Requirement already satisfied: opencv-python in c:\\users\\sj992\\anaconda3\\lib\\site-packages (4.8.1.78)\n",
14
+ "Requirement already satisfied: numpy>=1.17.0 in c:\\users\\sj992\\anaconda3\\lib\\site-packages (from opencv-python) (1.23.5)\n",
15
+ "Note: you may need to restart the kernel to use updated packages.\n"
16
+ ]
17
+ }
18
+ ],
19
+ "source": [
20
+ "pip install opencv-python"
21
+ ]
22
+ },
23
+ {
24
+ "cell_type": "code",
25
+ "execution_count": 1,
26
+ "id": "656a8c72",
27
+ "metadata": {},
28
+ "outputs": [],
29
+ "source": [
30
+ "import cv2\n",
31
+ "\n",
32
+ "# Load the pre-trained face detection model\n",
33
+ "face_cascade = cv2.CascadeClassifier(cv2.data.haarcascades + 'haarcascade_frontalface_default.xml')\n",
34
+ "\n",
35
+ "# Function to perform real-time face detection from webcam\n",
36
+ "def detect_faces_webcam():\n",
37
+ " cap = cv2.VideoCapture(0) # 0 corresponds to the default camera (you may need to adjust this value)\n",
38
+ "\n",
39
+ " while True:\n",
40
+ " # Capture frame-by-frame\n",
41
+ " ret, frame = cap.read()\n",
42
+ "\n",
43
+ " # Convert the frame to grayscale\n",
44
+ " gray = cv2.cvtColor(frame, cv2.COLOR_BGR2GRAY)\n",
45
+ "\n",
46
+ " # Detect faces in the frame\n",
47
+ " faces = face_cascade.detectMultiScale(gray, scaleFactor=1.3, minNeighbors=5)\n",
48
+ "\n",
49
+ " # Draw rectangles around the faces\n",
50
+ " for (x, y, w, h) in faces:\n",
51
+ " cv2.rectangle(frame, (x, y), (x+w, y+h), (255, 0, 0), 2)\n",
52
+ "\n",
53
+ " # Display the result\n",
54
+ " cv2.imshow('Face Detection', frame)\n",
55
+ "\n",
56
+ " # Break or exit the loop when 'e' key is pressed\n",
57
+ " if cv2.waitKey(1) & 0xFF == ord('e'):\n",
58
+ " break\n",
59
+ "\n",
60
+ " # Release the webcam and close the window\n",
61
+ " cap.release()\n",
62
+ " cv2.destroyAllWindows()\n",
63
+ "detect_faces_webcam() "
64
+ ]
65
+ },
66
+ {
67
+ "cell_type": "code",
68
+ "execution_count": 26,
69
+ "id": "a8cd511e",
70
+ "metadata": {},
71
+ "outputs": [],
72
+ "source": [
73
+ "import tkinter as tk\n",
74
+ "from tkinter import messagebox\n",
75
+ "import random\n",
76
+ "\n",
77
+ "class FlashcardQuizApp:\n",
78
+ " \n",
79
+ " def __init__(self,root):\n",
80
+ " self.root = root\n",
81
+ " self.root.title(\"Flashcard Quiz App\") \n",
82
+ " self.flashcards = [\n",
83
+ " {\"question\" : \"Currency of india\",\"answer\" : \"rupee\"},\n",
84
+ " {\"question\" : \"president of india\",\"answer\" : \"Modi\"},\n",
85
+ " ]\n",
86
+ " self.question_label = tk.Label(root,text=\"\",font=(\"Times Now Roman\",16))\n",
87
+ " self.answer_entry = tk.Entry(root,font=(\"Times Now Roman\",14))\n",
88
+ " self.submit_button = tk.Button(root,text = \"Submit answer\", command = self.check_answer)\n",
89
+ " self.next_button = tk.Button(root,text = \"Next Question\",command = self.next_question)\n",
90
+ " \n",
91
+ " self.question_label.pack(pady=20)\n",
92
+ " self.answer_entry.pack(pady=10)\n",
93
+ " self.submit_button.pack(pady=10)\n",
94
+ " self.next_button.pack(pady=10)\n",
95
+ "#set variable\n",
96
+ " self.current_flashcard = None\n",
97
+ " self.next_question()\n",
98
+ " \n",
99
+ " def next_question(self):\n",
100
+ " self.current_flashcard = random.choice(self.flashcards)\n",
101
+ " self.question_label.config(text = self.current_flashcard[\"question\"])\n",
102
+ " self.answer_entry.delete(0, tk.END)\n",
103
+ " \n",
104
+ " def check_answer(self):\n",
105
+ " user_answer = self.answer_entry.get().strip().lower()\n",
106
+ " correct_answer = self.current_flashcard[\"answer\"].lower()\n",
107
+ " \n",
108
+ " if user_answer == correct_answer:\n",
109
+ " messagebox.showinfo(\"Correct\",\"Your answer is correct!!\")\n",
110
+ " else:\n",
111
+ " messagebox.showerror(\"Incorrect\",f\"right answer is: {correct_answer}\")\n",
112
+ " \n",
113
+ " self.next_question()\n",
114
+ " \n",
115
+ "if __name__ == \"__main__\":\n",
116
+ " root = tk.Tk()\n",
117
+ " app = FlashcardQuizApp(root)\n",
118
+ " root.mainloop()\n",
119
+ " "
120
+ ]
121
+ },
122
+ {
123
+ "cell_type": "code",
124
+ "execution_count": null,
125
+ "id": "115dfbf0",
126
+ "metadata": {},
127
+ "outputs": [],
128
+ "source": []
129
+ },
130
+ {
131
+ "cell_type": "code",
132
+ "execution_count": null,
133
+ "id": "2f24af3f",
134
+ "metadata": {},
135
+ "outputs": [],
136
+ "source": []
137
+ }
138
+ ],
139
+ "metadata": {
140
+ "kernelspec": {
141
+ "display_name": "Python 3 (ipykernel)",
142
+ "language": "python",
143
+ "name": "python3"
144
+ },
145
+ "language_info": {
146
+ "codemirror_mode": {
147
+ "name": "ipython",
148
+ "version": 3
149
+ },
150
+ "file_extension": ".py",
151
+ "mimetype": "text/x-python",
152
+ "name": "python",
153
+ "nbconvert_exporter": "python",
154
+ "pygments_lexer": "ipython3",
155
+ "version": "3.10.9"
156
+ }
157
+ },
158
+ "nbformat": 4,
159
+ "nbformat_minor": 5
160
+ }