Socket
Socket
Sign inDemoInstall

detectanime

Package Overview
Dependencies
121
Maintainers
1
Versions
1
Alerts
File Explorer

Advanced tools

Install Socket

Detect and block malicious and high-risk dependencies

Install

    detectanime

Detects anime/manga characters in Node.js


Version published
Weekly downloads
1
Maintainers
1
Created
Weekly downloads
 

Readme

Source

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[]
}
Source

Keywords

FAQs

Last updated on 27 Jan 2021

Did you know?

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc