GithubHelp home page GithubHelp logo

AFLW files about cnn_face_detection HOT 2 CLOSED

anson0910 avatar anson0910 commented on June 15, 2024
AFLW files

from cnn_face_detection.

Comments (2)

melgor avatar melgor commented on June 15, 2024 4

Hi,
I found that GUI but I do not know how should I extract this information. So I write a python script for extracting this information, where output file have format

path x y w h

Maybe someone will want to use it.

import sqlite3

list_annotation = list()
# Format for saving: path x y w h
ann_format = "{}/{} {} {} {} {}"

conn = sqlite3.connect('aflw.sqlite')
print "Opened database successfully"

# Get all Face ID
fidQuery = 'SELECT face_id FROM Faces'
faceIDs = conn.execute(fidQuery)

for idx in faceIDs:
  # Get ImgID connected to face
  fidQuery = 'SELECT file_id FROM Faces WHERE face_id = {}'.format(idx[0])
  imgID = conn.execute(fidQuery)
  imgID = [id for id in imgID]

  # Get image name and DB ID
  imgDataQuery = "SELECT db_id,filepath,width,height FROM FaceImages WHERE file_id = '{}'".format(imgID[0][0])
  fileID = conn.execute(imgDataQuery)
  fileID = [id for id in fileID]
  db_id = fileID[0][0]
  filepath = fileID[0][1]

  # Get Face Rect
  faceRectQuery = 'SELECT x,y,w,h FROM FaceRect WHERE face_id = {}'.format(idx[0])
  faceRect = conn.execute(faceRectQuery)
  faceRect = [id for id in faceRect]
  x,y,w,h =  faceRect[0]

  list_annotation.append(ann_format.format(db_id,filepath,x,y,w,h))


with open("AFLW_ann.txt",'w') as f:
  f.writelines("%s\n" % line for line in list_annotation) 

and this is changed aflw.py for a new format.

import numpy as np
import cv2
import os

data_base_dir = "/media/blcv/drive_2TB/Face/AFLW/aflw/data/"     # file containing pictures
save_dir = "/media/blcv/drive_2TB/CODE/Face_Detection/CNN_face_detection/Data/positive"         # file to save cropped male faces
read_file_name_faces = "AFLW_ann.txt"   # file with path to image and rect

faceID_fileName_dict = {}   # dictionary of str to str

if not os.path.isdir(save_dir): os.makedirs(save_dir)
# =========== read face file ===============
with open(read_file_name_faces, "r") as ins:
  for line in ins:
    path,x,y,w,h = line.strip().split(" ")
    id_image = os.path.basename(path).split(".")[0]
    faceID_fileName_dict[id_image] = (path,int(x),int(y),int(w),int(h))

# =========== Start processing ===============
i = 0
for key,value in faceID_fileName_dict.iteritems():
    if i % 10 == 0:
        print "Processing rect number " + str(i)
    path,x,y,w,h = value
    x = max(0, x)
    y = max(0, y)

    read_img_name = os.path.join(data_base_dir, path)
    if not os.path.exists(read_img_name):     # check if file exists
        continue
    img = cv2.imread(read_img_name)     # read image
    cropped_img = img[y : y + h, x : x + w]

    file_name = os.path.join(save_dir ,str(key).zfill(6) + ".jpg")
    cv2.imwrite(file_name, cropped_img)
    i += 1

from cnn_face_detection.

anson0910 avatar anson0910 commented on June 15, 2024

Hi, I remember I used a GUI interface (Qt?) to connect to the SQLITE database.

Well, I just wanted to see if it was able to do gender recognition at the same time.
The accuracy was pretty high, but I didn't really need it so I didn't use it.
If you need it, you can just modify the labels to be 3 bins instead of binary classfication.

from cnn_face_detection.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.