Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
cv.circle(img_raw, (landms[1], landms[6]), 1, (0, 255, 255), 4)
cv.circle(img_raw, (landms[2], landms[7]), 1, (255, 0, 255), 4)
cv.circle(img_raw, (landms[3], landms[8]), 1, (0, 255, 0), 4)
cv.circle(img_raw, (landms[4], landms[9]), 1, (255, 0, 0), 4)
# save image
cv.imwrite('images/result.jpg', img_raw)
cv.imshow('image', img_raw)
cv.waitKey(0)
if __name__ == "__main__":
full_path = 'test/Jason Behr_27968.JPG'
img = Image.open(full_path).convert('RGB')
bboxes, landmarks = mtcnn.detect_faces(img)
print(bboxes)
print(landmarks)
show_bboxes(full_path, bboxes, landmarks)
bboxes, landmarks = retinaface.detect_faces(img)
print(bboxes)
print(landmarks)
show_bboxes(full_path, bboxes, landmarks)
def test_mtcnn_multiple_instances(self):
"""
Multiple instances of MTCNN can be created in the same thread.
:return:
"""
detector_1 = MTCNN(steps_threshold=[.2, .7, .7])
detector_2 = MTCNN(steps_threshold=[.1, .1, .1])
ivan = cv2.imread("ivan.jpg")
faces_1 = detector_1.detect_faces(ivan)
faces_2 = detector_2.detect_faces(ivan)
self.assertEqual(len(faces_1), 1)
self.assertGreater(len(faces_2), 1)
def setUpClass(cls):
global mtcnn
mtcnn = MTCNN()
def test_mtcnn_multiple_instances(self):
"""
Multiple instances of MTCNN can be created in the same thread.
:return:
"""
detector_1 = MTCNN(steps_threshold=[.2, .7, .7])
detector_2 = MTCNN(steps_threshold=[.1, .1, .1])
ivan = cv2.imread("ivan.jpg")
faces_1 = detector_1.detect_faces(ivan)
faces_2 = detector_2.detect_faces(ivan)
self.assertEqual(len(faces_1), 1)
self.assertGreater(len(faces_2), 1)
def test_detect_faces_invalid_content(self):
"""
MTCNN detects invalid images
:return:
"""
ivan = cv2.imread("example.py")
with self.assertRaises(InvalidImage):
result = mtcnn.detect_faces(ivan) # type: list
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