Opencv4nodejs: Missing LineSegmentDetector methods?

Created on 24 May 2018  路  5Comments  路  Source: justadudewhohacks/opencv4nodejs

Hello,

First thank you for your amazing work on this adaptation of opencv.

I am currently looking for module LineSegmentDetector (LSD), but I can't find it in the documentation as mentioned here:
[https://docs.opencv.org/3.4/db/d73/classcv_1_1LineSegmentDetector.html]

Any clue about how to get it? Otherwise, is it planned to be implemented?

Thank you!

good first issue help wanted

Most helpful comment

Hi,

Bindings to the LineSegmentDetector are not implemented currently. For the time being I am not planning to do any additions to the package myself, but I am always happy to take PRs.

All 5 comments

Hi,

Bindings to the LineSegmentDetector are not implemented currently. For the time being I am not planning to do any additions to the package myself, but I am always happy to take PRs.

Hey,

I would also be happy to have this LineSegmentDetector feature, that would be great if this feature could be implemented with OpenCV4nodejs !

Need Help !! I am trying to make an integration of cv::LineSegmentDetector to opencv4nodejs which is an node addon of opencv. I have successfully complied an opencv4nodejs module which get loaded by require. Initially was facing problems of opencv_core.dll , and opencv_imgproc.dll while loading the opencv4nodejs.node module to js. But cv::createLineSegmentDetector() crashes catch( std::exception &e) does not work but catch(...) exception catches it. But its still does not work.

Here is the code.

`#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;
};`

#include "LineSegmentDetector.h"
#include "Mat.h"
#include "Vec4.h"

Nan::Persistent<v8::FunctionTemplate> LineSegmentDetector::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);
}



md5-dd9758f33419dac55c08571a6c0f8ed7



    Nan::Set(modules, FF::newString("lineSegmentDetector"), Nan::New(true));
    LineSegmentDetector::Init(target);

As I understood there is no problem with my code the implementation is not present in version 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");
}

void LineSegmentDetectorImpl::detect(InputArray _image, OutputArray _lines,
OutputArray _width, OutputArray _prec, OutputArray _nfa)
{
CV_INSTRUMENT_REGION();

CV_UNUSED(_image); CV_UNUSED(_lines);
CV_UNUSED(_width); CV_UNUSED(_prec); CV_UNUSED(_nfa);
CV_Error(Error::StsNotImplemented, "Implementation has been removed due original code license issues");

}`

Here check the link. https://github.com/opencv/opencv/blob/master/modules/imgproc/src/lsd.cpp

@justadudewhohacks Can you tell me any work around ?

Was this page helpful?
0 / 5 - 0 ratings

Related issues

pabx06 picture pabx06  路  4Comments

G33kLabs picture G33kLabs  路  3Comments

SatoshiKawabata picture SatoshiKawabata  路  5Comments

karlbernard2 picture karlbernard2  路  4Comments

sinitsyn-alex picture sinitsyn-alex  路  4Comments