Example #1
0
def main(broker):
    MQTT_PATH = "pi-cam"

    mqttc = mqtt.Client("pi-camera-publisher")
    mqttc.connect(host=broker, port=1883, keepalive=60)
    mqttc.on_message = on_message
    mqttc.on_connect = on_connect
    mqttc.on_publish = on_publish
    mqttc.on_subscribe = on_subscribe
    mqttc.on_log = on_log

    # Wait for connection setup to complete
    time.sleep(4)
    mqttc.loop_start()

    # Open camera
    framerate = 12
    vs = VideoStream(src=0, usePiCamera=True, resolution=(640, 480), framerate=framerate).start()
    time.sleep(2.0)
    fps = FPS().start()

    # Webcam light should come on if using one
    time.sleep(2)

    try:
        while True:
            frame = vs.read()
            retval, buffer = cv2.imencode('.png', frame)
            value = base64.b64encode(buffer).decode()
            publish_encoded_image(mqttc, MQTT_PATH, value)
            time.sleep(1 / framerate)
    finally:
        fps.stop()
        vs.close()
        mqttc.disconnect()
Example #2
0
        
    cv2.imshow('camera',img)
    cv2.imwrite('786image.jpg',img)


    k = cv2.waitKey(10) & 0xff # Press 'ESC' for exiting video
    if k == 2:
       
        break
    d+=1


# Do a bit of cleanup
print("\n [INFO] Exiting Program and cleanup stuff")

cam.close()#release()
if(a>0):
    printid(a)
    emps = get_emps_by_id(a+1)
    print(emps)
    sendMail(emps)
    
  
cv2.destroyAllWindows()
conn.close()





Example #3
0
	def onClicked(self):
		todays_date = str(date.today())
		todays_date = "AOD_" + str(todays_date.replace("-","_"))
		# PRAGMA foreign_keys=ON
		conn = sqlite3.connect('FaceRecognition.db')
		c = conn.cursor()
		crete_query = ("""CREATE TABLE IF NOT EXISTS {} 
	        (   Name text NOT NULL,
	            ID text PRIMARY KEY,
	            CheckInTime text NOT NULL,
	            CONSTRAINT fk
	            FOREIGN KEY (ID)
	            REFERENCES employees(ID)
	        )""".format(str(todays_date))) 
		c.execute(crete_query)
		conn.commit()
		conn.close()

		print("[INFO] loading encodings + face detector...")
		file = open('encodings', 'rb')
		data = pickle.load(file)
		detector = cv2.CascadeClassifier(os.getcwd()+'\\'+'haarcascade_frontalface_default.xml')
		print("[INFO] starting video stream...")
		cap =VideoStream(src=0).start()
		fps = FPS().start()
		while(True):
			frame = cap.read()
			gray = cv2.cvtColor(frame, cv2.COLOR_BGR2GRAY)
			rgb = cv2.cvtColor(frame, cv2.COLOR_BGR2RGB)
			rects = detector.detectMultiScale(gray, scaleFactor=1.1, minNeighbors=5,minSize=(30, 30),flags=cv2.CASCADE_SCALE_IMAGE)
			boxes = [(y, x + w, y + h, x) for (x, y, w, h) in rects]
			encodings = face_recognition.face_encodings(rgb, boxes)
			names = []
			for encoding in encodings:
				matches = face_recognition.compare_faces(data["encodings"],encoding)
				name = "Unknown"
				if True in matches:
					matchedIdxs = [i for (i, b) in enumerate(matches) if b]
					counts = {}
					for i in matchedIdxs:
						name = data["names"][i]
						counts[name] = counts.get(name, 0) + 1
					name = max(counts, key=counts.get)
				names.append(name)
				self.Text.setText(name)
				global emp
				emp = name
			i=0	
			for ((top, right, bottom, left), name) in zip(boxes, names):
				cv2.rectangle(frame, (left, top), (right, bottom),(0, 255, 0), 2)
				y = top - 15 if top - 15 > 15 else top + 15
				cv2.putText(frame, name, (left, y), cv2.FONT_HERSHEY_SIMPLEX,0.75, (0, 255, 0), 2)
				#self.Text.setText(name)
				if(name!="Unknown"):
					engine = pyttsx3.init()
					engine.say("Good Morning")
					engine.runAndWait()
					break

				else:
					engine = pyttsx3.init()
					engine.say("Not Recognised please contact Admin")
					engine.runAndWait()
					break
				break

			conn2 = sqlite3.connect('FaceRecognition.db', timeout=40.0)
			c2 = conn2.cursor()

			if emp!="Unknown":
				try:
					Name = c2.execute("""SELECT Name FROM employees WHERE ID == {}""".format(emp))
					Name = Name.fetchone()[0]
					if i==0:
						c2.execute(("""INSERT INTO {} (Name, ID, CheckInTime) VALUES (?,?,?)""".format(todays_date)), (str(Name), emp, datetime.now().strftime("%H:%M:%S")))
						conn2.commit()
						i=1
						break
					conn2.commit()

				except Exception as err:
					print('Query Failed: Error: %s' %(str(err)))
					break    #Pop up Needed
					# c1.execute(("""INSERT INTO {} (Name, ID, CheckInTime) VALUES (?,?,?)""".format(todays_date)), (emp, '-', datetime.now().strftime("%H:%M:%S")))

				finally:
					c2.close()
					conn2.close()
			else:
				conn1 = sqlite3.connect('FaceRecognition.db', timeout=40.0)
				c1 = conn1.cursor()
				c1.execute(("""INSERT INTO {} (Name, ID, CheckInTime) VALUES (?,?,?)""".format(todays_date)), ('Unknown', '-', datetime.now().strftime("%H:%M:%S")))
				c1.close()
				conn1.close()
				break

			# conn2 = sqlite3.connect('FaceRecognition.db', timeout=40.0)
			# c2 = conn2.cursor()
			# if i==0:
			# 	c2.execute(("""INSERT INTO {} (Name, ID, CheckInTime) VALUES (?,?,?)""".format(todays_date)), (str(Name), emp, datetime.now().strftime("%H:%M:%S")))
			# 	conn2.commit()
			# 	i=1
			# 	break

			# c2.close()
			# conn2.close()

			self.displayImage(frame,1)
			if cv2.waitKey(1) & 0xFF == ord('q'):
				break
		cap.close()
		window.close()
		cv2.destroyAllWindows()
		cap.stop()