Академический Документы
Профессиональный Документы
Культура Документы
import cv2
import os
import glob
from tqdm import tqdm
import math
from numpy import matrix
from numpy import linalg
"""def check_path(path): #function to confirm whether the given path
exists or not
dir = os.path.dirname(path) #if it doesn't exist this function will create
if not os.path.exists(dir):
os.makedirs(dir)
cap = cv2.VideoCapture(0)
camera=cv2.VideoCapture(1)
anh = 1
dem = 1
face_id = 1 # For each person,there will be one face id
count = 0 # Initialize sample face image
check_path("dataset/")
check_path("dataset1/")
# Define the codec and create VideoWriter object.The output is stored in
'outpy.avi' file.
while(cap.isOpened()):
ret, frame = cap.read()
ret1,frame1=camera.read()
if ret==True:
count += 1
cv2.imwrite("dataset/User." + str(face_id) + '.' + str(count) + ".jpg",
frame)
cv2.imshow('Creating Dataset!!!', frame)
cv2.waitKey(1000)
if ret1 == True:
dem += 1
cv2.imwrite("dataset1/User." + str(anh) + '.' + str(dem) + ".jpg", frame1)
cv2.imshow('Creating Dataset 1!!!', frame1)
cv2.waitKey(1000)
if cv2.waitKey(1) & 0xFF == ord('q'):
break
if (count > 29) and (dem>29): # If image taken reach 100, stop taking video
break
"""
img_mask = 'dataset/*.jpg'
img_names = glob.glob(img_mask)
img_mask1 = 'dataset1/*.jpg'
img_names1 = glob.glob(img_mask1)
pattern_size = (9, 6)
print(M1)
print(M2)
print(d1)
print(d2)
#print(t1)
flags = (cv2.CALIB_FIX_K5 + cv2.CALIB_FIX_K6)
stereocalib_criteria = (cv2.TERM_CRITERIA_MAX_ITER + cv2.TERM_CRITERIA_EPS, 100,
1e-5)
flags = (cv2.CALIB_FIX_PRINCIPAL_POINT | cv2.CALIB_FIX_ASPECT_RATIO |
cv2.CALIB_FIX_FOCAL_LENGTH |
cv2.CALIB_FIX_INTRINSIC | cv2.CALIB_FIX_K3 | cv2.CALIB_FIX_K4 |
cv2.CALIB_FIX_K5 |
cv2.CALIB_FIX_K6)
T = np.zeros((3, 1), dtype=np.float64)
R = np.eye(3, dtype=np.float64)
#stereocalibration_flags = 0
#stereocalibration_flags= cv2.CALIB_FIX_INTRINSIC
#stereocalibration_flags= cv2.CALIB_USE_INTRINSIC_GUESS
#stereocalibration_flags= cv2.CALIB_FIX_FOCAL_LENGTH
#stereocalibration_flags= cv2.CALIB_ZERO_TANGENT_DIST
ret, M_1, d_1, M_2, d_2, R, T, E, F = cv2.stereoCalibrate(obj_points,
img_points,img_points1, M1, d1, M2,d2, gray1.shape[::-
1],criteria=stereocalib_criteria, flags=flags)
#print('Intrinsic_mtx_1', M_1)
#print('dist_1', d_1)
#print('Intrinsic_mtx_2', M_2)
#print('dist_2', d_2)
#print('R', R)
#print('T', T)
#print('E', E)
#print('F', F)