增加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

@ -50,6 +50,7 @@ class CVMat : public ObjectWrap<CVMat> {
MAT_INSTANCE_METHOD(GetTotal),
MAT_INSTANCE_METHOD(GetTotalWithDim),
MAT_INSTANCE_METHOD(GetSize),
MAT_INSTANCE_METHOD(GetData),
MAT_INSTANCE_METHOD(Col),
MAT_INSTANCE_METHOD(ColRange),
@ -58,6 +59,7 @@ class CVMat : public ObjectWrap<CVMat> {
MAT_INSTANCE_METHOD(Diag),
MAT_INSTANCE_METHOD(Clone),
MAT_INSTANCE_METHOD(CopyTo),
});
constructor = new FunctionReference();
@ -159,7 +161,12 @@ class CVMat : public ObjectWrap<CVMat> {
for (int i = 0; i < mat_.dims; ++i) ret.Set(i, size[i]);
return ret;
}
Napi::Value GetData(const Napi::CallbackInfo &info)
{
auto ptr = mat_.ptr();
auto bytes = mat_.elemSize() * mat_.total();
return ArrayBuffer::New(info.Env(), ptr, bytes);
}
Napi::Value Col(const Napi::CallbackInfo &info)
{
@ -194,7 +201,11 @@ class CVMat : public ObjectWrap<CVMat> {
{
return CreateMat(info.Env(), [&](CVMat &mat) { mat.mat_ = mat_.clone(); });
}
Napi::Value CopyTo(const Napi::CallbackInfo &info) {
auto &target = GetMat(info[0].As<Object>());
mat_.copyTo(target.mat_);
return info.Env().Undefined();
}
static Napi::Value Crop(const Napi::CallbackInfo &info)
{