Options
All
  • Public
  • Public/Protected
  • All
Menu

The class of image object, constructed by the Mat, or by readImage, decodeImage etc. functions.

Hierarchy

  • Image

Index

Constructors

constructor

Accessors

c4mat

  • get c4mat(): Mat
  • Get the Mat object of the 4-channel (BGRA) format.

    Returns Mat

height

  • get height(): number
  • Get the height of the image.

    Returns number

mat

  • get mat(): Mat

width

  • get width(): number
  • Get the width of the image.

    Returns number

Methods

clip

  • Clip the image with the given region, return the clipped image asynchronously.

    example
    "nodejs";
    const cv = require("@autojs/opencv");
    const { loadImage } = require("image");
    
    async function main() {
        const img = await loadImage("https://picsum.photos/200/300");
        console.log(await img.clip(new cv.Rect(0, 0, 100, 100)));
    }
    main();
    

    Parameters

    • rect: Rect

      The region to clip

    Returns Promise<Image>

clipSync

  • Clip the image with the given region, return the clipped image synchronously.

    example
    "nodejs";
    const cv = require("@autojs/opencv");
    const { loadImage } = require("image");
    
    async function main() {
        const img = await loadImage("https://picsum.photos/200/300");
        console.log(img.clipSync(new cv.Rect(0, 0, 100, 100)));
    }
    main();
    

    Parameters

    • rect: Rect

      The region to clip

    Returns Image

copy

  • Copy the image and return the promise of the new image instance.

    Returns Promise<Image>

copySync

  • Copy the image and return the new image instance synchronously.

    Returns Image

detectAndComputeFeatures

grayscale

  • grayscale(): Promise<Image>
  • Grayscale the image, and return a new image object of the gray image asynchronously.

    Returns Promise<Image>

grayscaleSync

  • Grayscale the image, and return a new image object of the gray image synchronously.

    Returns Image

pixel

  • pixel(x: number, y: number): Color
  • Get the color at the position (x, y) of the image. If the image is a 3-channel image, then assume it is in BGR format; if it is a 4-channel image, then assume it is in BGRA format; if it is a single-channel image, then assume it is in gray-scale.

    example
    "nodejs";
    const { loadImage } = require("image");
    
    async function main() {
        const img = await loadImage("https://picsum.photos/200/300");
        console.log(img.pixel(0, 0));
    }
    main();
    

    Parameters

    • x: number
    • y: number

    Returns Color

recycle

  • recycle(): void
  • Release the image object. After release, the object should not be used.

    Returns void

resize

  • resize(width: number, height: number, interpolation?: number): Promise<Image>
  • Scale the image, return a new image asynchronously.

    Parameters

    • width: number

      The width of the scaled image.

    • height: number

      The height of the scaled image.

    • interpolation: number = ...

      Interpolation method, default is {@link cv.INTER_LINEAR}. Can be {@link cv.INTER_AREA}, {@link cv.INTER_CUBIC}, {@link cv.INTER_LANCZOS4}, {@link cv.INTER_LINEAR}, {@link cv.INTER_NEAREST}.

    Returns Promise<Image>

resizeSync

  • resizeSync(width: number, height: number, interpolation?: number): Image
  • Scale the image, return a new image synchronously.

    Parameters

    • width: number

      The width of the scaled image.

    • height: number

      The height of the scaled image.

    • interpolation: number = ...

      Interpolation method, default is {@link cv.INTER_LINEAR}. Can be {@link cv.INTER_AREA}, {@link cv.INTER_CUBIC}, {@link cv.INTER_LANCZOS4}, {@link cv.INTER_LINEAR}, {@link cv.INTER_NEAREST}.

    Returns Image

rotate

  • rotate(degree: number, center?: Point2): Promise<Image>
  • Rotate the image by the specified degree. If the center is not specified, then the center of the image is used. Asynchronously return the rotated image.

    Parameters

    • degree: number
    • Optional center: Point2

    Returns Promise<Image>

rotateSync

  • Rotate the image by the specified degree. If the center is not specified, then the center of the image is used. Synchronously return the rotated image.

    Parameters

    • degree: number
    • Optional center: Point2

    Returns Image

scale

  • scale(fx: number, fy?: number, interpolation?: number): Promise<Image>
  • Scale the image, return a new image asynchronously.

    Parameters

    • fx: number

      x-axis scaling ratio (width)

    • fy: number = ...

      y-axis scaling ratio (height)

    • interpolation: number = ...

      Interpolation method, default is {@link cv.INTER_LINEAR}. Can be {@link cv.INTER_AREA}, {@link cv.INTER_CUBIC}, {@link cv.INTER_LANCZOS4}, {@link cv.INTER_LINEAR}, {@link cv.INTER_NEAREST}.

    Returns Promise<Image>

scaleSync

  • scaleSync(fx: number, fy?: number, interpolation?: number): Image
  • Scale the image, return a new image synchronously.

    Parameters

    • fx: number

      x-axis scaling ratio (width)

    • fy: number = ...

      y-axis scaling ratio (height)

    • interpolation: number = ...

      Interpolation method, default is {@link cv.INTER_LINEAR}. Can be {@link cv.INTER_AREA}, {@link cv.INTER_CUBIC}, {@link cv.INTER_LANCZOS4}, {@link cv.INTER_LINEAR}, {@link cv.INTER_NEAREST}.

    Returns Image

toBitmap

  • toBitmap(): Bitmap
  • Convert the image to an android Bitmap object.

    see

    Bitmap

    Returns Bitmap

Static ofBitmap

  • ofBitmap(bitmap: Bitmap): Image
  • Convert an android Bitmap object to an Image object. If the Bitmap is null or not a Bitmap object, then throw an exception.

    see

    Bitmap

    Parameters

    • bitmap: Bitmap

    Returns Image