npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

detectanime

v0.0.1

Published

Detects anime/manga characters in Node.js

Downloads

6

Readme

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

/*You can specify a custom cascade file so in theory, you can use this to detect any object.*/
const customObject = await detectanime("./images/obj.png", {cascade: "cascade.xml"})

/*Fine tune the results by setting scaleFactor, minNeighbors, etc.*/
const withOptions = await detectanime("./images/stuff.jpg", {scaleFactor: 1.1, minNeighbors: 5, minSize: [24, 24]})

/*Set the writeDir to draw a rectangle over the detected area and write the file to that directory. The destination will
be available in the result under the dest property. You can also specify the color and thickness.*/
const drawRectangle = await detectanime("./images/anime.png", {writeDir: "./images", color: "blue", thickness: 2})

/*Gifs have an additional option skipFactor that may speed things up on large files. Setting it to 2 will only extract
every other frame, for example.*/
const fasterGif = await detectanime("./images/largegif.gif", {skipFactor: 2})

/*You can also optimize videos by setting a lower framerate (default is the same as original).*/
const fasterVideo = await detectanime("./videos/episode.mp4", {framerate: 24})

/*Set the downloadDir to download an image, gif, or video locally if you pass in a link.*/
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[]
}