Skip to content

Instantly share code, notes, and snippets.

@blackball
Last active August 29, 2015 14:04
Show Gist options
  • Save blackball/feae93ec6f802792d82b to your computer and use it in GitHub Desktop.
Save blackball/feae93ec6f802792d82b to your computer and use it in GitHub Desktop.
A simple warpper for Capture in C++.
/**
* A simple warpper for Capture in C++.
*
* @blackball
*/
#ifndef OPENCV_CAP_H
#define OPENCV_CAP_H
#include <opencv/cv.h>
#include <opencv/highgui.h>
#include <stdio.h>
class Capture {
public:
Capture() : m_cap(0){}
~Capture() {
_release();
}
void open(int device) {
_release();
m_cap = cvCaptureFromCAM(device);
if (!m_cap) {
fprintf(stderr, "Can not open device: %d!\n", device);
exit(0);
}
}
void open(const char *vname) {
_release();
m_cap = cvCaptureFromFile(vname);
if (!m_cap) {
fprintf(stderr, "Can not open video: %s!\n", vname);
exit(0);
}
}
int grab() {
return cvGrabFrame(m_cap);
}
IplImage * retrieve() {
return cvRetrieveFrame(m_cap);
}
IplImage * queryFrame() {
return cvQueryFrame(m_cap);
}
private:
void _release() {
if (m_cap)
cvReleaseCapture( &m_cap );
}
private:
CvCapture *m_cap;
};
#endif
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment