python-animeface
repository·main·Indexed 41 days ago
https://github.com/nya3jp/python-animefaceA 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.
What's inside python-animeface
- Pillow is a friendly fork of the Python Imaging Library (PIL). It is used for image processing in Python and serves as the modern replacement for the original PIL library.
Install libnvxs from source
mainIf a Python binary package (wheel) is not available for your specific environment, you must manually install
libnvxs(the original AnimeFace library) before installingpython-animeface. The source code forlibnvxsis located in thethird_party/nvxs-1.0.2directory of this repository.Follow these steps to build and install it:
cd third_party/nvxs-1.0.2 ./configure make sudo make installAccess Pillow documentation and installation guides
mainFor detailed information on how to use Pillow, you can refer to the official documentation resources:
- Main Documentation: https://pillow.readthedocs.io/
- Installation Guide: https://pillow.readthedocs.io/en/latest/installation.html
- Pillow Handbook: https://pillow.readthedocs.io/en/latest/handbook/index.html
Install python-animeface via PIP
mainYou can install the
animefacemodule directly using PIP. If a prebuilt wheel is available for your environment, this will also include the necessarylibnvxsdependency.pip install animefaceVerify CLAPACK and BLAS correctness
mainAfter 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
*.SUMMfiles 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 Makeblat32. Test LAPACK
Build the matrix generation software and the specific testing routines (Eigen or Linear System), then run the LAPACK tests. Inspect
*.outfiles for errors.cd CLAPACK/TESTING/MATGEN; make cd CLAPACK/TESTING; makeInstall CLAPACK via fast default installation
mainTo perform a standard installation of CLAPACK, follow these steps in order:
- Extract and Configure: Untar
clapack.tarand modify themake.incfile to match your system's compiler and flags. You can find samplemake.incfiles in theINSTALL/subdirectory. - Build f2c libraries: Run
make f2clibfrom the main directory. - Build BLAS library: Run
make blaslibfrom the main directory to use the included reference BLAS (note: this is not optimized for speed). - Build LAPACK: Run
makefrom the main directory to compile the main library. - Test: Run
makefrom the main directory to test and time the installation.
tar xvf clapack.tar # Modify make.inc first make f2clib make blaslib make- Extract and Configure: Untar
Enable INTEGER*8 (64-bit integers) in libf2c
mainTo use 64-bit integers (
INTEGER*8), follow these steps:- Modify
f2c.h: Uncomment thetypedefsforlongintandulongintand adjust them to:typedef long longint; typedef unsigned long ulongint; - Update Makefile:
- Add
-DAllow_TYQUADto theCFLAGSassignment. - Add
$(QINT)to the end of the dependency list forlibf2c.a(if usingmakefile.u). - If using PC makefiles, add
pow_qq.obj qbitbits.obj qbitshft.objto the library's dependency list and adjustlibf2c.lbcorlibf2c.syaccordingly.
- Add
- Optional: You may also add
-DINTEGER_STAR_8to theCFLAGSassignment.
# Example CFLAGS modification CFLAGS = -DAllow_TYQUAD -DINTEGER_STAR_8- Modify
Configure libf2c compiler flags for compatibility
mainDepending on your compiler and system architecture, you may need to define specific macros in your
CFLAGSwithin the makefile:- Non-ANSI C headers: Add
-DKR_headerstoCFLAGSor insert#define KR_headersat the top off2c.h. - Missing
onexit(): If your system lacksonexit()and you aren't using an ANSI C compiler, compilemain.cwithNO_ONEXITdefined. - IEEE
drem()function: If your system has a doubledrem()that follows the IEEE remainder function, compiler_mod.candd_mod.cwithIEEE_dremdefined. - Ancient K&R C (no
void): Add-Dvoid=inttoCFLAGS. - Non-UNIX STDIO: If you encounter errors regarding
cf->_ptr,cf->_base, orstderr->_ptr, insert#define NON_UNIX_STDIOat the beginning offio.hand recompile. - Non-ANSI binary modes: If
fopendoes not supportrborwb, compileopen.cwithNON_ANSI_RW_MODESdefined.
- Non-ANSI C headers: Add
Build libf2c using makefiles
mainThe
libf2clibrary is built using makefiles. The defaultmakefileis a copy ofmakefile.u(a Unix makefile). For other systems, look for files namedmakefile.*which contain specific invocation instructions. You may need to copy a system-specificmakefile.*tomakefilebefore running the build.C++ Compiler Setup
If you are using a C++ compiler, you must first create a suitable
f2c.hfromf2c.h0andf2ch.addby running:make haddOtherwise, running
make f2c.hwill simply copyf2c.h0tof2c.h.make haddUse the BLAS wrapper in f2c generated code
mainTo use f2c-style BLAS interfaces that call through to high-performance CBLAS or F77 BLAS routines, include
blaswrap.hat the top of your f2c-generated file. This allows you to use interfaces preceded withf2c_(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 codeDetect anime faces in images
mainTo detect anime character faces, use the
animeface.detect()function. This function accepts aPIL.Imageobject and returns a list ofanimeface.Faceobjects. EachFaceobject 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.posattribute 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)Use the animeface.detect API
mainThe
animeface.detect(im)function is the primary entry point for the library.Parameters:
im: APIL.Image.Imageobject representing the image to analyze.
Returns:
- A
listofanimeface.Faceobjects.
The
animeface.Faceobject contains:likelihood: A float representing the detection confidence.face: An object containingpos(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.