Advertisement
Guest User

Untitled

a guest
Oct 18th, 2018
82
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 2.61 KB | None | 0 0
  1. import cv2                                                                      # openCV
  2. import numpy as np                                                              # for numpy arrays
  3. import sqlite3
  4. import dlib
  5. import os                                
  6. import ftplib
  7. import requests
  8.                                        # for creating folders
  9.  
  10. cap = cv2.VideoCapture(0)
  11. detector = dlib.get_frontal_face_detector()
  12.  
  13. def insertOrUpdate(nis, nama, username, password, kelas, imageName) :                        
  14.    
  15.     API_ENDPOINT = "http://zoopedia-panel.xyz/face/api_register.php"
  16.    
  17.     # data to be sent to api
  18.     data = {'nis':nis,
  19.             'nama':nama,
  20.             'username':username,
  21.             'password':password,
  22.             'kelas':kelas,
  23.             'imageName':imageName}
  24.      
  25.     # sending post request and saving response as response object
  26.     r = requests.post(url = API_ENDPOINT, data = data)
  27.      
  28.     # extracting    response text  
  29.     print(r.text)
  30.  
  31. nis = raw_input("Nis : ")
  32. nama = raw_input("Nama : ")
  33. username = raw_input("Username : ")
  34. password = raw_input("Password : ")
  35. kelas = raw_input("Kelas : ")
  36. # Id = int(nis)
  37.  
  38.  
  39. folderName = "Siswa_" + nis                      
  40. folderPath = os.path.join(os.path.dirname(os.path.realpath(__file__)), "dataset/"+folderName)
  41. if not os.path.exists(folderPath):
  42.     os.makedirs(folderPath)
  43.  
  44. sampleNum = 0
  45. while(True):
  46.     ret, img = cap.read()                                                      
  47.     gray = cv2.cvtColor(img, cv2.COLOR_BGR2GRAY)                              
  48.     dets = detector(img, 1)
  49.     for i, d in enumerate(dets):                                              
  50.         sampleNum += 1
  51.         cv2.imwrite(folderPath + "/Siswa." + nis + ".jpg",
  52.                     img[d.top():d.bottom(), d.left():d.right()])              
  53.         cv2.rectangle(img, (d.left(), d.top())  ,(d.right(), d.bottom()),(0,255,0) ,2)
  54.         cv2.waitKey(200)
  55.  
  56.     cv2.imshow('frame', img)                                          
  57.     cv2.waitKey(1)
  58.  
  59.  
  60.     if(sampleNum >= 1):                                                
  61.         break
  62.  
  63.  
  64. cap.release()                                                        
  65.  
  66. cv2.destroyAllWindows()                                              
  67.  
  68.  
  69. imageName= "Siswa." + nis + ".jpg"
  70. ftp= ftplib.FTP('103.15.226.230')
  71. ftp.login('new@zoopedia-panel.xyz', 'projectsindu')
  72. ftp.cwd('user_foto')
  73. uploadfile= open(folderPath + "/Siswa." + nis + ".jpg", 'rb')
  74. ftp.storlines('STOR ' + imageName, uploadfile)
  75. insertOrUpdate(nis, nama, username, password, kelas, imageName)                                                            
  76.  
  77.  
  78. 2
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement