增加Mat数据获取

This commit is contained in:
2025-03-17 11:51:48 +08:00
parent 84f388f294
commit 27a24d0073
6 changed files with 36 additions and 5 deletions

View File

@ -9,7 +9,7 @@ const URLS = {
}
function getURL(template: string) {
const version = require("../../package.json").version;
const version = require("../../package.json").releaseVersion;
let platform = "";
let arch = "";
switch (os.platform()) {
@ -49,7 +49,7 @@ export async function downloadAddon(savename?: string) {
const defaultAddon = path.resolve(process.cwd(), C("ADDON_PATH"));
const saveName = savename ? path.resolve(path.dirname(defaultAddon), savename) : defaultAddon;
if (fs.existsSync(saveName)) return saveName;
await fs.promises.mkdir(path.dirname(saveName), { recursive: true });
const stream = await getStream();

View File

@ -35,8 +35,13 @@ export class Mat {
else return this.#mat.GetTotalWithDim(startDim, endDim ?? 2147483647);
}
public get size(): number[] { return this.#mat.GetSize(); }
public get data(): Uint8Array {
if (this.isContinuous) return new Uint8Array(this.#mat.GetData());
else return this.copyTo(this.clone()).data;
}
public clone() { return FromCV(this.#mat.Clone()); }
public copyTo(mat: Mat) { return this.#mat.CopyTo(M(mat)), mat; }
public row(y: number) { return FromCV(this.#mat.Row(y)); }
public col(x: number) { return FromCV(this.#mat.Col(x)); }

View File

@ -8,6 +8,7 @@ async function test() {
const res = await cv.imread("test_data/im1.jpeg");
// const res = await cv.imdecode(buffer);
const cropIm = cv.crop(res, { x: 10, y: 10, width: 300, height: 200 });
console.log(cropIm.data)
console.log(cv.imwrite("test_data/cropIm.jpg", cropIm));
fs.writeFileSync("test_data/base.jpg", cv.imencode(".jpg", res)!);