Mark2020H

Ptython code for basic security camera (Part1)

Jan 21st, 2022 (edited)
1,101
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. import cv2
  2. import ftplib
  3. import sched, time
  4. from datetime import datetime
  5.  
  6.  
  7. # this is the function that will be called on starting thread
  8. def saveImage(s):
  9.     print(s)
  10.    
  11.     ret,frame = vid.read()
  12.     vid.release() #releasing camera immediately after capturing picture
  13.     now = datetime.now() # current date and time
  14.     date_time = now.strftime("%d/%m/%Y, %H:%M:%S")
  15.     font = cv2.FONT_HERSHEY_COMPLEX
  16.  
  17.     # Use putText() method for
  18.     # inserting text on video
  19.     cv2.putText(frame,
  20.                 date_time,
  21.                 (10, 40),
  22.                 font, 1,
  23.                 (255,255, 255),
  24.                 1,
  25.                 cv2.LINE_4)
  26.  
  27.     cv2.imwrite('img.jpg', frame)
  28.  
  29.    
  30.        
  31.  
  32. def uploadtoFTPServer():
  33.     # Fill Required Information
  34.     HOSTNAME = "x12.x10hosting.com"
  35.     USERNAME = "<YOUR LOGON>"
  36.     PASSWORD = "YOUR PASSWORD"
  37.  
  38.     filename = "img.jpg"
  39.     ftp_server = ftplib.FTP(HOSTNAME, USERNAME, PASSWORD)
  40.  
  41.     # force UTF-8 encoding
  42.     ftp_server.encoding = "utf-8"
  43.     ftp_server.cwd("/domains/eliteprojects.x10host.com/public_html")
  44.     with open(filename, "rb") as file:
  45.        # data = []
  46.         #ftp_server.dir(data.append)
  47.  
  48.         #for line in data:
  49.  
  50.             #print ( "-", line)
  51.  
  52.  
  53.         # Command for Uploading the file "STOR filename"
  54.         ftp_server.storbinary(f"STOR {filename}", file)
  55.         time.sleep(2)
  56.         ftp_server.quit()
  57.  
  58.  
  59.  # main execution starts here
  60.  
  61.  
  62.  
  63.  
  64. while(True):
  65.     vid = cv2.VideoCapture(0)
  66.     vid.set(3, 640)
  67.     vid.set(4, 480)
  68.     time_now = time.time()
  69.     saveImage(time_now)
  70.     time.sleep(1)
  71.    
  72.     uploadtoFTPServer()
RAW Paste Data Copied