c++ - How to retrieve a cv::Mat object from an object of this API class? -
i stuck trying cv::mat
object class (third party code) main function.
i have class:
frameobserver.h
class frameobserver : virtual public iframeobserver { public: frameobserver( cameraptr pcamera, frameinfos eframeinfos, colorprocessing ecolorprocessing ); cv::mat m_convertimage; // our callback routine executed on every received frame virtual void framereceivedleft( const frameptr pframe ); virtual void framereceivedright(const frameptr pframe); void processcvleft(const frameptr pframe); void processcvright(const frameptr pframe); static cv::mat frameobserver::getcurrentframe() { return currentframe; } private: static cv::mat currentframe; #ifdef win32 double m_dfrequency; #endif //win32 }; }}} // namespace avt::vmbapi::examples
frameobserver.cpp
void frameobserver::processcvleft(const frameptr pframe) { vmbuchar_t *pbuffer; vmbuint32_t framewidth; vmbuint32_t frameheight; pframe->getwidth(framewidth); pframe->getheight(frameheight); pframe->getimage(pbuffer); showframeinfos(pframe); iplimage *img1 = cvcreateimageheader(cvsize( framewidth, frameheight), ipl_depth_8u, 1); cvsetdata(img1, pbuffer, img1->widthstep); cv::mat copyimagel = cv::cvarrtomat(img1); currentframe = copyimagel; //copies currentframe here }
then have main.cpp:
cv::mat mainframe; int main( int argc, char* argv[] ) { //i need pull currentframe mat stream frame mat above. }
what best way this? have tried:
frameobserver fo; cv::mat test = fo.currentframe;
but gives me following error:
no default constructor exists class "frameobserver"
thank you.
as far c++ goes, mistake class frameobserver
has no default constructor (i.e. constructor can called without arguments). it's not defined explicitly, nor generated, since constructor has been defined (see here). thus, can't write
frameobserver fo;
since invokes default constructor frameobserver::frameobserver()
(see above) not present. thus, should create frameobserver
object using existing constructor arguments frameobserver::frameobserver( cameraptr pcamera, frameinfos eframeinfos, colorprocessing ecolorprocessing );
now on actual problem. since class part of supplied api, shouldn't try change it, rather learn use correctly. name of it, appears observer. thus, need create instance of (a single one, @ that), , carefully read docs on how it's supposed supply frame data matrix. don't know how works, common sense, since it's "observer", should automatically provide notifications incoming frames. again, have close @ documentation.
important edit:
here is, @ header:
// our callback routine executed on every received frame virtual void framereceivedleft( const frameptr pframe ); virtual void framereceivedright(const frameptr pframe);
by looks of it, supposed subclass frameobserver
, reimplement 2 above functions. means code process or extract frames must reside inside routines in subclass you're going create.
anyway, while details may vary, concept stays: observer going call methods on own. can wait call methods , react accordingly. more precisely, register class object or function within observer object, , let observer call methods automatically. (it said "subscribe notifications" provided observer).
Comments
Post a Comment