Security News
38% of CISOs Fear They’re Not Moving Fast Enough on AI
CISOs are racing to adopt AI for cybersecurity, but hurdles in budgets and governance may leave some falling behind in the fight against cyber threats.
kl-camera-frontend
Advanced tools
此库封装了相机开始采集、停止采集、切换采集模式、开始订阅、停止订阅、订阅参数更新、设置曝光、获取曝光、设置畸变参数等相机实时画面预览相关业务的接口,但对应SDK的调用需要通过配置回调函数传入
Install with npm:
npm install kl-camera-frontend
setConfig({
// 开始采集
grabStart?: (camera: Camera) => Promise<boolean>,
// 停止采集
grabStop?: (camera: Camera) => Promise<boolean>,
// 设置曝光
setExposureTime?: (camera: Camera, expTime: number) => Promise<void>,
// 获取曝光
getExposureTime?: (camera: Camera) => Promise<number>,
// 设置畸变参数
undistort?: (camera: Camera, undistortParam: number[] | null) => Promise<void>,
// 开始订阅
startSubscribe?: (subscribe: Subscribe, cb: (imageData: ImageData) => void) => Promise<void>,
// 停止订阅
stopSubscribe?: (subscribe: Subscribe) => Promise<void>,
// 更新订阅参数
updateSubscribe?: (subscribe: Subscribe) => Promise<void>,
// 销毁订阅
destorySubscribe?: (subscribe: Subscribe) => Promise<void>,
// 采集一帧图像
grabImage<T>(subscribe: Subscribe, save?: boolean): Promise<T | undefined>,
});
new Camera(param: {
// 相机id
id: number,
// 相机名称
name: string,
// 相机型号
model: string,
// 相机SN
sn: string,
// 相机输出图像宽
width: number,
// 相机输出图像高
height: number,
// 相机输出图像通道
channel: number,
}) => Camera
{
// 相机id
id: number,
// 相机名称
name: string,
// 相机型号
model: string,
// 相机SN
sn: string,
// 相机输出图像宽
width: number,
// 相机输出图像高
height: number,
// 相机输出图像通道
channel: number,
// 描述:name + sn
desc: string,
// 订阅列表
subscribes: Subscribe[],
// 是否正在采集图像
isGrabing: boolean;
// 触发方式;grabInternal|grabExternal|grabOnce
grabType: string;
// 第一个正在订阅的Subscribe
firstWorkSubscribe: Subscribe | undefined;
}
/**
* @param name 订阅名;默认为时间戳
*/
createSubscribe(listener: (imageData: ImageData, sub: Subscribe) => void, name?: string) => Subscribe
grabStart() => Promise<void>
grabStop() => Promise<void>
/**
* 若相机正在采集图像(且采集模式不一致),会先停止采集再切换
*/
swicthGrabType(type: 'grabInternal' | 'grabExternal' | 'grabOnce') => void
/**
* @param save 是否存储
* @param subscribe 非空时为第一个正在订阅的Subscribe
*/
grabImage<T>(save?: boolean, subscribe?: Subscribe) => Promise<T | undefined>
setExposureTime(expTime: number) => Promise<void>
getExposureTime() => Promise<number>
undistort(undistortParam: number[] | null) => Promise<void>
removeName() => void
addName(name: string) => void
{
// 订阅的相机
camera: Camera;
// 订阅名称
name: string;
// 订阅的回调函数
listener: (imageData: ImageData, sub: Subscribe) => void;
// 订阅的宽
width: number;
// 订阅的高
height: number;
// 订阅的缩放比例
scale: number;
// 订阅的dx
dx: number;
// 订阅的dy
dy: number;
// 是否已订阅
isSubscribed: boolean;
}
/**
* @param silent 对应相机是否静默,否则开始采集图像
*/
startSubscribe(silent?: boolean) => Promise<void>
/**
* @param silent 对应相机是否静默,否则停止采集图像
*/
stopSubscribe(silent?: boolean) => Promise<void>
/**
* @param param 订阅参数:[width, height, scale, dx, dy]
*/
updateParam(param: number[]) => void
/**
* 组件卸载时若有资源需要释放可以调用此接口
*/
destorySubscribe() => Promise<void>
/**
* @param save 是否存储图像
*/
grabImage<T>(save?: boolean) => Promise<T | undefined>
import { Camera, setConfig } from 'kl-camera-frontend';
// 创建相机
const camera = new Camera({
id: 1,
name: 'test',
model: 'MODEL',
sn: 'SN-TEST',
width: 5120,
height: 5120,
channel: 3,
})
// 创建订阅
const sub = camera.createSubscribe((imageData) => {
console.log(imageData.width, imageData.height);
});
// 设置全局参数
setConfig({
async grabStart(camera: Camera) {
console.log(`${camera.desc}: ${camera.grabType} grabStart...`);
return true;
},
async grabStop(camera: Camera) {
console.log(`${camera.desc}: grabStop...`);
return false;
},
async startSubscribe(subscribe: Subscribe, cb: (imageData: ImageData) => void) {
console.log(`${subscribe.camera.desc}/${subscribe.name}: startSubscribe...`);
cb(new ImageData(subscribe.width, subscribe.height));
},
async stopSubscribe(subscribe: Subscribe) {
console.log(`${subscribe.camera.desc}/${subscribe.name}: stopSubscribe...`);
},
async updateSubscribe(subscribe: Subscribe) {
console.log(`${subscribe.name}/${subscribe.camera.desc}: updateSubscribe...`);
}
})
// 开始订阅
sub.startSubscribe();
setTimeout(() => {
// 停止订阅
sub.stopSubscribe();
}, 10000)
若使用已定义好的c+=库方法,使用方式如下:
import { Camera, setConfig } from 'kl-camera-frontend';
import { useLibrary } from 'kl-camera-frontend/useLibrary';
const { Callback, Library } = require("ffi-napi") as typeof import("ffi-napi");
// 创建相机
const camera = new Camera({
id: 1,
name: 'test',
model: 'MODEL',
sn: 'SN-TEST',
width: 5120,
height: 5120,
channel: 3,
})
// 创建订阅
const sub = camera.createSubscribe((imageData) => {
console.log(imageData.width, imageData.height);
});
// dll库路径与图像存储地址
useLibrary({
Callback,
Library,
dllPath: 'c.dll',
generationImagePath: () => {
`D:/img/${Date.now().png}`;
}
})
// 开始订阅
sub.startSubscribe();
setTimeout(() => {
// 停止订阅
sub.stopSubscribe();
}, 10000)
FAQs
We found that kl-camera-frontend demonstrated a healthy version release cadence and project activity because the last version was released less than a year ago. It has 1 open source maintainer collaborating on the project.
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.
Security News
CISOs are racing to adopt AI for cybersecurity, but hurdles in budgets and governance may leave some falling behind in the fight against cyber threats.
Research
Security News
Socket researchers uncovered a backdoored typosquat of BoltDB in the Go ecosystem, exploiting Go Module Proxy caching to persist undetected for years.
Security News
Company News
Socket is joining TC54 to help develop standards for software supply chain security, contributing to the evolution of SBOMs, CycloneDX, and Package URL specifications.