c++ - cv::createLineSegmentDetector() 函数的 Opencv4nodejs 插件崩溃。异常只能被 catch(...) 捕获。如何调试异常类型?
问题描述
我正在尝试将 cv::LineSegmentDetector 集成到 opencv4nodejs,这是 opencv 的一个节点插件(链接:https ://github.com/justadudewhohacks/opencv4nodejs )。我已经成功编译了一个由 require 加载的 opencv4nodejs 模块。最初在将 opencv4nodejs.node 模块加载到 js 时遇到了 opencv_core.dll 和 opencv_imgproc.dll 的问题。但是 cv::createLineSegmentDetector() 崩溃 catch( std::exception &e) 不起作用但 catch(...) 异常捕获它。但它仍然不起作用。
这是代码。
#include <nan.h>
#include <opencv2/core.hpp>
#include <opencv2/imgproc.hpp>
#include "macros.h"
class LineSegmentDetector : public Nan::ObjectWrap
{
public:
cv::Ptr<cv::LineSegmentDetector> m_plsd;
static NAN_MODULE_INIT(Init);
static NAN_METHOD(New);
static NAN_METHOD(Detect);
static Nan::Persistent<v8::FunctionTemplate> constructor;
};
这是CC文件。
#include "LineSegmentDetector.h"
#include "Mat.h"
#include "Vec4.h"
Nan::Persistent<v8::FunctionTemplate> LineSegmentDetector::constructor;
// Nan::Persistent<v8::FunctionTemplate> Mat::constructor;
// Nan::Persistent<v8::FunctionTemplate> Vec4::constructor;
NAN_MODULE_INIT(LineSegmentDetector::Init)
{
v8::Local<v8::FunctionTemplate> ctor = Nan::New<v8::FunctionTemplate>(LineSegmentDetector::New);
constructor.Reset(ctor);
ctor->InstanceTemplate()->SetInternalFieldCount(1);
ctor->SetClassName(Nan::New("LineSegmentDetector").ToLocalChecked());
Nan::SetPrototypeMethod(ctor, "detect", LineSegmentDetector::Detect);
target->Set(Nan::New("LineSegmentDetector").ToLocalChecked(), ctor->GetFunction());
}
std::string handle_eptr(std::exception_ptr eptr) // passing by value is ok
{
try
{
if (eptr)
{
std::rethrow_exception(eptr);
}
}
catch (const std::exception &e)
{
return std::string("Caught exception \"") + e.what() + std::string("\"\n");
}
}
NAN_METHOD(LineSegmentDetector::New)
{
// throw an error if constructor is called without new keyword
if (!info.IsConstructCall())
{
return Nan::ThrowError(Nan::New("LineSegmentDetector::New - called without new keyword").ToLocalChecked());
}
LineSegmentDetector *self = new LineSegmentDetector();
if (self == nullptr)
{
return Nan::ThrowError(Nan::New("LineSegmentDetector::New - self was null").ToLocalChecked());
}
try
{
self->m_plsd = cv::createLineSegmentDetector();
}
catch (...)
{
// std::exception_ptr eptr = std::current_exception();
return Nan::ThrowError(Nan::New("LineSegmentDetector::New - cv::createLineSegmentDetector failed").ToLocalChecked());
}
self->Wrap(info.Holder());
// return the wrapped javascript instance
info.GetReturnValue().Set(info.Holder());
}
NAN_METHOD(LineSegmentDetector::Detect)
{
FF::TryCatch tryCatch("LineSegmentDetector::Detect");
cv::Mat gray;
if (Mat::Converter::arg(0, &gray, info))
{
return tryCatch.reThrow();
}
LineSegmentDetector *self = Nan::ObjectWrap::Unwrap<LineSegmentDetector>(info.This());
std::vector<cv::Vec4f> lines;
self->m_plsd->detect(gray, lines);
v8::Local<v8::Value> val = Vec4::ArrayWithCastConverter<cv::Vec4f>::wrap(lines);
info.GetReturnValue().Set(val);
}
解决方案
据我了解,我的代码没有问题,版本 3.4 中不存在实现。
LineSegmentDetectorImpl::LineSegmentDetectorImpl(int _refine, double _scale, double _sigma_scale, double _quant,
double _ang_th, double _log_eps, double _density_th, int _n_bins)
{
CV_Assert(_scale > 0 && _sigma_scale > 0 && _quant >= 0 &&
_ang_th > 0 && _ang_th < 180 && _density_th >= 0 && _density_th < 1 &&
_n_bins > 0);
CV_UNUSED(_refine); CV_UNUSED(_log_eps);
CV_Error(Error::StsNotImplemented, "Implementation has been removed due original code license issues");
}
推荐阅读
- xml - 根据来自不同节点的 Xpath 条件过滤 XML
- c++ - 替换 Dll 中的类以进行单元测试
- javascript - 使用 Tabulator 设置最大表格高度
- python - 如何绘制正则表达式的输出?
- kotlin - 成员变量无法正确转换为 lambda 表达式
- javascript - Linkedin 链接预览中的消息显示网站错误
- blockchain - 您如何修改 Parity Substrate 中“哈希”中的字节?
- wpf - 将 d:DataContext 设置为另一个程序集的内部类
- c# - 在 Azure 函数中使用参数调用存储过程会出错
- android - 获取 recyclerview 上的项目计数不起作用