Skip to content

Commit 96cf1a1

Browse files
Merge pull request #2102 from NitkarshChourasia/testing
add: Luhn algorithm
2 parents abddc12 + a13646d commit 96cf1a1

12 files changed

+354
-119
lines changed
Lines changed: 50 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -1,37 +1,52 @@
1-
## Name - Soumyajit Chakraborty
2-
## place - kolkata
3-
## date - 10 / 08 / 2020
4-
51
import cv2 as cv
62

7-
face_cascade = cv.CascadeClassifier("..\libs\haarcascade_frontalface_default.xml")
8-
face_cascade_eye = cv.CascadeClassifier("..\libs\haarcascade_eye.xml")
9-
# face_glass = cv.CascadeClassifier('..\libs\haarcascade_eye_tree_eyeglasses.xml')
10-
11-
cap = cv.VideoCapture(0)
12-
while cap.isOpened():
13-
14-
falg, img = cap.read() # start reading the camera output i mean frames
15-
# cap.read() returning a bool value and a frame onject type value
16-
17-
gray = cv.cvtColor(
18-
img, cv.COLOR_BGR2GRAY
19-
) # converting to grayscale image to perform smoother
20-
faces = face_cascade.detectMultiScale(
21-
img, 1.1, 7
22-
) # we use detectMultiscale library function to detect the predefined structures of a face
23-
eyes = face_cascade_eye.detectMultiScale(img, 1.1, 7)
24-
# using for loops we are trying to read each and every frame and map
25-
for (x, y, w, h) in faces:
26-
cv.rectangle(img, (x, y), (x + w, y + h), (0, 255, 0), 1)
27-
28-
for (a, b, c, d) in eyes:
29-
cv.rectangle(img, (a, b), (a + c, b + d), (255, 0, 0), 1)
30-
31-
cv.imshow("img", img)
32-
c = cv.waitKey(1)
33-
if c == ord("q"):
34-
break
35-
36-
cv.release()
37-
cv.destroyAllWindows()
3+
4+
def detect_faces_and_eyes():
5+
"""
6+
Detects faces and eyes in real-time using the webcam.
7+
8+
Press 'q' to exit the program.
9+
"""
10+
# Load the pre-trained classifiers for face and eye detection
11+
face_cascade = cv.CascadeClassifier(r"..\libs\haarcascade_frontalface_default.xml")
12+
eye_cascade = cv.CascadeClassifier(r"..\libs\haarcascade_eye.xml")
13+
14+
# Open the webcam
15+
cap = cv.VideoCapture(0)
16+
17+
while cap.isOpened():
18+
# Read a frame from the webcam
19+
flag, img = cap.read()
20+
21+
# Convert the frame to grayscale for better performance
22+
gray = cv.cvtColor(img, cv.COLOR_BGR2GRAY)
23+
24+
# Detect faces in the frame
25+
faces = face_cascade.detectMultiScale(gray, scaleFactor=1.1, minNeighbors=7)
26+
27+
# Detect eyes in the frame
28+
eyes = eye_cascade.detectMultiScale(gray, scaleFactor=1.1, minNeighbors=7)
29+
30+
# Draw rectangles around faces and eyes
31+
for x, y, w, h in faces:
32+
cv.rectangle(img, (x, y), (x + w, y + h), (0, 255, 0), 1)
33+
34+
for a, b, c, d in eyes:
35+
cv.rectangle(img, (a, b), (a + c, b + d), (255, 0, 0), 1)
36+
37+
# Display the resulting frame
38+
cv.imshow("Face and Eye Detection", img)
39+
40+
# Check for the 'q' key to exit the program
41+
key = cv.waitKey(1)
42+
if key == ord("q"):
43+
break
44+
45+
# Release the webcam and close all windows
46+
cap.release()
47+
cv.destroyAllWindows()
48+
49+
50+
if __name__ == "__main__":
51+
# Call the main function
52+
detect_faces_and_eyes()
Lines changed: 18 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,27 @@
11
import cv2 as cv
22

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

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

8-
contor, _ = cv.findContours(frame.copy(), cv.RETR_TREE, cv.CHAIN_APPROX_SIMPLE)
9+
# Find contours in the binary image
10+
contours, _ = cv.findContours(thresholded.copy(), cv.RETR_TREE, cv.CHAIN_APPROX_SIMPLE)
911

10-
hull = [cv.convexHull(c) for c in contor]
12+
# Convex Hull for each contour
13+
convex_hulls = [cv.convexHull(contour) for contour in contours]
1114

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

19+
# Display the images
20+
cv.imshow("Original Image", img)
21+
cv.imshow("Thresholded Image", thresholded)
22+
cv.imshow("Contours", original_with_contours)
23+
cv.imshow("Convex Hulls", original_with_convex_hulls)
24+
25+
# Wait for a key press and close windows
1726
cv.waitKey(0)
1827
cv.destroyAllWindows()

Password Generator/requirements.txt

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,2 @@
1-
string
2-
secrets
3-
random
1+
colorama==0.4.4
2+
inquirer==2.7.0

Print_List_of_Even_Numbers.py

Lines changed: 0 additions & 19 deletions
This file was deleted.

Print_List_of_Odd_Numbers.py

Lines changed: 0 additions & 31 deletions
This file was deleted.

cli_master/cli_master.py

Lines changed: 136 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,136 @@
1+
import os
2+
import sys
3+
from pprint import pprint
4+
5+
import sys
6+
7+
sys.path.append(os.path.realpath("."))
8+
import inquirer # noqa
9+
10+
# Take authentication input from the user
11+
questions = [
12+
inquirer.List(
13+
"authentication", # This is the key
14+
message="Choose an option",
15+
choices=["Login", "Sign up", "Exit"],
16+
),
17+
]
18+
answers = inquirer.prompt(questions)
19+
20+
21+
# Just making pipelines
22+
class Validation:
23+
def phone_validation():
24+
# Think over how to make a validation for phone number?
25+
pass
26+
27+
def email_validation():
28+
pass
29+
30+
def password_validation():
31+
pass
32+
33+
def username_validation():
34+
pass
35+
36+
def country_validation():
37+
# All the countries in the world???
38+
# JSON can be used.
39+
# Download the file
40+
41+
def state_validation():
42+
# All the states in the world??
43+
# The state of the selected country only.
44+
pass
45+
46+
def city_validation():
47+
# All the cities in the world??
48+
# JSON can be used.
49+
pass
50+
51+
52+
# Have an option to go back.
53+
# How can I do it?
54+
if answers["authentication"] == "Login":
55+
print("Login")
56+
questions = [
57+
inquirer.Text(
58+
"username",
59+
message="What's your username?",
60+
validate=Validation.login_username,
61+
),
62+
inquirer.Text(
63+
"password",
64+
message="What's your password?",
65+
validate=Validation.login_password,
66+
),
67+
]
68+
69+
70+
elif answers["authentication"] == "Sign up":
71+
print("Sign up")
72+
73+
questions = [
74+
inquirer.Text(
75+
"name",
76+
message="What's your first name?",
77+
validate=Validation.fname_validation,
78+
),
79+
inquirer.Text(
80+
"surname",
81+
message="What's your last name(surname)?, validate=Validation.lname), {name}?",
82+
),
83+
inquirer.Text(
84+
"phone",
85+
message="What's your phone number",
86+
validate=Validation.phone_validation,
87+
),
88+
inquirer.Text(
89+
"email",
90+
message="What's your email",
91+
validate=Validation.email_validation,
92+
),
93+
inquirer.Text(
94+
"password",
95+
message="What's your password",
96+
validate=Validation.password_validation,
97+
),
98+
inquirer.Text(
99+
"password",
100+
message="Confirm your password",
101+
validate=Validation.password_confirmation,
102+
),
103+
inquirer.Text(
104+
"username",
105+
message="What's your username",
106+
validate=Validation.username_validation,
107+
),
108+
inquirer.Text(
109+
"country",
110+
message="What's your country",
111+
validate=Validation.country_validation,
112+
),
113+
inquirer.Text(
114+
"state",
115+
message="What's your state",
116+
validate=Validation.state_validation,
117+
),
118+
inquirer.Text(
119+
"city",
120+
message="What's your city",
121+
validate=Validation.city_validation,
122+
),
123+
inquirer.Text(
124+
"address",
125+
message="What's your address",
126+
validate=Validation.address_validation,
127+
),
128+
]
129+
# Also add optional in the above thing.
130+
# Have string manipulation for the above thing.
131+
# How to add authentication of google to command line?
132+
elif answers["authentication"] == "Exit":
133+
print("Exit")
134+
sys.exit()
135+
136+
pprint(answers)
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
import requests
2+
3+
url = "https://api.countrystatecity.in/v1/countries"
4+
5+
headers = {"X-CSCAPI-KEY": "API_KEY"}
6+
7+
response = requests.request("GET", url, headers=headers)
8+
9+
print(response.text)

cli_master/validation_page.py

Lines changed: 62 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,62 @@
1+
import re
2+
3+
def phone_validation(phone_number):
4+
# Match a typical US phone number format (xxx) xxx-xxxx
5+
pattern = re.compile(r'^\(\d{3}\) \d{3}-\d{4}$')
6+
return bool(pattern.match(phone_number))
7+
8+
# Example usage:
9+
phone_number_input = input("Enter phone number: ")
10+
if phone_validation(phone_number_input):
11+
print("Phone number is valid.")
12+
else:
13+
print("Invalid phone number.")
14+
15+
def email_validation(email):
16+
# Basic email format validation
17+
pattern = re.compile(r'^[a-zA-Z0-9_.+-]+@[a-zA-Z0-9-]+\.[a-zA-Z0-9-.]+$')
18+
return bool(pattern.match(email))
19+
20+
# Example usage:
21+
email_input = input("Enter email address: ")
22+
if email_validation(email_input):
23+
print("Email address is valid.")
24+
else:
25+
print("Invalid email address.")
26+
27+
28+
def password_validation(password):
29+
# Password must be at least 8 characters long and contain at least one digit
30+
return len(password) >= 8 and any(char.isdigit() for char in password)
31+
32+
# Example usage:
33+
password_input = input("Enter password: ")
34+
if password_validation(password_input):
35+
print("Password is valid.")
36+
else:
37+
print("Invalid password.")
38+
39+
40+
def username_validation(username):
41+
# Allow only alphanumeric characters and underscores
42+
return bool(re.match('^[a-zA-Z0-9_]+$', username))
43+
44+
# Example usage:
45+
username_input = input("Enter username: ")
46+
if username_validation(username_input):
47+
print("Username is valid.")
48+
else:
49+
print("Invalid username.")
50+
51+
52+
def country_validation(country):
53+
# Example: Allow only alphabetical characters and spaces
54+
return bool(re.match('^[a-zA-Z ]+$', country))
55+
56+
# Example usage:
57+
country_input = input("Enter country name: ")
58+
if country_validation(country_input):
59+
print("Country name is valid.")
60+
else:
61+
print("Invalid country name.")
62+

0 commit comments

Comments
 (0)