Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
def detect_face(img_path, detector=MTCNN()):
"""
detect face with MTCNN
:param img_path:
:return:
"""
img = cv2.imread(img_path)
if detector is None:
detector = MTCNN()
mtcnn_result = detector.detect_faces(img)
return mtcnn_result
def __init__(self, preprocessed_image_size=128):
from mtcnn.mtcnn import MTCNN
self.database_directory = '../LAP Apparent Age V2'
self.face_detector = MTCNN(steps_threshold=[0.5, 0.6, 0.6])
self.preprocessed_image_size = preprocessed_image_size
def face_detection(username):
x = 0
''' Get user media and scan it for a face'''
user_id = bot.get_user_id_from_username(username)
medias = bot.get_user_medias(user_id, filtration=False)
for media in medias:
while x < 1:
try:
bot.logger.info(media)
path = bot.download_photo(media, folder=username)
img = cv2.imread(path)
detector = MTCNN()
detect = detector.detect_faces(img)
if not detect:
Bots.save_user_info(ig_username, "no face detected " + bot.get_link_from_media_id(media))
bot.logger.info("save user info")
bot.logger.info("no face detected " + bot.get_link_from_media_id(media))
x += 1
elif detect:
Bots.save_user_info(ig_username, "there was a face detected")
bot.logger.info("save user info")
bot.logger.info("there was a face detected")
bot.api.like(media)
display_url = bot.get_link_from_media_id(media)
bot.logger.info("liked " + display_url + " by " + username)
Bots.save_user_info(ig_username, "liked " + display_url + " by " + username)
Bots.payment_system()
def main():
args = get_args()
mypath = args.db
output_path = args.output
img_size = args.img_size
ad = args.ad
isPlot = True
detector = MTCNN()
onlyfiles_png = []
onlyfiles_txt = []
for num in range(0,24):
if num<9:
mypath_obj = mypath+'/0'+str(num+1)
else:
mypath_obj = mypath+'/'+str(num+1)
print(mypath_obj)
onlyfiles_txt_temp = [f for f in listdir(mypath_obj) if isfile(join(mypath_obj, f)) and join(mypath_obj, f).endswith('.txt')]
onlyfiles_png_temp = [f for f in listdir(mypath_obj) if isfile(join(mypath_obj, f)) and join(mypath_obj, f).endswith('.png')]
onlyfiles_txt_temp.sort()
onlyfiles_png_temp.sort()
onlyfiles_txt.append(onlyfiles_txt_temp)
def detect_face(img_path, detector=MTCNN()):
"""
detect face with MTCNN
:param img_path:
:return:
"""
img = cv2.imread(img_path)
if detector is None:
detector = MTCNN()
mtcnn_result = detector.detect_faces(img)
return mtcnn_result
ap.add_argument('--gpu', default=0, type=int, help='gpu id')
ap.add_argument('--det', default=0, type=int, help='mtcnn option, 1 means using R+O, 0 means detect from begining')
ap.add_argument('--flip', default=0, type=int, help='whether do lr flip aug')
ap.add_argument('--threshold', default=1.24, type=float, help='ver dist threshold')
args = ap.parse_args()
# Load embeddings and labels
data = pickle.loads(open(args.embeddings, "rb").read())
le = pickle.loads(open(args.le, "rb").read())
embeddings = np.array(data['embeddings'])
labels = le.fit_transform(data['names'])
# Initialize detector
detector = MTCNN()
# Initialize faces embedding model
embedding_model =face_model.FaceModel(args)
# Load the classifier model
model = load_model(args.mymodel)
# Define distance function
def findCosineDistance(vector1, vector2):
"""
Calculate cosine distance between two vector
"""
vec1 = vector1.flatten()
vec2 = vector2.flatten()
a = np.dot(vec1.T, vec2)