增加Mat数据获取
This commit is contained in:
@ -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();
|
||||
|
@ -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)); }
|
||||
|
@ -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)!);
|
||||
|
Reference in New Issue
Block a user