Skip to content

Commit

Permalink
Updated code
Browse files Browse the repository at this point in the history
  • Loading branch information
memidhun committed Oct 4, 2024
1 parent 1c73095 commit f066061
Show file tree
Hide file tree
Showing 17 changed files with 194 additions and 73 deletions.
Binary file not shown.
3 changes: 3 additions & 0 deletions Machine Learning/Model/Pet/labels.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
0 DOG
1 RABBIT
2 NEUTRAL
61 changes: 61 additions & 0 deletions Machine Learning/Model/Pet/pet.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
from keras.models import load_model # TensorFlow is required for Keras to work
import cv2 # Install opencv-python
import numpy as np

# Disable scientific notation for clarity
np.set_printoptions(suppress=True)

# Load the model
model = load_model(r"C:\Users\Midhun Mathew\Desktop\Test\Machine Learning\Model\Pet\keras_model.h5", compile=False)

# Load the labels
class_names = open(r"C:\Users\Midhun Mathew\Desktop\Test\Machine Learning\Model\Pet\labels.txt", "r").readlines()

# CAMERA can be 0 or 1 based on default camera of your computer
camera = cv2.VideoCapture(0)

while True:
# Grab the webcamera's image.
ret, image = camera.read()

# Resize the raw image into (224-height,224-width) pixels
resized_image = cv2.resize(image, (224, 224), interpolation=cv2.INTER_AREA)

# Make the image a numpy array and reshape it to the model's input shape.
input_image = np.asarray(resized_image, dtype=np.float32).reshape(1, 224, 224, 3)

# Normalize the image array
input_image = (input_image / 127.5) - 1

# Predict using the model
prediction = model.predict(input_image)
index = np.argmax(prediction)
class_name = class_names[index].strip()
confidence_score = prediction[0][index]

# Print prediction and confidence score
print(f"Class: {class_name}, Confidence Score: {str(np.round(confidence_score * 100))[:-2]}%")

# Draw the frame and label based on prediction
if index == 0: # DOG
cv2.rectangle(image, (0, 0), (image.shape[1], image.shape[0]), (0, 0, 255), 10) # Red frame
cv2.putText(image, "DOG", (10, 50), cv2.FONT_HERSHEY_SIMPLEX, 2, (0, 0, 255), 3) # Red text
elif index == 1: # RABBIT
cv2.rectangle(image, (0, 0), (image.shape[1], image.shape[0]), (0, 255, 0), 10) # Green frame
cv2.putText(image, "RABBIT", (10, 50), cv2.FONT_HERSHEY_SIMPLEX, 2, (0, 255, 0), 3) # Green text
elif index == 2: # NEUTRAL
pass # No frame, no text

# Display the frame with the label
cv2.imshow("Webcam Image", image)

# Listen to the keyboard for presses.
keyboard_input = cv2.waitKey(1)

# 27 is the ASCII for the ESC key.
if keyboard_input == 27:
break

# Release the camera and close the window
camera.release()
cv2.destroyAllWindows()
File renamed without changes.
79 changes: 79 additions & 0 deletions Machine Learning/Model/face_intruder.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,79 @@
import cv2
import datetime
import os
import time

# Load pre-trained data on face frontals from OpenCV (Haar cascade algorithm)
face_cascade = cv2.CascadeClassifier(cv2.data.haarcascades + 'haarcascade_frontalface_default.xml')

# Function to trigger an alert and save the photo
def trigger_alert_and_save(frame):
# Print the alert message
print("Intrusion Alert! Face Detected!")

# Get the current time to name the photo uniquely
timestamp = datetime.datetime.now().strftime("%Y-%m-%d_%H-%M-%S")

# Create a directory to save the photos if it doesn't exist
if not os.path.exists('intrusion_photos'):
os.makedirs('intrusion_photos')

# Save the frame as a photo
file_name = f"intrusion_photos/intrusion_{timestamp}.jpg"
cv2.imwrite(file_name, frame)
print(f"Saved photo: {file_name}")

# Start video capture from the default camera (0)
cap = cv2.VideoCapture(0)

# Variables to track timing and last detected faces
last_detected_faces = []
last_photo_time = 0
photo_interval = 5 # Time interval in seconds between photos

while True:
# Read the current frame from the video capture
ret, frame = cap.read()

# Convert the frame to grayscale (Haar cascade requires grayscale)
gray = cv2.cvtColor(frame, cv2.COLOR_BGR2GRAY)

# Detect faces in the frame
faces = face_cascade.detectMultiScale(gray, scaleFactor=1.1, minNeighbors=5, minSize=(30, 30))

# Process detected faces
current_faces = []

for idx, (x, y, w, h) in enumerate(faces):
current_faces.append((x, y, w, h))

# Draw a rectangle around the first face (normal detection)
if idx == 0:
cv2.rectangle(frame, (x, y), (x + w, y + h), (255, 0, 0), 2) # Blue box
cv2.putText(frame, f"Face detected at {datetime.datetime.now()}", (x, y - 10), cv2.FONT_HERSHEY_SIMPLEX, 0.5, (255, 0, 0), 2)

# If a second face is detected, mark as intruder and use a red box
if idx == 1:
cv2.rectangle(frame, (x, y), (x + w, y + h), (0, 0, 255), 2) # Red box for intruder
cv2.putText(frame, "Intruder!", (x, y - 10), cv2.FONT_HERSHEY_SIMPLEX, 0.5, (0, 0, 255), 2)

# Check the time interval to control photo capture frequency
current_time = time.time()
if (x, y, w, h) not in last_detected_faces and (current_time - last_photo_time > photo_interval):
# Trigger intrusion alert and save the photo
trigger_alert_and_save(frame)
last_photo_time = current_time # Update the last photo time

# Update the list of last detected faces
last_detected_faces = current_faces

# Display the frame with detection
cv2.imshow('Intrusion Detection', frame)

# Break the loop if 'q' is pressed
if cv2.waitKey(1) & 0xFF == ord('q'):
break

# Release the capture and close windows
cap.release()
cv2.destroyAllWindows()
File renamed without changes.
2 changes: 0 additions & 2 deletions Machine Learning/Pet Model/labels.txt

This file was deleted.

71 changes: 0 additions & 71 deletions Machine Learning/Pet Model/pet_detect.py

This file was deleted.

Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
1 change: 1 addition & 0 deletions my-key.ssh
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
YPQ94AAtPi34JrtV884vMToikf7WbHdzA1oJfG9pNbWjjgpuHSHM5e3NcKaFX6LYy8yCzuRn96Zl2Pg0WhBI97pnNJRfbp6A5cmz26hDdR0nX0C3WNxa0kBIL1W0Mk2BlTQQ4B87aO40k4s7gGCkhiYnhpk9tJt3GS/rL7o/skjkHIbDhKiMCbNJIjWMFNRFmxIqd2BhiPQi2XQlsQkXmasfc/f0IB05e7paRwNovF+My76Y/L/yfMZHs0Mth2rezUKbq+Z1YIeta3c4HzHhATiJ0kH4gwRYC0QyhEOnhLY6vkw1JmR266r9noJkVE4iWvJE2ujaII46Var8NIMAiywEucGN9yYX31pMX8/HxZeNB/rGTTNTyU5F94oXtjvA/UT+zyLPEGvFWh4s8A+DofUU3NLHEcdPGTRVPnIo9dW4ph5KNI2f5L6S5wl66yTcEBDIrRT2MdoyhPGlxhNPT/ix1tlxcDuxn18VNVInEariWmoNhVQ5h/hTq/TBM99rGDowT2WqxDU7h39kRQyHdEw0c62dtIonQMr102swgrujLj1ptsZOEoJHovw9Y702tr3qgM36091L3J8kZqL0Et/1uo0ZRC8DqypBgN5Le1k4VWJVw2rXsl9MSlmyXtFCaw== Midhun Mathew@Inspiron
49 changes: 49 additions & 0 deletions UserProfile.sshid_rsa
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
-----BEGIN OPENSSH PRIVATE KEY-----
b3BlbnNzaC1rZXktdjEAAAAABG5vbmUAAAAEbm9uZQAAAAAAAAABAAACFwAAAAdzc2gtcn
NhAAAAAwEAAQAAAgEA56Frg6ECq/izTfsowyAzAHH9GAcnb/R6y0FQS0HZhiQx/w8Yah9I
B7+GJzRVA6V+GcQr+h6O8vHA00s4ByybWyLV9xybbRkWVSUFFc+tuna3qP4IpLpNQ1vveA
TGVv9kCFbsZzRfSigN85vz8IWJjdKuEai1opvbe771syDX/kzLWVicWja2dGjf7T8Y9b5j
cCXyAkn/1JSOsA1HfXlZdRAE35BDG7xUgcU7QbU/YFEge9NOMLjboFZsy1okw2IIzmxKOz
Vz7/eCtmkaIS3AHuTvxHJE5MCm88J/4hr4KzV9VSNnXMOkorWREgdr9seG35HEyG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MU9eLhpFSYdyBjwPERTY587
X489civSdxFA0nsSlRi8gZV/6WYNw7n+CxKGnaHybKo+UXtKMe0EnqEmchiPFIdBYjJ+Ay
n2vehQu8E299QjJiH+Fhf+7PQ8Zb0kjx6YdEyKrWwSm/Z1CnW2v35woleWQpU1qWaWWjGh
ADn7cSolx+CVtZH1D4hD23on+8AKslZNPOS9Y0Q169f2cDYm0gSI/6gt4RTpmH0xFcWnex
ksaTPnvl0kcRoCDBrClzC0tw1lMqRggCbUEgCR8BSvXR1vp6LwUU/SuXo5507I9fd60yHz
pUWKyNhzmAiv85AAABAQDufZjCyoACxlrqP7V46TUtswj0ww94OMShYVYbq8yO9n09JYhp
FhtZpLGwSlrM0AnWc3zqrX9gpLf0Yr9dRZZEWkSRwxt9skDQwrB6wpNshTV/8bFvj8vsoa
b60AdfMoCfHORrqBwP4gfJcYydy6ocVLzxQe78rn4ELIpuJTRtQLPf+3l2frAIsseCBRVF
gFnB9mgVZLLZDw14xRIvSe4FTW/3XSKRtM4irg0hFFp5EUTC6Yz9XVMRawAzD3KOtCkDyz
Eo6f+DFoqIqhGTYi5CBuUytRxChcI8cD0lDFaoE8RHyL8/wFIw8ciaHIMF7Aj5L8smVYWq
E5YUufo92DsDAAAAFk1pZGh1biBNYXRoZXdASW5zcGlyb24BAgME
-----END OPENSSH PRIVATE KEY-----
1 change: 1 addition & 0 deletions UserProfile.sshid_rsa.pub
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
ssh-rsa AAAAB3NzaC1yc2EAAAADAQABAAACAQDnoWuDoQKr+LNN+yjDIDMAcf0YBydv9HrLQVBLQdmGJDH/DxhqH0gHv4YnNFUDpX4ZxCv6Ho7y8cDTSzgHLJtbItX3HJttGRZVJQUVz626dreo/gikuk1DW+94BMZW/2QIVuxnNF9KKA3zm/PwhYmN0q4RqLWim9t7vvWzINf+TMtZWJxaNrZ0aN/tPxj1vmNwJfICSf/UlI6wDUd9eVl1EATfkEMbvFSBxTtBtT9gUSB7004wuNugVmzLWiTDYgjObEo7NXPv94K2aRohLcAe5O/EckTkwKbzwn/iGvgrNX1VI2dcw6SitZESB2v2x4bfkcTIZ1Na09+66VNfXxDefA5G12wIZTe9EmA+pbR1yBnD8iyKCG2GrOXDVWxx8ahm9rUmtoU0nh93JPbWMDkdxHC4NgPBI0xFeTsKEuSgZ6GuMe8pciOmCGQPp2LgyInw/1ZkQmgNDzIWCe/ZG2mvTVX87VkwxCsqhLOs7JqSR+u2LEUXugLOtO4DJY+3Kp5TyCDqzzzCju6rZq/X4u/HPYnt5ub/rfMgxwOJdwk8r/dhV0i4HMSN/3BC6lmT7U0Xj8RVVfbVkIrVSALXzysifawt+itfrQDbps3lc2R3LaOOu8AsICPeueUDt8hT6BCsa89ULBsULyLBO2lmHqEGtVXsuYM2oR/AmdkOd4sgqw== Midhun Mathew@Inspiron

0 comments on commit f066061

Please sign in to comment.