Ask Your Question
0

dynamicCast<Boost> returns Segmentation fault

asked 2018-04-17 09:39:02 -0600

fragolka gravatar image

Hi,

I'm using OpenCV 3.3 running on Linux and bumped into following error:

Ptr create_model()
{
   Ptr model = Boost::create();
   model->setBoostType(Boost::DISCRETE);
}

int main()
{
   Ptr model = create_model().dynamicCast<Boost>()
}

I've used dynamicCast successfully with other classes (SVM, trees, logistic regression), however, casting to boost returns Segmentation fault. Backtracking is not very helpful either:

#0 0x0000ffffb6c625d4 in __dynamic_cast () from /usr/lib/libstdc++.so.6
#1 0x00000000004066e8 in cv::Ptr<cv::ml::Boost> cv::Ptr<cv::ml::StatModel>::dynamicCast<cv::ml::Boost>() const ()

Is it a bug? Or bad compilation?

Many thanks!

edit retag flag offensive close merge delete

Comments

can you try again with editing, and show your real code ? there seem to things missing (template arguments) !

also please explain why you need a dynamicCast here at all.

berak gravatar imageberak ( 2018-04-17 09:46:41 -0600 )edit

again, above code does not compile, and imho, if you need any cast here, you're doing something (horribly) wrong.

berak gravatar imageberak ( 2018-04-17 10:22:12 -0600 )edit

1 answer

Sort by ยป oldest newest most voted
1

answered 2018-04-18 02:57:57 -0600

fragolka gravatar image

updated 2018-04-18 02:58:49 -0600

Sorry, <type> keyword got lost when preformatted. I found that the error was very very stupid - I forgot 'return model;' at the end of create_model() function. Very stupid typo :/ The code should have looked like this:

Ptr<StatModel> create_model()
{
   Ptr<Boost> model = Boost::create();
   model->setBoostType(Boost::DISCRETE);
}

int main()
{
   Ptr<Boost> model = create_model().dynamicCast<Boost>();
   return 0;
}

Anyway, thanks a lot for your responses!

edit flag offensive delete link more

Comments

you might as well close your issue here

berak gravatar imageberak ( 2018-04-18 03:37:06 -0600 )edit

Question Tools

1 follower

Stats

Asked: 2018-04-17 09:39:02 -0600

Seen: 311 times

Last updated: Apr 17 '18