-
-
Notifications
You must be signed in to change notification settings - Fork 3
/
camera_adjustment.py
52 lines (49 loc) · 1.67 KB
/
camera_adjustment.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
#/usr/bin/python3.6.x
#encoding:'utf-8'
#License: All Rights Reserved (C) Muneeb Ahmad
import os
import cv2
import pyttsx3
samples = []
to_do = ['Take a Photo in a Normal Condition', 'Put a Finger or Hand covering the Camera Pixel Now']
os.system('pyfiglet ANTI-COVERED')
#Calculates the Sharpness of the Image
def sharpness(img):
img = cv2.cvtColor(img, cv2.COLOR_BGR2GRAY)
lap = cv2.Laplacian(img, cv2.CV_16S)
mean, stddev = cv2.meanStdDev(lap)
return stddev[0,0]
# Get Camera Indexes
def returnCameraIndexes(camera_indexes_to_check=10):
# checks the first 10 indexes.
index = 0
arr = []
i = camera_indexes_to_check
while i > 0:
cap = cv2.VideoCapture(index, cv2.CAP_DSHOW)
if cap.read()[0]:
arr.append(index)
cap.release()
index += 1
i -= 1
return arr
camera_index = returnCameraIndexes(50)
print(camera_index)
print('[+] Select a Value from the Active Cameras in your PC, Select 0 for Default and other number if you want to use an attached usb or other camera')
camerz_inex = input('** Enter the Camera Index >> ')
# Getting the Blurry/Non-Blurry Image Ratings
for element in to_do:
data = pyttsx3.init()
data.say(f"{element}")
data.runAndWait()
vid = cv2.VideoCapture(int(camerz_inex), cv2.CAP_DSHOW)
return_value, image = vid.read()
cv2.imwrite('Open.png', image)
samples.append(sharpness(image))
print(f'Sharpness is: {sharpness(image)}')
vid.release()
# Now Starting the Routine for Processing the Results
sharp_reading = samples[0]
blurry_reading = samples[1]
with open('Camera_Covered_Values.txt', 'w+') as f:
f.write(f'{sharp_reading},{blurry_reading}')