-
Notifications
You must be signed in to change notification settings - Fork 0
/
cameraexploitation3.py
82 lines (65 loc) · 3.12 KB
/
cameraexploitation3.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
import cv2
import time
# Function to start live camera capture
def start_camera():
cap = cv2.VideoCapture(0)
if not cap.isOpened():
print("Failed to open camera")
exit(1)
return cap
# Function to stop live camera capture
def stop_camera(cap):
cap.release()
cv2.destroyAllWindows()
# Morse code dictionary
morse_code_dict = {'A': '.-', 'B': '-...', 'C': '-.-.', 'D': '-..', 'E': '.', 'F': '..-.', 'G': '--.', 'H': '....',
'I': '..', 'J': '.---', 'K': '-.-', 'L': '.-..', 'M': '--', 'N': '-.', 'O': '---', 'P': '.--.',
'Q': '--.-', 'R': '.-.', 'S': '...', 'T': '-', 'U': '..-', 'V': '...-', 'W': '.--', 'X': '-..-',
'Y': '-.--', 'Z': '--..', '1': '.----', '2': '..---', '3': '...--', '4': '....-', '5': '.....',
'6': '-....', '7': '--...', '8': '---..', '9': '----.', '0': '-----', ', ': '--..--', '.': '.-.-.-',
'?': '..--..', '/': '-..-.', '-': '-....-', '(': '-.--.', ')': '-.--.-', '_': '..--.-', '+': '.-.-.',
'*': '-..-', '@': '.--.-.', ' ': ' '}
# Function to transmit Morse code
def transmit_morse_code(message):
# Calculate total number of frames for progress tracking
total_frames = len(message) * 2 # 2 frames per dot/dash
# Record start time for bitrate calculation
start_time = time.time()
for char in message:
if char.upper() in morse_code_dict:
morse_code = morse_code_dict[char.upper()]
for code in morse_code:
if code == '.':
# Start live camera capture
cap = start_camera()
# Capture and display frames for dot duration (e.g. 1 second)
start_time_dot = time.time()
while time.time() - start_time_dot < 1:
ret, frame = cap.read()
if not ret:
print("Failed to capture frame")
break
stop_camera(cap)
elif code == '-':
# Start live camera capture
cap = start_camera()
# Capture and display frames for dash duration (e.g. 3 seconds)
start_time_dash = time.time()
while time.time() - start_time_dash < 3:
ret, frame = cap.read()
if not ret:
print("Failed to capture frame")
break
stop_camera(cap)
# Pause between dots and dashes (e.g. 1 second)
time.sleep(1)
total_frames -= 1
print(f"Progress: {total_frames} frames remaining")
elif char == ' ':
# Pause between words (e.g. 3 seconds)
time.sleep(3)
# Calculate time taken and bitrate
time_taken = time.time() - start_time
print(time_taken)
message = "HAR v"
transmit_morse_code(message)