merge #1
							
								
								
									
										35
									
								
								main.py
									
									
									
									
									
								
							
							
						
						
									
										35
									
								
								main.py
									
									
									
									
									
								
							@ -6,17 +6,33 @@ import cv2
 | 
				
			|||||||
import numpy as np
 | 
					import numpy as np
 | 
				
			||||||
 | 
					
 | 
				
			||||||
def init():
 | 
					def init():
 | 
				
			||||||
 | 
						go = true
 | 
				
			||||||
	print('Initilizing Camera and cascade components..')
 | 
						print('Initilizing Camera and cascade components..')
 | 
				
			||||||
 | 
						try:
 | 
				
			||||||
		camera = PiCamera()
 | 
							camera = PiCamera()
 | 
				
			||||||
	print('[ OK ] Camera')
 | 
					 | 
				
			||||||
		camera.resolution = (640, 480)
 | 
							camera.resolution = (640, 480)
 | 
				
			||||||
	face_cascade = cv2.CascadeClassifier('haarcascade_frontalface_default.xml')
 | 
							sleep(2)
 | 
				
			||||||
	print('[ OK ] CascadeClassifier')
 | 
							print('[ OK ] Camera')
 | 
				
			||||||
	print('Starting Photo loop..')
 | 
						except:
 | 
				
			||||||
	start()
 | 
							print('[ Error ] Can not initialize PiCamera')
 | 
				
			||||||
 | 
							go = false
 | 
				
			||||||
 | 
					
 | 
				
			||||||
def start():
 | 
						try:
 | 
				
			||||||
 | 
							face_cascade = cv2.CascadeClassifier('haarcascade_frontalface_default.xml')
 | 
				
			||||||
 | 
							sleep(1)
 | 
				
			||||||
 | 
							print('[ OK ] CascadeClassifier')
 | 
				
			||||||
 | 
						except:
 | 
				
			||||||
 | 
							print('[ Error ] Can not load cascade File')
 | 
				
			||||||
 | 
							go = false
 | 
				
			||||||
 | 
						if (go):
 | 
				
			||||||
 | 
							print('Starting Photo loop..')
 | 
				
			||||||
 | 
							start(camera)
 | 
				
			||||||
 | 
						else: 
 | 
				
			||||||
 | 
							print('closing')
 | 
				
			||||||
 | 
						
 | 
				
			||||||
 | 
					def start(camera):
 | 
				
			||||||
	while True:
 | 
						while True:
 | 
				
			||||||
 | 
							try:
 | 
				
			||||||
			print('Taking photo')
 | 
								print('Taking photo')
 | 
				
			||||||
			camera.capture('img.jpg')
 | 
								camera.capture('img.jpg')
 | 
				
			||||||
			print('Photo Captured')
 | 
								print('Photo Captured')
 | 
				
			||||||
@ -29,7 +45,7 @@ def start():
 | 
				
			|||||||
			for (x,y,w,h) in faces:
 | 
								for (x,y,w,h) in faces:
 | 
				
			||||||
				i = i + 1
 | 
									i = i + 1
 | 
				
			||||||
				cv2.rectangle(img,(x,y),(x+w,y+h),(255,0,0),2)
 | 
									cv2.rectangle(img,(x,y),(x+w,y+h),(255,0,0),2)
 | 
				
			||||||
			cv2.imwrite('result.jpg', gray)
 | 
									#cv2.imwrite('result.jpg', gray)
 | 
				
			||||||
				roi_gray = gray[y:y+h, x:x+w]
 | 
									roi_gray = gray[y:y+h, x:x+w]
 | 
				
			||||||
				roi_color = img[y:y+h, x:x+w]
 | 
									roi_color = img[y:y+h, x:x+w]
 | 
				
			||||||
				print('Drawing on face ', i)
 | 
									print('Drawing on face ', i)
 | 
				
			||||||
@ -40,7 +56,10 @@ def start():
 | 
				
			|||||||
				cv2.destroyAllWindows()
 | 
									cv2.destroyAllWindows()
 | 
				
			||||||
				break
 | 
									break
 | 
				
			||||||
		
 | 
							
 | 
				
			||||||
	print('Finshed')
 | 
							except:
 | 
				
			||||||
 | 
								print('[ Error ] Unexpected exception')
 | 
				
			||||||
 | 
								print('Closing')
 | 
				
			||||||
 | 
								break
 | 
				
			||||||
	
 | 
						
 | 
				
			||||||
def recognize():
 | 
					def recognize():
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
				
			|||||||
		Loading…
	
		Reference in New Issue
	
	Block a user