About
This package uses OpenCV and the lbpcascade_animeface cascade to detect anime faces in images, gifs, or videos. For video detection you also need to have ffmpeg installed.
Insall
npm install detectanime
Basic Usage
There is just one exported function that accepts either a link or file path to an image, gif, or video. If openCV detects an
anime character, it returns DetectAnimeResult
, otherwise it returns null
. That's it.
import detectanime from "detectanime"
const image = await detectanime("https://i.pximg.net/img-original/img/2020/12/13/00/00/01/86261493_p0.png")
const gif = await detectanime("https://media.giphy.com/media/XOYUlNCFwsivS/giphy.gif")
const video = await detectanime("https://thumbs.gfycat.com/BriskRegularAnt-mobile.mp4")
Advanced Usage
const customObject = await detectanime("./images/obj.png", {cascade: "cascade.xml"})
const withOptions = await detectanime("./images/stuff.jpg", {scaleFactor: 1.1, minNeighbors: 5, minSize: [24, 24]})
const drawRectangle = await detectanime("./images/anime.png", {writeDir: "./images", color: "blue", thickness: 2})
const fasterGif = await detectanime("./images/largegif.gif", {skipFactor: 2})
const fasterVideo = await detectanime("./videos/episode.mp4", {framerate: 24})
const download = await detectanime("https://i.pximg.net/img-original/img/2014/04/30/02/44/47/43194202_p0.jpg", {downloadDir: "./images"})
DetectAnimeOptions
export interface DetectAnimeOptions {
cascade?: string
scaleFactor?: number
minNeighbors?: number
minSize?: number[]
maxSize?: number[]
skipFactor?: number
framerate?: number
ffmpegPath?: string
downloadDir?: string
thickness?: number
color?: string
writeDir?: string
}
DetectAnimeResult
Only videos and gifs will have the frame property (frame where the anime character was detected).
The dest property is available if you set the writeDir to draw the rectangles.
export interface DetectAnimeResult {
frame?: number
dest?: string
objects: Array<{
height: number
width: number
x: number
y: number
}>
numDetections: number[]
}
Source