def main(): global cam, out, img_counter cam = cv2.VideoCapture(0) out = cv2.VideoWriter(filename, get_video_type(filename), 15, get_dims(cam, res)) #cv2.namedWindow("test") resize_1080p() ret, frame = cam.read() #gray = cv2.cvtColor(frame, cv2.COLOR_BGR2GRAY) #for converting into gray color #sketch_gray, sketch_color = cv2.pencilSketch(frame, sigma_s=60, sigma_r=0.07, shade_factor=0.05) #for converting into sketch and sketch colour #cv2.imshow("test", frame) #out.write(frame) //video wala img_name = "{}.png".format(img_counter) path = '/root/Documents/miniProject/ML Part/facial_recogn/test' cv2.imwrite(os.path.join(path, img_name), frame) #cv2.imwrite(img_name, frame) print("{} written!".format(img_name)) #img_counter += 1 #cv2.imshow("gray", gray) #cv2.imshow("sketch_gray", sketch_gray) #cv2.imshow("sketch_color", sketch_color) # if not ret: # break # # # elif k%256 == 32: # # SPACE pressed # img_name = "opencv_frame_{}.png".format(img_counter) # cv2.imwrite(img_name, frame) # print("{} written!".format(img_name)) # img_counter += 1 #time.sleep(10) cam.release() try: face_detection.main(img_counter) except Exception as e: print("Error in detection of faces\nDue to following error : ") print(e) img_counter += 1
def on_status(self, tweet): try: if 'hashtags' in tweet.entities: # 0 pra pegar a primeira hashtag, 6: pra tirar o robbbo pessoa = tweet.entities['hashtags'][0]["text"][6:] logger.info("Novo tweet torcendo para {}".format(pessoa)) if 'media' in tweet.entities: for image in tweet.entities['media']: photoOwner = tweet.user.screen_name logger.info( "Pegando imagem do tweet de {}".format(photoOwner)) picName = "%s.jpg" % photoOwner link = image['media_url'] filename = os.path.join(photo_directory, pessoa, picName) # talvez vamos ter que usar o agent (https://towardsdatascience.com/how-to-download-an-image-using-python-38a75cfa21c) urllib.request.urlretrieve(link, filename) face_detection.main([pessoa, photoOwner]) talker_bot(self.api, tweet, pessoa) else: logger.info("Esse post não tem imagem") except Exception as e: logger.exception("Erro ao favoritar tweet, erro:")
def execute_app(): while(1): print('----------') if systemArmed == True: print('System Armed') else: print('System Unarmed') cam.start() time.sleep(0.1) img = cam.get_image() pygame.image.save(img, "/home/pi/Documents/feed.jpg") print("Pic taken") cam.stop() files=[ ('feed',('feed.jpg',open('/home/pi/Documents/feed.jpg', 'rb'), 'image/png')) ] if(systemArmed): detections = face_detection.main("/home/pi/Documents/feed.jpg") faces_detected, known_faces, names, coords = detections if(faces_detected): imageData = { "detected": faces_detected, "name": names[0], "coords": coords[0][0] } else: imageData = { "detected": faces_detected, } else: imageData = { "detected": False } payload = imageData print(imageData) response = requests.request("POST", url, headers=headers, data=payload, files=files) #jsonResp = json.loads(response.text) #print(jsonResp['code']) print(response.text) time.sleep(5) # Wait for selected time
# cv2.imwrite(os.path.join(path , img_name), frame) # print("{} written!".format(img_name)) # img_counter += 1 # #k = cv2.waitKey(1) # #time.sleep(2) # if img_counter > 10: # ESC pressed k%256 == 27 or # print("Escape hit, closing...") # break except Exception as e: print("Error in recoding the video\nDue to following error : ") print(e) file = os.path.join(os.getcwd(), 'test', str(img_counter) + '.png') try: while (img_counter <= 10): face_detection.main(img_counter, file) img_counter += 1 file = os.path.join(os.getcwd(), 'test', str(img_counter) + '.png') except Exception as e: print("Error in detection of faces\nDue to following error : ") print(e) # try: # model.main() # except Exception as e: # print("Error in recoding the video\nDue to following error : ") # print(e) # cam.release() # cv2.destroyAllWindows() # time.sleep(1)