c++ - OpenCV 2.4.5 & Boost for Passing VideoCapture -
issue: want pass cv::videocapture objects different thread. want able dynamically handle how many cameras can have.
proposed solution: insert vector , pass argument thread:
inserting mechanism:
std::vector< boost::shared_ptr<cv::videocapture> > camvect; for(int i=0;i<6;i++){ boost::shared_ptr<cv::videocapture> cvinputobj(new cv::videocapture(i)); if((*cvinputobj.get()).isopened()){ camvect.push_back(cvinputobj); validcams++; } } retrieval mechanism:create local vector , assign passed in data vector such:
cvision::cvision(std::vector< boost::shared_ptr<cv::videocapture> > camvect) { cameras=camvect; } following go ahead , following pull out image:
note, typedefs below:
typedef std::vector< boost::shared_ptr<cv::videocapture> > cameracontainer; typedef cameracontainer::iterator camiterator; using this, create iterator , try retrieve images. gathered class definition '>>' operator grab() followed retrieve()
void cvision::grabimage(int camnumber){ int index=0; for(camiterator it=cameras.begin();it!=cameras.end();++it) { if(index==camnumber) { if((*it)->grab()) { cout<<"successfully grabbed!"<<endl; if((*it)->retrieve(imcur[camnumber],0)) cout<<"successfully retrieved!"<<endl; else cout<<"error retrieving"<<endl; } } else index++; } } issue: seems calling grab() method, fails on retrieve? (this guess):
libv4l2: error dequeuing buf: invalid argument vidioc_dqbuf: invalid argument grabbed! any advice immensely helpful!
i figured out how circumvent this. i.e. defining following global main():
std::vector< boost::shared_ptr<cv::videocapture> > camvect; following called same method thread , worked expected.
still not sure why happened though.
Comments
Post a Comment