Skip to content

Commit

Permalink
Merge pull request #2102 from NitkarshChourasia/testing
Browse files Browse the repository at this point in the history
add: Luhn algorithm
  • Loading branch information
geekcomputers authored Jan 17, 2024
2 parents abddc12 + a13646d commit 96cf1a1
Show file tree
Hide file tree
Showing 12 changed files with 354 additions and 119 deletions.
85 changes: 50 additions & 35 deletions Face and eye Recognition/face_recofnation_first.py
Original file line number Diff line number Diff line change
@@ -1,37 +1,52 @@
## Name - Soumyajit Chakraborty
## place - kolkata
## date - 10 / 08 / 2020

import cv2 as cv

face_cascade = cv.CascadeClassifier("..\libs\haarcascade_frontalface_default.xml")
face_cascade_eye = cv.CascadeClassifier("..\libs\haarcascade_eye.xml")
# face_glass = cv.CascadeClassifier('..\libs\haarcascade_eye_tree_eyeglasses.xml')

cap = cv.VideoCapture(0)
while cap.isOpened():

falg, img = cap.read() # start reading the camera output i mean frames
# cap.read() returning a bool value and a frame onject type value

gray = cv.cvtColor(
img, cv.COLOR_BGR2GRAY
) # converting to grayscale image to perform smoother
faces = face_cascade.detectMultiScale(
img, 1.1, 7
) # we use detectMultiscale library function to detect the predefined structures of a face
eyes = face_cascade_eye.detectMultiScale(img, 1.1, 7)
# using for loops we are trying to read each and every frame and map
for (x, y, w, h) in faces:
cv.rectangle(img, (x, y), (x + w, y + h), (0, 255, 0), 1)

for (a, b, c, d) in eyes:
cv.rectangle(img, (a, b), (a + c, b + d), (255, 0, 0), 1)

cv.imshow("img", img)
c = cv.waitKey(1)
if c == ord("q"):
break

cv.release()
cv.destroyAllWindows()

def detect_faces_and_eyes():
"""
Detects faces and eyes in real-time using the webcam.
Press 'q' to exit the program.
"""
# Load the pre-trained classifiers for face and eye detection
face_cascade = cv.CascadeClassifier(r"..\libs\haarcascade_frontalface_default.xml")
eye_cascade = cv.CascadeClassifier(r"..\libs\haarcascade_eye.xml")

# Open the webcam
cap = cv.VideoCapture(0)

while cap.isOpened():
# Read a frame from the webcam
flag, img = cap.read()

# Convert the frame to grayscale for better performance
gray = cv.cvtColor(img, cv.COLOR_BGR2GRAY)

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

# Detect eyes in the frame
eyes = eye_cascade.detectMultiScale(gray, scaleFactor=1.1, minNeighbors=7)

# Draw rectangles around faces and eyes
for x, y, w, h in faces:
cv.rectangle(img, (x, y), (x + w, y + h), (0, 255, 0), 1)

for a, b, c, d in eyes:
cv.rectangle(img, (a, b), (a + c, b + d), (255, 0, 0), 1)

# Display the resulting frame
cv.imshow("Face and Eye Detection", img)

# Check for the 'q' key to exit the program
key = cv.waitKey(1)
if key == ord("q"):
break

# Release the webcam and close all windows
cap.release()
cv.destroyAllWindows()


if __name__ == "__main__":
# Call the main function
detect_faces_and_eyes()
27 changes: 18 additions & 9 deletions Face and eye Recognition/gesture_control.py
Original file line number Diff line number Diff line change
@@ -1,18 +1,27 @@
import cv2 as cv

# import numpy as np
# Read the image in grayscale
img = cv.imread(r"..\img\hand1.jpg", cv.IMREAD_GRAYSCALE)

img = cv.imread("..\img\hand1.jpg", 0)
flag, frame = cv.threshold(img, 70, 255, cv.THRESH_BINARY)
# Apply thresholding to create a binary image
_, thresholded = cv.threshold(img, 70, 255, cv.THRESH_BINARY)

contor, _ = cv.findContours(frame.copy(), cv.RETR_TREE, cv.CHAIN_APPROX_SIMPLE)
# Find contours in the binary image
contours, _ = cv.findContours(thresholded.copy(), cv.RETR_TREE, cv.CHAIN_APPROX_SIMPLE)

hull = [cv.convexHull(c) for c in contor]
# Convex Hull for each contour
convex_hulls = [cv.convexHull(contour) for contour in contours]

final = cv.drawContours(img, hull, -1, (0, 0, 0))
cv.imshow("original_image", img)
cv.imshow("thres", frame)
cv.imshow("final_hsv", final)
# Draw contours and convex hulls on the original image
original_with_contours = cv.drawContours(img.copy(), contours, -1, (0, 0, 0), 2)
original_with_convex_hulls = cv.drawContours(img.copy(), convex_hulls, -1, (0, 0, 0), 2)

# Display the images
cv.imshow("Original Image", img)
cv.imshow("Thresholded Image", thresholded)
cv.imshow("Contours", original_with_contours)
cv.imshow("Convex Hulls", original_with_convex_hulls)

# Wait for a key press and close windows
cv.waitKey(0)
cv.destroyAllWindows()
5 changes: 2 additions & 3 deletions Password Generator/requirements.txt
Original file line number Diff line number Diff line change
@@ -1,3 +1,2 @@
string
secrets
random
colorama==0.4.4
inquirer==2.7.0
19 changes: 0 additions & 19 deletions Print_List_of_Even_Numbers.py

This file was deleted.

31 changes: 0 additions & 31 deletions Print_List_of_Odd_Numbers.py

This file was deleted.

136 changes: 136 additions & 0 deletions cli_master/cli_master.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,136 @@
import os
import sys
from pprint import pprint

import sys

sys.path.append(os.path.realpath("."))
import inquirer # noqa

# Take authentication input from the user
questions = [
inquirer.List(
"authentication", # This is the key
message="Choose an option",
choices=["Login", "Sign up", "Exit"],
),
]
answers = inquirer.prompt(questions)


# Just making pipelines
class Validation:
def phone_validation():
# Think over how to make a validation for phone number?
pass

def email_validation():
pass

def password_validation():
pass

def username_validation():
pass

def country_validation():
# All the countries in the world???
# JSON can be used.
# Download the file

def state_validation():
# All the states in the world??
# The state of the selected country only.
pass

def city_validation():
# All the cities in the world??
# JSON can be used.
pass


# Have an option to go back.
# How can I do it?
if answers["authentication"] == "Login":
print("Login")
questions = [
inquirer.Text(
"username",
message="What's your username?",
validate=Validation.login_username,
),
inquirer.Text(
"password",
message="What's your password?",
validate=Validation.login_password,
),
]


elif answers["authentication"] == "Sign up":
print("Sign up")

questions = [
inquirer.Text(
"name",
message="What's your first name?",
validate=Validation.fname_validation,
),
inquirer.Text(
"surname",
message="What's your last name(surname)?, validate=Validation.lname), {name}?",
),
inquirer.Text(
"phone",
message="What's your phone number",
validate=Validation.phone_validation,
),
inquirer.Text(
"email",
message="What's your email",
validate=Validation.email_validation,
),
inquirer.Text(
"password",
message="What's your password",
validate=Validation.password_validation,
),
inquirer.Text(
"password",
message="Confirm your password",
validate=Validation.password_confirmation,
),
inquirer.Text(
"username",
message="What's your username",
validate=Validation.username_validation,
),
inquirer.Text(
"country",
message="What's your country",
validate=Validation.country_validation,
),
inquirer.Text(
"state",
message="What's your state",
validate=Validation.state_validation,
),
inquirer.Text(
"city",
message="What's your city",
validate=Validation.city_validation,
),
inquirer.Text(
"address",
message="What's your address",
validate=Validation.address_validation,
),
]
# Also add optional in the above thing.
# Have string manipulation for the above thing.
# How to add authentication of google to command line?
elif answers["authentication"] == "Exit":
print("Exit")
sys.exit()

pprint(answers)
9 changes: 9 additions & 0 deletions cli_master/database_import_countries.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
import requests

url = "https://api.countrystatecity.in/v1/countries"

headers = {"X-CSCAPI-KEY": "API_KEY"}

response = requests.request("GET", url, headers=headers)

print(response.text)
62 changes: 62 additions & 0 deletions cli_master/validation_page.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
import re

def phone_validation(phone_number):
# Match a typical US phone number format (xxx) xxx-xxxx
pattern = re.compile(r'^\(\d{3}\) \d{3}-\d{4}$')
return bool(pattern.match(phone_number))

# Example usage:
phone_number_input = input("Enter phone number: ")
if phone_validation(phone_number_input):
print("Phone number is valid.")
else:
print("Invalid phone number.")

def email_validation(email):
# Basic email format validation
pattern = re.compile(r'^[a-zA-Z0-9_.+-]+@[a-zA-Z0-9-]+\.[a-zA-Z0-9-.]+$')
return bool(pattern.match(email))

# Example usage:
email_input = input("Enter email address: ")
if email_validation(email_input):
print("Email address is valid.")
else:
print("Invalid email address.")


def password_validation(password):
# Password must be at least 8 characters long and contain at least one digit
return len(password) >= 8 and any(char.isdigit() for char in password)

# Example usage:
password_input = input("Enter password: ")
if password_validation(password_input):
print("Password is valid.")
else:
print("Invalid password.")


def username_validation(username):
# Allow only alphanumeric characters and underscores
return bool(re.match('^[a-zA-Z0-9_]+$', username))

# Example usage:
username_input = input("Enter username: ")
if username_validation(username_input):
print("Username is valid.")
else:
print("Invalid username.")


def country_validation(country):
# Example: Allow only alphabetical characters and spaces
return bool(re.match('^[a-zA-Z ]+$', country))

# Example usage:
country_input = input("Enter country name: ")
if country_validation(country_input):
print("Country name is valid.")
else:
print("Invalid country name.")

Loading

0 comments on commit 96cf1a1

Please sign in to comment.