Upload 12 files
Browse filesFiles changed (12)
- .idea/.gitignoreAdded+3
- .idea/T24.imlAdded+8
- .idea/inspectionProfiles/Project_Default.xmlAdded+15
- .idea/inspectionProfiles/profiles_settings.xmlAdded+6
- .idea/misc.xmlAdded+4
- .idea/modules.xmlAdded+8
- .idea/workspace.xmlAdded+66
- .ipynb_checkpoints/test-checkpoint.pyAdded+95
- Model/keras_model.h5Added+3
- Model/labels.txtAdded+3
- dataCollection.pyAdded+62
- test.pyAdded+95
123# Default ignored files
/shelf/
/workspace.xml12345678<?xml version="1.0" encoding="UTF-8"?>
<module type="PYTHON_MODULE" version="4">
<component name="NewModuleRootManager">
<content url="file://$MODULE_DIR$" />
<orderEntry type="inheritedJdk" />
<orderEntry type="sourceFolder" forTests="false" />
</component>
</module>123456789101112131415<component name="InspectionProjectProfileManager"> <profile version="1.0"> <option name="myName" value="Project Default" /> <inspection_tool class="PyPep8NamingInspection" enabled="true" level="WEAK WARNING" enabled_by_default="true"> <option name="ignoredErrors"> <list> <option value="N803" /> <option value="N802" /> <option value="N806" /> <option value="N801" /> </list> </option> </inspection_tool> </profile></component>123456<component name="InspectionProjectProfileManager"> <settings> <option name="USE_PROJECT_PROFILE" value="false" /> <version value="1.0" /> </settings></component>1234<?xml version="1.0" encoding="UTF-8"?>
<project version="4">
<component name="ProjectRootManager" version="2" project-jdk-name="Python 3.11" project-jdk-type="Python SDK" />
</project>12345678<?xml version="1.0" encoding="UTF-8"?>
<project version="4">
<component name="ProjectModuleManager">
<modules>
<module fileurl="file://$PROJECT_DIR$/.idea/T24.iml" filepath="$PROJECT_DIR$/.idea/T24.iml" />
</modules>
</component>
</project>123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566<?xml version="1.0" encoding="UTF-8"?>
<project version="4">
<component name="AutoImportSettings">
<option name="autoReloadType" value="SELECTIVE" />
</component>
<component name="ChangeListManager">
<list default="true" id="15e16f15-f7a0-47bd-8da7-9e3e2bf12e47" name="Changes" comment="" />
<option name="SHOW_DIALOG" value="false" />
<option name="HIGHLIGHT_CONFLICTS" value="true" />
<option name="HIGHLIGHT_NON_ACTIVE_CHANGELIST" value="false" />
<option name="LAST_RESOLUTION" value="IGNORE" />
</component>
<component name="MarkdownSettingsMigration">
<option name="stateVersion" value="1" />
</component>
<component name="ProjectId" id="2l1D3W1d2Nr45X1uRVePz8Qnu8H" />
<component name="ProjectViewState">
<option name="hideEmptyMiddlePackages" value="true" />
<option name="showLibraryContents" value="true" />
</component>
<component name="PropertiesComponent">{ "keyToString": { "RunOnceActivity.OpenProjectViewOnStart": "true", "RunOnceActivity.ShowReadmeOnStart": "true", "last_opened_file_path": "D:/SEBASTIAN GEORGE/S5/f/EEg", "settings.editor.selected.configurable": "com.jetbrains.python.configuration.PyActiveSdkModuleConfigurable" }}</component>
<component name="RunManager">
<configuration name="dataCollection" type="PythonConfigurationType" factoryName="Python" nameIsGenerated="true">
<module name="T24" />
<option name="INTERPRETER_OPTIONS" value="" />
<option name="PARENT_ENVS" value="true" />
<envs>
<env name="PYTHONUNBUFFERED" value="1" />
</envs>
<option name="SDK_HOME" value="" />
<option name="WORKING_DIRECTORY" value="$PROJECT_DIR$" />
<option name="IS_MODULE_SDK" value="true" />
<option name="ADD_CONTENT_ROOTS" value="true" />
<option name="ADD_SOURCE_ROOTS" value="true" />
<option name="SCRIPT_NAME" value="D:\SEBASTIAN GEORGE\S5\f\T24\dataCollection.py" />
<option name="PARAMETERS" value="" />
<option name="SHOW_COMMAND_LINE" value="false" />
<option name="EMULATE_TERMINAL" value="false" />
<option name="MODULE_MODE" value="false" />
<option name="REDIRECT_INPUT" value="false" />
<option name="INPUT_FILE" value="" />
<method v="2" />
</configuration>
</component>
<component name="SpellCheckerSettings" RuntimeDictionaries="0" Folders="0" CustomDictionaries="0" DefaultDictionary="application-level" UseSingleDictionary="true" transferred="true" />
<component name="SvnConfiguration">
<configuration>C:\Users\user\AppData\Roaming\Subversion</configuration>
</component>
<component name="TaskManager">
<task active="true" id="Default" summary="Default task">
<changelist id="15e16f15-f7a0-47bd-8da7-9e3e2bf12e47" name="Changes" comment="" />
<created>1724338491973</created>
<option name="number" value="Default" />
<option name="presentableId" value="Default" />
<updated>1724338491973</updated>
</task>
<servers />
</component>
</project>1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495import cv2
from cvzone.HandTrackingModule import HandDetector
from cvzone.ClassificationModule import Classifier
import numpy as np
import math
import pyttsx3
from collections import deque
# Initialize the text-to-speech engine
engine = pyttsx3.init()
voices = engine.getProperty('voices')
engine.setProperty('voice', voices[1].id)
rate = engine.getProperty('rate')
engine.setProperty('rate', 125)
cap = cv2.VideoCapture(0)
detector = HandDetector(maxHands=1)
classifier = Classifier("Model/keras_model.h5", "Model/labels.txt")
offset = 20
imgSize = 300
labels = ["A", "B", "C"]
# Deque to store the last few predictions
prediction_history = deque(maxlen=3)
last_prediction = None
while True:
try:
success, img = cap.read()
if not success:
print("Failed to capture image")
continue
imgOutput = img.copy()
hands, img = detector.findHands(img)
if hands:
hand = hands[0]
x, y, w, h = hand['bbox']
imgWhite = np.ones((imgSize, imgSize, 3), np.uint8) * 255
try:
imgCrop = img[y - offset:y + h + offset, x - offset:x + w + offset]
if imgCrop.size == 0:
raise ValueError("Empty image crop detected")
imgCropShape = imgCrop.shape
aspectRatio = h / w
if aspectRatio > 1:
k = imgSize / h
wCal = math.ceil(k * w)
imgResize = cv2.resize(imgCrop, (wCal, imgSize))
imgResizeShape = imgResize.shape
wGap = math.ceil((imgSize - wCal) / 2)
imgWhite[:, wGap:wCal + wGap] = imgResize
else:
k = imgSize / w
hCal = math.ceil(k * h)
imgResize = cv2.resize(imgCrop, (imgSize, hCal))
imgResizeShape = imgResize.shape
hGap = math.ceil((imgSize - hCal) / 2)
imgWhite[hGap:hCal + hGap, :] = imgResize
try:
prediction, index = classifier.getPrediction(imgWhite, draw=False)
print(prediction, index)
prediction_history.append(labels[index])
if len(prediction_history) == 3 and len(set(prediction_history)) == 1 and prediction_history[1]!=last_prediction:
last_prediction=labels[index]
engine.say(labels[index])
engine.runAndWait()
prediction_history = deque(maxlen=3)
except Exception as e:
print("Error in classifier prediction:", e)
except cv2.error as e:
print("OpenCV error:", e)
except ValueError as e:
print(e)
cv2.rectangle(imgOutput, (x - offset, y - offset - 50),
(x - offset + 90, y - offset - 50 + 50), (255, 0, 255), cv2.FILLED)
cv2.putText(imgOutput, labels[index], (x, y - 26), cv2.FONT_HERSHEY_COMPLEX, 1.7, (255, 255, 255), 2)
cv2.rectangle(imgOutput, (x - offset, y - offset),
(x + w + offset, y + h + offset), (255, 0, 255), 4)
cv2.imshow("ImageCrop", imgCrop)
cv2.imshow("ImageWhite", imgWhite)
cv2.imshow("Image", imgOutput)
cv2.waitKey(1)
except Exception as e:
print("Unexpected error:", e)123version https://git-lfs.github.com/spec/v1oid sha256:69f7c8e1dcb153a962e7b6048597b74f2fe8b559f2bb9b970b2c50bccc92312asize 24534321230 A1 B2 C1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162import cv2
from cvzone.HandTrackingModule import HandDetector
import numpy as np
import math
import time
cap = cv2.VideoCapture(0)
detector = HandDetector(maxHands=1)
offset = 20
imgSize = 300
folder = "Data/Hi"
counter = 0
while True:
success, img = cap.read()
if not success:
print("Failed to capture image")
continue
hands, img = detector.findHands(img)
if hands:
hand = hands[0]
x, y, w, h = hand['bbox']
imgWhite = np.ones((imgSize, imgSize, 3), np.uint8) * 255
try:
imgCrop = img[y - offset:y + h + offset, x - offset:x + w + offset]
if imgCrop.size == 0:
raise ValueError("Empty image crop detected")
imgCropShape = imgCrop.shape
aspectRatio = h / w
if aspectRatio > 1:
k = imgSize / h
wCal = math.ceil(k * w)
imgResize = cv2.resize(imgCrop, (wCal, imgSize))
imgResizeShape = imgResize.shape
wGap = math.ceil((imgSize - wCal) / 2)
imgWhite[:, wGap:wCal + wGap] = imgResize
else:
k = imgSize / w
hCal = math.ceil(k * h)
imgResize = cv2.resize(imgCrop, (imgSize, hCal))
imgResizeShape = imgResize.shape
hGap = math.ceil((imgSize - hCal) / 2)
imgWhite[hGap:hCal + hGap, :] = imgResize
cv2.imshow("ImageCrop", imgCrop)
cv2.imshow("ImageWhite", imgWhite)
except cv2.error as e:
print("OpenCV error:", e)
except ValueError as e:
print(e)
cv2.imshow("Image", img)
key = cv2.waitKey(1)
if key == ord("s"):
if imgCrop.size == 0:
continue
counter += 1
cv2.imwrite(f'{folder}/Image_{time.time()}.jpg', imgWhite)
print(counter)1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495import cv2
from cvzone.HandTrackingModule import HandDetector
from cvzone.ClassificationModule import Classifier
import numpy as np
import math
import pyttsx3
from collections import deque
# Initialize the text-to-speech engine
engine = pyttsx3.init()
voices = engine.getProperty('voices')
engine.setProperty('voice', voices[1].id)
rate = engine.getProperty('rate')
engine.setProperty('rate', 125)
cap = cv2.VideoCapture(0)
detector = HandDetector(maxHands=1)
classifier = Classifier("Model/keras_model.h5", "Model/labels.txt")
offset = 20
imgSize = 300
labels = ["A", "B", "C"]
# Deque to store the last few predictions
prediction_history = deque(maxlen=3)
last_prediction = None
while True:
try:
success, img = cap.read()
if not success:
print("Failed to capture image")
continue
imgOutput = img.copy()
hands, img = detector.findHands(img)
if hands:
hand = hands[0]
x, y, w, h = hand['bbox']
imgWhite = np.ones((imgSize, imgSize, 3), np.uint8) * 255
try:
imgCrop = img[y - offset:y + h + offset, x - offset:x + w + offset]
if imgCrop.size == 0:
raise ValueError("Empty image crop detected")
imgCropShape = imgCrop.shape
aspectRatio = h / w
if aspectRatio > 1:
k = imgSize / h
wCal = math.ceil(k * w)
imgResize = cv2.resize(imgCrop, (wCal, imgSize))
imgResizeShape = imgResize.shape
wGap = math.ceil((imgSize - wCal) / 2)
imgWhite[:, wGap:wCal + wGap] = imgResize
else:
k = imgSize / w
hCal = math.ceil(k * h)
imgResize = cv2.resize(imgCrop, (imgSize, hCal))
imgResizeShape = imgResize.shape
hGap = math.ceil((imgSize - hCal) / 2)
imgWhite[hGap:hCal + hGap, :] = imgResize
try:
prediction, index = classifier.getPrediction(imgWhite, draw=False)
print(prediction, index)
prediction_history.append(labels[index])
if len(prediction_history) == 3 and len(set(prediction_history)) == 1 and prediction_history[1]!=last_prediction:
last_prediction=labels[index]
engine.say(labels[index])
engine.runAndWait()
prediction_history = deque(maxlen=3)
except Exception as e:
print("Error in classifier prediction:", e)
except cv2.error as e:
print("OpenCV error:", e)
except ValueError as e:
print(e)
cv2.rectangle(imgOutput, (x - offset, y - offset - 50),
(x - offset + 90, y - offset - 50 + 50), (255, 0, 255), cv2.FILLED)
cv2.putText(imgOutput, labels[index], (x, y - 26), cv2.FONT_HERSHEY_COMPLEX, 1.7, (255, 255, 255), 2)
cv2.rectangle(imgOutput, (x - offset, y - offset),
(x + w + offset, y + h + offset), (255, 0, 255), 4)
cv2.imshow("ImageCrop", imgCrop)
cv2.imshow("ImageWhite", imgWhite)
cv2.imshow("Image", imgOutput)
cv2.waitKey(1)
except Exception as e:
print("Unexpected error:", e).idea/.gitignoreAdded+3
.idea/T24.imlAdded+8
.idea/inspectionProfiles/Project_Default.xmlAdded+15
.idea/inspectionProfiles/profiles_settings.xmlAdded+6
.idea/misc.xmlAdded+4
.idea/modules.xmlAdded+8
.idea/workspace.xmlAdded+66
.ipynb_checkpoints/test-checkpoint.pyAdded+95
Model/keras_model.h5Added+3
Model/labels.txtAdded+3
dataCollection.pyAdded+62
test.pyAdded+95