Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import cv2 # openCV
- import numpy as np # for numpy arrays
- import sqlite3
- import dlib
- import os
- import ftplib
- import requests
- # for creating folders
- cap = cv2.VideoCapture(0)
- detector = dlib.get_frontal_face_detector()
- def insertOrUpdate(nis, nama, username, password, kelas, imageName) :
- API_ENDPOINT = "http://zoopedia-panel.xyz/face/api_register.php"
- # data to be sent to api
- data = {'nis':nis,
- 'nama':nama,
- 'username':username,
- 'password':password,
- 'kelas':kelas,
- 'imageName':imageName}
- # sending post request and saving response as response object
- r = requests.post(url = API_ENDPOINT, data = data)
- # extracting response text
- print(r.text)
- nis = raw_input("Nis : ")
- nama = raw_input("Nama : ")
- username = raw_input("Username : ")
- password = raw_input("Password : ")
- kelas = raw_input("Kelas : ")
- # Id = int(nis)
- folderName = "Siswa_" + nis
- folderPath = os.path.join(os.path.dirname(os.path.realpath(__file__)), "dataset/"+folderName)
- if not os.path.exists(folderPath):
- os.makedirs(folderPath)
- sampleNum = 0
- while(True):
- ret, img = cap.read()
- gray = cv2.cvtColor(img, cv2.COLOR_BGR2GRAY)
- dets = detector(img, 1)
- for i, d in enumerate(dets):
- sampleNum += 1
- cv2.imwrite(folderPath + "/Siswa." + nis + ".jpg",
- img[d.top():d.bottom(), d.left():d.right()])
- cv2.rectangle(img, (d.left(), d.top()) ,(d.right(), d.bottom()),(0,255,0) ,2)
- cv2.waitKey(200)
- cv2.imshow('frame', img)
- cv2.waitKey(1)
- if(sampleNum >= 1):
- break
- cap.release()
- cv2.destroyAllWindows()
- imageName= "Siswa." + nis + ".jpg"
- ftp= ftplib.FTP('103.15.226.230')
- ftp.login('new@zoopedia-panel.xyz', 'projectsindu')
- ftp.cwd('user_foto')
- uploadfile= open(folderPath + "/Siswa." + nis + ".jpg", 'rb')
- ftp.storlines('STOR ' + imageName, uploadfile)
- insertOrUpdate(nis, nama, username, password, kelas, imageName)
- 2
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement