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 🙏

© 2026 – Pkg Stats / Ryan Hefner

@koala123/cutils

v2.0.7

Published

c++公共函数的js方法

Readme

c++公共函数的js方法

算法公共函数文档:https://kaolayouran.feishu.cn/docx/TuqrdRKA8oesgnxXCzxcCC8WnIe

安装

npm install @koala123/cutils

使用

此安装包默认使用内部的kl-common.dll,若想替换dll,请使用环境变量KOALA_DLL_PATH

process.env.KOALA_DLL_PATH = 'D:\\kl-storage\\dll\\wafer.dll'

1. 获取版本号

const utils = require('@koala123/utils') as typeof import("@koala123/utils");
utils.get_dll_version();
// kl-common.dll 2025-01-16 16:44:49

2. 图像操作

image类型定义

// 图像
interface image {
  // 图像地址
  path?: string;
  // 图像buffer
  buffer: Buffer;
  // 图像宽
  width: number;
  // 图像高
  height: number;
  // 图像通道
  channel: number;
}

// ROI区域
interface ROI {
  /** 起点x */
  x: number;
  /** 起点y */
  y: number;
  /** 宽 */
  width: number;
  /** 高 */
  height: number;
}

2.1 释放图像数据内存

/**
 * 释放图像数据内存
 */
export declare function free_img(buffer: Buffer): Promise<void>;

2.2 读图

/**
 * 读图
 * @param path 图像地址
 * @param keepAlive 图像指针是否保活,默认会拷贝一份,否则需要调用free_img手动释放
 */
export declare function imread(path: string, keepAlive?: boolean): Promise<image>;

2.3 写图

/**
 * 写图
 * @param image 图像
 * @param path 存图地址,可为空,否则使用image.path
 */
export declare function imwrite(image: image, path?: string): Promise<boolean>;

2.4 图像粘贴

/**
 * 抠图
 * @param srcImage 源图像
 * @param distImage 目标图像
 * @param x 扣取源图像的起点x坐标
 * @param y 扣取源图像的起点y坐标
 */
export declare function imcrop(srcImage: image, distImage: image, x: number, y: number): Promise<boolean>;

2.5 图像粘贴

/**
 * 抠图
 * @param srcImage 源图像
 * @param roi 拷贝区域
 * @param savePath 存图地址,为空则不存图
 */
export declare function imcropByROI(srcImage: image, roi: ROI, savePath?: string): Promise<image>;

2.6 拼接全景图

interface MosaicImagesParam {
    /** 源图像目录 */
    srcImgDir: string;
    /** 全景图像素分辨率,单位为um */
    unit: number;
    /** 待拼接图像标定的镜头参数(像素标定矩阵) */
    calibParams: number[];
    /** 全景图存储地址 */
    distImgPath: string;
    /** 源图像坐标解析函数:文件名->图像采集的机械坐标[x,y] */
    parseMotorFn: (filename: string) => number[];
    /** 拼接进度 */
    progressFn?: (current: number, total: number) => void;
}
/**
 * 拼接全景图
 */
export declare function mosaicImages(param: MosaicImagesParam): Promise<void>;

3. 坐标转换

3.1 图像坐标变换至机械坐标(将imgCoor点置于图像中心需行进到的x/y轴位置)

/**
 * 图像坐标变换至机械坐标(将imgCoor点置于图像中心需行进到的x/y轴位置)
 * @param imgCoor [double[2*n]] 图像坐标(x/y坐标)
 * @param curMotorCoor [double[2]] 采图时的x/y轴位置读数
 * @param calibParams [double[13]] 像素标定参数
 * @returns [double[2*n]] 机械坐标(x/y坐标)
 */
export declare function transformBiaxial(imgCoor: number[], curMotorCoor: number[], calibParams: number[]): Promise<number[]>;

3.2 图像坐标变换至世界(物料)坐标

/**
 * 图像坐标变换至世界(物料)坐标
 * @param imgCoor [double[2*n]] 图像坐标(x/y坐标)
 * @param curMotorCoor [double[2]] 采图时的x/y轴位置读数
 * @param calibParams [double[13]] 像素标定参数
 * @param rectifyParams [double[9]] 坐标变换矩阵(可为NULL表示恒等变换, 此时传出(各倍镜)统一坐标)
 * @returns [double[2*n]] 世界坐标(x/y坐标)
 */
export declare function transformWorld(imgCoor: number[], curMotorCoor: number[], calibParams: number[], rectifyParams?: number[]): Promise<number[]>;

3.3 世界(物料)坐标反变换至图像坐标

/**
 * 世界(物料)坐标反变换至图像坐标
 * @param worldCoor [double[2*n]] 世界坐标(x/y坐标)
 * @param curMotorCoor [double[2]] 采图时的x/y轴位置读数
 * @param calibParams [double[13]] 像素标定参数
 * @param rectifyParams [double[9]] 坐标变换矩阵(可为NULL表示恒等变换, 此时传出(各倍镜)统一坐标)
 * @returns [double[2*n]] 图像坐标(x/y坐标)
 */
export declare function transformInvWorld(worldCoor: number[], curMotorCoor: number[], calibParams: number[], rectifyParams?: number[]): Promise<number[]>;

3.4 将世界坐标置于图像中心时,需行进到的x/y轴位置

/**
 * 将世界坐标置于图像中心时,需行进到的x/y轴位置
 * @param worldCoor [double[2*n]] 世界坐标(x/y坐标)
 * @param calibParams [double[13]] 像素标定参数
 * @param rectifyParams [double[9]] 坐标变换矩阵(可为NULL表示恒等变换, 此时传出(各倍镜)统一坐标)
 * @returns [double[2*n]] x/y轴目标位置
 */
export declare function transformInvWorldCenter(worldCoor: number[], calibParams: number[], rectifyParams?: number[]): Promise<number[]>;

3.5 物料坐标转换至行列坐标

/**
 * 物料坐标转换至行列坐标
 * @param worldCoor [double[2*n]] 世界坐标(x/y坐标)
 * @param mapParams [double[9]] 投影矩阵
 * @returns [double[2*n]] 行列坐标(列x/行y坐标)
 */
export declare function transformMapping(worldCoor: number[], mapParams: number[]): Promise<number[]>;

3.6 行列坐标反变换至物料坐标

/**
 * 行列坐标反变换至物料坐标
 * @param mapCoor [double[2*n]] 行列坐标(列x/行y坐标)
 * @param mapParams [double[9]] 投影矩阵(正变换矩阵)
 * @returns [double[2*n]] 物料坐标(x/y坐标)
 */
export declare function transformInvMapping(mapCoor: number[], mapParams: number[]): Promise<number[]>;

4. 内存管理

4.1 在其他进程中引用共享内存

/**
 * 分配共享内存
 * @param name 共享内存块名称(其他进程ref引用时需同名)
 * @param size 共享内存块大小(字节单位)
 * @returns 共享内存块在本进程中的首地址
 */
export declare function shmalloc(name: string, size: number): Buffer;

4.2 在其他进程中引用共享内存

/**
 * 在其他进程中引用共享内存
 * @param name 共享内存块名称
 * @returns 共享内存块在本进程中的首地址
 */
export declare function ref(name: string): Buffer;

4.3 释放共享内存在本进程中的引用

/**
 * 释放共享内存在本进程中的引用
 * @param name 共享内存块名称
 * @param ptr 共享内存块在本进程中的首地址
 */
export declare function unref(name: string, ptr: Buffer): void;

4.4 释放堆内存,按指针传递

/**
 * 释放堆内存,按指针传递
 * @param ptr 堆内存指针
 */
export declare function free_ptr(ptr: Buffer): void;

5. 标定

标定参数定义

// 标定参数
interface CalibrateBoardCoor {
  boardSize: Buffer;
  imgCoor: Buffer;
  angle: Buffer;
}

5.1 采用棋盘格或圆形点阵标定板,计算点坐标

/**
 * 采用棋盘格或圆形点阵标定板,计算点坐标
 * @param image 图像
 * @param type 圆形点阵: 0; 棋盘格: 1; 物料本身 2
 * @param modelFile type为2时的物料模型文件
 */
export declare function findCalibrateBoardCoor(image: image, type: number, modelFile?: string): Promise<CalibrateBoardCoor>;

5.2 标定相机参数

/**
 * 标定相机参数
 * @param image 图像
 * @param calibrateBoardCoor findCalibrateBoardCoor返回值
 * @param rationalModel 是否使用理想模型
 * @param thinPrismModel 是否使用薄棱镜模型
 * @param tiltedModel 是否使用倾斜模型
 * @param ratio 标定目标之间的dx / dy的比值 默认使用圆形标定板的比值是 1
 * @returns [double[19]] 畸变参数
 */
export declare function estimateCameraParams(image: image, calibrateBoardCoor: CalibrateBoardCoor, rationalModel: boolean, thinPrismModel: boolean, tiltedModel: boolean, ratio?: number): Promise<number[]>;

5.3 图像上绘制网格, 判定图像的畸变程度、或者畸变校正的效果

/**
 * 图像上绘制网格, 判定图像的畸变程度、或者畸变校正的效果
 * @param image 图像
 * @param calibrateBoardCoor findCalibrateBoardCoor返回值
 */
export declare function drawGridOnImage(image: image, calibrateBoardCoor: CalibrateBoardCoor): Promise<boolean>;

5.4 计算mark(圆)的图像偏移量;用于像素标定与旋转标定每一帧图

/**
 * 计算mark(圆)的图像偏移量;用于像素标定与旋转标定每一帧图
 * 此接口会更改原图像数据:绘制圆及圆中心
 * @param image 图像
 * @param tpl 模板图像
 * @retuns [double[2]] 圆的图像坐标(x/y坐标)
 */
export declare function calibCircleLocalization(image: image, tpl: image): Promise<number[]>;

5.5 获取像素标定参数,根据标定图像坐标偏移量、机械坐标偏移量,计算变换矩阵

/**
 * 获取像素标定参数,根据标定图像坐标偏移量、机械坐标偏移量,计算变换矩阵
 * @param width 图像宽
 * @param height 图像高
 * @param imgCoors [double[2*n]] 圆的图像坐标(x/y坐标)
 * @param moterCoors [double[2*n]] 采图时的x/y轴位置读数
 * @retuns [double[13]] 像素标定参数
 */
export declare function estimateBixialParams(width: number, height: number, imgCoors: number[][], moterCoors: number[][]): Promise<number[]>;

5.6 计算载台旋转中心

/**
 * 计算载台旋转中心
 * @param imgCoors [double[2*n]] 圆的图像坐标(x/y坐标)
 * @param moterCoors [double[3*n]] 采图时的x/y/r轴位置读数
 * @param calibParams [double[13]] 像素标定参数
 * @retuns [double[2]] 旋转中心坐标(x/y(mm))
 */
export declare function estimateRotateCenter(imgCoors: number[][], moterCoors: number[][], calibParams: number[]): Promise<number[]>;

5.7 计算一个更高精度的载台旋转中心

/**
 * 计算一个更高精度的载台旋转中心
 * 在旋转中心附近,R=-180/-90/0/90度采集的四张图像
 * @param images [image[n]] 图像列表
 * @param moterCoor [double[2]] 采图时的x/y轴位置读数
 * @param calibParams [double[13]] 像素标定参数
 * @retuns [double[2]] 旋转中心坐标(x/y(mm))
 */
export declare function estimateAccurateRotateCenter(images: image[], moterCoor: number[], calibParams: number[]): Promise<number[]>;