vij21 commited on
Commit
dcb3bcc
·
1 Parent(s): ba75753

Upload 2 files

Browse files
Files changed (2) hide show
  1. Run .ipynb +100 -0
  2. signlanguage.ipynb +0 -0
Run .ipynb ADDED
@@ -0,0 +1,100 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ {
2
+ "cells": [
3
+ {
4
+ "cell_type": "code",
5
+ "execution_count": 6,
6
+ "id": "4e992bb3",
7
+ "metadata": {},
8
+ "outputs": [
9
+ {
10
+ "ename": "KeyboardInterrupt",
11
+ "evalue": "",
12
+ "output_type": "error",
13
+ "traceback": [
14
+ "\u001b[1;31m---------------------------------------------------------------------------\u001b[0m",
15
+ "\u001b[1;31mKeyboardInterrupt\u001b[0m Traceback (most recent call last)",
16
+ "Cell \u001b[1;32mIn[6], line 29\u001b[0m\n\u001b[0;32m 26\u001b[0m cap \u001b[38;5;241m=\u001b[39m cv2\u001b[38;5;241m.\u001b[39mVideoCapture(\u001b[38;5;241m0\u001b[39m)\n\u001b[0;32m 28\u001b[0m \u001b[38;5;28;01mwhile\u001b[39;00m \u001b[38;5;28;01mTrue\u001b[39;00m:\n\u001b[1;32m---> 29\u001b[0m ret, frame \u001b[38;5;241m=\u001b[39m \u001b[43mcap\u001b[49m\u001b[38;5;241;43m.\u001b[39;49m\u001b[43mread\u001b[49m\u001b[43m(\u001b[49m\u001b[43m)\u001b[49m \u001b[38;5;66;03m# Read a frame from the webcam\u001b[39;00m\n\u001b[0;32m 31\u001b[0m \u001b[38;5;28;01mif\u001b[39;00m \u001b[38;5;129;01mnot\u001b[39;00m ret:\n\u001b[0;32m 32\u001b[0m \u001b[38;5;28;01mcontinue\u001b[39;00m\n",
17
+ "\u001b[1;31mKeyboardInterrupt\u001b[0m: "
18
+ ]
19
+ }
20
+ ],
21
+ "source": [
22
+ "import cv2\n",
23
+ "import numpy as np\n",
24
+ "from tensorflow import keras\n",
25
+ "from keras.preprocessing.image import img_to_array\n",
26
+ "\n",
27
+ "# Load your pre-trained model\n",
28
+ "model = keras.models.load_model('D:\\Trained model\\sign_language_model.h5') \n",
29
+ "\n",
30
+ "# Define a mapping from class indices to text labels\n",
31
+ "class_to_text_mapping = {\n",
32
+ " 0: 'A',\n",
33
+ " 1: 'B',\n",
34
+ " # Add more mapping as needed\n",
35
+ "}\n",
36
+ "\n",
37
+ "# Create a function to preprocess frames from the camera\n",
38
+ "def preprocess_frame(frame):\n",
39
+ " # Resize and normalize the frame\n",
40
+ " frame = cv2.resize(frame, (200, 200))\n",
41
+ " frame = frame.astype(\"float\") / 255.0\n",
42
+ " frame = img_to_array(frame)\n",
43
+ " frame = np.expand_dims(frame, axis=0)\n",
44
+ " return frame\n",
45
+ "\n",
46
+ "# Start capturing video from your webcam (you may need to change the index depending on your setup)\n",
47
+ "cap = cv2.VideoCapture(0)\n",
48
+ "\n",
49
+ "while True:\n",
50
+ " ret, frame = cap.read() # Read a frame from the webcam\n",
51
+ "\n",
52
+ " if not ret:\n",
53
+ " continue\n",
54
+ "\n",
55
+ " # Preprocess the frame\n",
56
+ " processed_frame = preprocess_frame(frame)\n",
57
+ "\n",
58
+ " # Make a prediction\n",
59
+ " predictions = model.predict(processed_frame)\n",
60
+ " predicted_class = np.argmax(predictions)\n",
61
+ "\n",
62
+ " # Get the corresponding text label\n",
63
+ " predicted_text = class_to_text_mapping[predicted_class]\n",
64
+ "\n",
65
+ " # Display the frame and predicted text on the screen\n",
66
+ " cv2.putText(frame, predicted_text, (10, 30), cv2.FONT_HERSHEY_SIMPLEX, 1, (0, 255, 0), 2)\n",
67
+ " cv2.imshow('Sign Language Detection', frame)\n",
68
+ "\n",
69
+ " # Break the loop if the 'q' key is pressed\n",
70
+ " if cv2.waitKey(1) & 0xFF == ord('q'):\n",
71
+ " break\n",
72
+ "\n",
73
+ "# Release the camera and close the OpenCV windows\n",
74
+ "cap.release()\n",
75
+ "cv2.destroyAllWindows()\n"
76
+ ]
77
+ }
78
+ ],
79
+ "metadata": {
80
+ "kernelspec": {
81
+ "display_name": "Python 3 (ipykernel)",
82
+ "language": "python",
83
+ "name": "python3"
84
+ },
85
+ "language_info": {
86
+ "codemirror_mode": {
87
+ "name": "ipython",
88
+ "version": 3
89
+ },
90
+ "file_extension": ".py",
91
+ "mimetype": "text/x-python",
92
+ "name": "python",
93
+ "nbconvert_exporter": "python",
94
+ "pygments_lexer": "ipython3",
95
+ "version": "3.10.13"
96
+ }
97
+ },
98
+ "nbformat": 4,
99
+ "nbformat_minor": 5
100
+ }
signlanguage.ipynb ADDED
The diff for this file is too large to render. See raw diff