Ask Your Question

How to declare and initial BackgroundSubtractorMOG2 in opencv3.

asked 2015-02-14 04:42:37 -0600

wuling gravatar image

Hi all, i try many different methods to declare and intial backgoundsubtractormog2 classs. But i always fails, i list all i declare. Someone can tell me how to declare or has any idea or any referance can help me? I appreciate your help.

Ptr<BackgroundSubtractor> MOG2model=createBackgroundSubtractorMOG2().dynamicCast<BackgroundSubtractor>();//Fail
Ptr<BackgroundSubtractorMOG2> MOG2model = createBackgroundSubtractorMOG2().dynamicCast<BackgroundSubtractorMOG2>();//Fail
Ptr<BackgroundSubtractorMOG2> MOG2model = createBackgroundSubtractorMOG2();//Fail
cv::BackgroundSubtractorMOG2 MOG2model=BackgroundSubtractorMOG2::create<BackgroundSubtractorMOG2>("Background");//Fail

by the way, thanks very much!

edit retag flag offensive close merge delete



Ptr<BackgroundSubtractor> MOG2model=createBackgroundSubtractorMOG2(); should just work, same as Ptr<BackgroundSubtractorMOG2> MOG2model=createBackgroundSubtractorMOG2();.

what's the error in your case ? why the dynamic_cast() ?

berak gravatar imageberak ( 2015-02-14 04:46:49 -0600 )edit

Hi,berak Ptr<BackgroundSubtractor> MOG2model=createBackgroundSubtractorMOG2(); // I get C2143 Syntax Error ,lost ";" (before <) and error C4430 ,error C2238Ptr<BackgroundSubtractorMOG2> MOG2model=createBackgroundSubtractorMOG2();// the same I find example "bgfg_segm.cpp" so, i try createBackgroundSubtractorMOG2().dynamicCast<BackgroundSubtractor>();

wuling gravatar imagewuling ( 2015-02-14 05:19:15 -0600 )edit

are you using CLI/managed c++ ?

berak gravatar imageberak ( 2015-02-14 05:26:07 -0600 )edit

No, pure C++,enviroment does not support CLI. But I think I use different version complier. I check again.

wuling gravatar imagewuling ( 2015-02-14 05:30:19 -0600 )edit

can it be, there's a missing ;before your statements ? (like, one or more lines up ?) , or something like unmatched {} () or such , again, in the lines above those statements ?

berak gravatar imageberak ( 2015-02-14 05:33:48 -0600 )edit

I mark this statement ,then it's ok. I change platform tool to VS2012(opencv lib is bulided VS2012) is the scame. But now I write code using VS2013. I think i use different version. I bulid VS2013 opencv lib now:)

wuling gravatar imagewuling ( 2015-02-14 05:46:36 -0600 )edit

hmm, that's still a compiler error. the libs won't change anything, i'm afraid.

berak gravatar imageberak ( 2015-02-14 05:55:53 -0600 )edit

1 answer

Sort by ยป oldest newest most voted

answered 2015-02-15 02:48:19 -0600

wuling gravatar image

Thanks, I use wrong version complier.Now it's ok Thanks very much

edit flag offensive delete link more

Question Tools

1 follower


Asked: 2015-02-14 04:42:37 -0600

Seen: 1,092 times

Last updated: Feb 14 '15