Пример #1
0
 def test_detect_face(self):
     orig_image = Image("jpg", "1", "./data/1.jpg")
     orig_image.getRGB(cache=True)
     
     orig_image.detect_face()
     
     self.assertTrue(os.path.exists("./data/1_face.jpg"))
Пример #2
0
def detect_face_from_url():
    if request.method == 'POST':
        url = request.form['url']
        filename = url.split('/')[-1]
        image_file = requests.get(url)
        
        if image_file and allowed_file(filename):
            with open(os.path.join(facerec.config['UPLOAD_FOLDER'], filename), 'wb') as f:
                f.write(image_file.content)
                
                f.close()
                
                image = Image('jpg', filename.split(".")[0], os.path.join(facerec.config['UPLOAD_FOLDER'], filename), facerec.config)
                image.getRGB(cache=True)
                
                
                largestBox = detector.getLargestFaceBoundingBox(image.rgb)
                alignedFace = detector.alignImg("homography", 256, image.rgb, largestBox, outputPrefix=image.name, outputDebug=True, expandBox=False)
            
                #image.detect_face()
        
                orig_filename = filename.split('.')[0] + "-orig" + ".jpg"
                face_imagename = filename.split('.')[0] + "-annotated" + ".jpg"
                cropped_filename = filename.split('.')[0] + "-cropped" + ".jpg"
                entries = []
                entries.append(orig_filename)
                entries.append(face_imagename)
                entries.append(cropped_filename)
                return render_template('index.html', entries = entries)
Пример #3
0
 def test_save_jpg(self):
     #Read jpg file to image
     orig_image = Image("jpg", "1", "./data/1.jpg")
     orig_image.getRGB(cache=True)
     
     # Save it to name + test - jpg image
     filename = orig_image.name + "_test"
     orig_image.save('jpg', filename, "./data/")
     #Check there is file called name + test image in directory
     self.assertTrue(os.path.exists("./data/1_test.jpg"))
     
     os.remove('./data/1_test.jpg')
Пример #4
0
def detect_face_from_local(filename):
    image = Image('jpg', filename.split(".")[0], os.path.join(facerec.config['UPLOAD_FOLDER'], filename), facerec.config)
    image.getRGB(cache=True)
        
    largestBox = detector.getLargestFaceBoundingBox(image.rgb)
    alignedFace = detector.alignImg("homography", 256, image.rgb, largestBox, outputPrefix=image.name, outputDebug=True, expandBox=False)
    orig_filename = filename.split('.')[0] + "-orig" + ".jpg"
    face_filename = filename.split('.')[0] + "-annotated" + ".jpg"
    cropped_filename = filename.split('.')[0] + "-cropped" + ".jpg"
    entries = []
    entries.append(orig_filename)
    entries.append(face_filename)
    entries.append(cropped_filename)
    return render_template('index.html', entries = entries)
Пример #5
0
def detect_face_from_file():
    if request.method == 'POST':
        image_file = request.files['file']
        if image_file and allowed_file(image_file.filename):
            image_file.save(os.path.join(facerec.config['UPLOAD_FOLDER'], image_file.filename))
            image = Image('jpg', image_file.filename.split(".")[0], os.path.join(facerec.config['UPLOAD_FOLDER'], image_file.filename), facerec.config)
            image.getRGB(cache=True)
            
            largestBox = detector.getLargestFaceBoundingBox(image.rgb)
            alignedFace = detector.alignImg("homography", 256, image.rgb, largestBox, outputPrefix=image.name, outputDebug=True, expandBox=False)
            
            #image.detect_face()
        
            orig_filename = image_file.filename.split('.')[0] + "-orig" + ".jpg"
            face_imagename = image_file.filename.split('.')[0] + "-annotated" + ".jpg"
            cropped_filename = image_file.filename.split('.')[0] + "-cropped" + ".jpg"
            entries = []
            entries.append(orig_filename)
            entries.append(face_imagename)
            entries.append(cropped_filename)
            return render_template('index.html', entries = entries)