python-animeface

repository·main·Indexed 41 days ago

https://github.com/nya3jp/python-animeface

A Python wrapper for the AnimeFace library used to detect anime character faces in images and extract facial features such as eyes, nose, and mouth positions. It provides the animeface.detect() API to analyze PIL.Image objects and return Face objects containing bounding box coordinates, confidence likelihood, and color information for skin and hair.

Tokens
2.8K
Snippets
9
Records
17
Agent score
51%

What's inside python-animeface

  1. Install libnvxs from source

    main

    If a Python binary package (wheel) is not available for your specific environment, you must manually install libnvxs (the original AnimeFace library) before installing python-animeface. The source code for libnvxs is located in the third_party/nvxs-1.0.2 directory of this repository.

    Follow these steps to build and install it:

    cd third_party/nvxs-1.0.2
    ./configure
    make
    sudo make install
  2. Verify CLAPACK and BLAS correctness

    main

    After building the libraries, you should run the testing suites to ensure correctness.

    1. Test BLAS

    Navigate to the BLAS testing directory, build the testers, and run them against the input files. Inspect the resulting *.SUMM files for errors.

    cd CLAPACK/BLAS/TESTING; make -f Makeblat2
    cd CLAPACK/BLAS
    xblat2s < sblat2.in
    xblat2d < dblat2.in
    xblat2c < cblat2.in
    xblat2z < dblat2.in
    # Repeat for Makeblat3

    2. Test LAPACK

    Build the matrix generation software and the specific testing routines (Eigen or Linear System), then run the LAPACK tests. Inspect *.out files for errors.

    cd CLAPACK/TESTING/MATGEN; make
    cd CLAPACK/TESTING; make
  3. Install CLAPACK via fast default installation

    main

    To perform a standard installation of CLAPACK, follow these steps in order:

    1. Extract and Configure: Untar clapack.tar and modify the make.inc file to match your system's compiler and flags. You can find sample make.inc files in the INSTALL/ subdirectory.
    2. Build f2c libraries: Run make f2clib from the main directory.
    3. Build BLAS library: Run make blaslib from the main directory to use the included reference BLAS (note: this is not optimized for speed).
    4. Build LAPACK: Run make from the main directory to compile the main library.
    5. Test: Run make from the main directory to test and time the installation.
    tar xvf clapack.tar
    # Modify make.inc first
    make f2clib
    make blaslib
    make
  4. Enable INTEGER*8 (64-bit integers) in libf2c

    main

    To use 64-bit integers (INTEGER*8), follow these steps:

    1. Modify f2c.h: Uncomment the typedefs for longint and ulongint and adjust them to:
      typedef long longint;
      typedef unsigned long ulongint;
    2. Update Makefile:
      • Add -DAllow_TYQUAD to the CFLAGS assignment.
      • Add $(QINT) to the end of the dependency list for libf2c.a (if using makefile.u).
      • If using PC makefiles, add pow_qq.obj qbitbits.obj qbitshft.obj to the library's dependency list and adjust libf2c.lbc or libf2c.sy accordingly.
    3. Optional: You may also add -DINTEGER_STAR_8 to the CFLAGS assignment.
    # Example CFLAGS modification
    CFLAGS = -DAllow_TYQUAD -DINTEGER_STAR_8
  5. Configure libf2c compiler flags for compatibility

    main

    Depending on your compiler and system architecture, you may need to define specific macros in your CFLAGS within the makefile:

    • Non-ANSI C headers: Add -DKR_headers to CFLAGS or insert #define KR_headers at the top of f2c.h.
    • Missing onexit(): If your system lacks onexit() and you aren't using an ANSI C compiler, compile main.c with NO_ONEXIT defined.
    • IEEE drem() function: If your system has a double drem() that follows the IEEE remainder function, compile r_mod.c and d_mod.c with IEEE_drem defined.
    • Ancient K&R C (no void): Add -Dvoid=int to CFLAGS.
    • Non-UNIX STDIO: If you encounter errors regarding cf->_ptr, cf->_base, or stderr->_ptr, insert #define NON_UNIX_STDIO at the beginning of fio.h and recompile.
    • Non-ANSI binary modes: If fopen does not support rb or wb, compile open.c with NON_ANSI_RW_MODES defined.
  6. Build libf2c using makefiles

    main

    The libf2c library is built using makefiles. The default makefile is a copy of makefile.u (a Unix makefile). For other systems, look for files named makefile.* which contain specific invocation instructions. You may need to copy a system-specific makefile.* to makefile before running the build.

    C++ Compiler Setup

    If you are using a C++ compiler, you must first create a suitable f2c.h from f2c.h0 and f2ch.add by running:

    make hadd

    Otherwise, running make f2c.h will simply copy f2c.h0 to f2c.h.

    make hadd
  7. Use the BLAS wrapper in f2c generated code

    main

    To use f2c-style BLAS interfaces that call through to high-performance CBLAS or F77 BLAS routines, include blaswrap.h at the top of your f2c-generated file. This allows you to use interfaces preceded with f2c_ (to avoid name collisions) which wrap the underlying BLAS implementation, helping to maintain performance when using f2c'd codes.

    #include "blaswrap.h"
    // ... rest of your f2c generated code
  8. Detect anime faces in images

    main

    To detect anime character faces, use the animeface.detect() function. This function accepts a PIL.Image object and returns a list of animeface.Face objects. Each Face object contains information about the face position, skin color, hair color, and the positions/colors of eyes, mouth, nose, and chin.

    You can access the bounding box coordinates (x, y, width, height) via the face.pos attribute of a detected face.

    import animeface
    import PIL.Image
    
    # Load an image
    im = PIL.Image.open('/path/to/image.jpg')
    
    # Detect faces
    faces = animeface.detect(im)
    
    # Access the first detected face's bounding box
    if faces:
        fp = faces[0].face.pos
        print(fp.x, fp.y, fp.width, fp.height)
  9. Use the animeface.detect API

    main

    The animeface.detect(im) function is the primary entry point for the library.

    Parameters:

    • im: A PIL.Image.Image object representing the image to analyze.

    Returns:

    • A list of animeface.Face objects.

    The animeface.Face object contains:

    • likelihood: A float representing the detection confidence.
    • face: An object containing pos (the bounding box).
    • skin: Color information.
    • hair: Color information.
    • left_eye, right_eye, mouth, nose, chin: Position and/or color information for facial features.

    For full API definitions, refer to animeface/__init__.py.