8 #define GLUT_DISABLE_ATEXIT_HACK // Needed to compile with Mingw? 16 unsigned char hidingtex[64*64*4];
19 glMultMatrixd(gl_mat);
21 glPushAttrib(GL_ALL_ATTRIB_BITS);
22 glEnable(GL_TEXTURE_2D);
24 glBindTexture(GL_TEXTURE_2D, tex);
25 glTexEnvf(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_REPLACE);
26 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
27 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
28 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP);
29 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP);
30 glTexImage2D(GL_TEXTURE_2D,0,GL_RGBA,64,64,0,GL_RGBA,GL_UNSIGNED_BYTE,hidingtex);
31 glDisable(GL_CULL_FACE);
32 glDisable(GL_LIGHTING);
33 glDisable(GL_DEPTH_TEST);
34 glEnable(GL_ALPHA_TEST);
36 glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
38 glTexCoord2d(0.0,0.0);
40 glTexCoord2d(0.0,1.0);
42 glTexCoord2d(1.0,1.0);
44 glTexCoord2d(1.0,0.0);
54 static bool init=
true;
58 static IplImage *hide_texture;
60 bool flip_image = (image->origin?
true:
false);
63 image->origin = !image->origin;
66 static IplImage* bg_image = 0;
67 if(!bg_image) bg_image = cvCreateImage(cvSize(512, 512), 8, 3);
68 if(image->nChannels == 3)
71 cvResize(image, bg_image);
81 cam.
SetRes(image->width, image->height);
82 cout<<
" [Fail]"<<endl;
93 for (
size_t i=0; i<marker_detector.
markers->size(); i++) {
97 for (
size_t i=0; i<marker_detector.
markers->size(); i++) {
109 for (
int ii=0; ii<64*64; ii++) {
110 d[i].
hidingtex[ii*4+0] = hide_texture->imageData[ii*4+2];
111 d[i].
hidingtex[ii*4+1] = hide_texture->imageData[ii*4+1];
112 d[i].
hidingtex[ii*4+2] = hide_texture->imageData[ii*4+0];
113 d[i].
hidingtex[ii*4+3] = hide_texture->imageData[ii*4+3];
118 image->origin = !image->origin;
122 int main(
int argc,
char *argv[])
127 filename = filename.substr(filename.find_last_of(
'\\') + 1);
128 std::cout <<
"SampleMarkerHide" << std::endl;
129 std::cout <<
"================" << std::endl;
130 std::cout << std::endl;
131 std::cout <<
"Description:" << std::endl;
132 std::cout <<
" This is an example of how to detect 'MarkerData' markers, similarly" << std::endl;
133 std::cout <<
" to 'SampleMarkerDetector', and hide them using the 'BuildHideTexture'" << std::endl;
134 std::cout <<
" and 'DrawTexture' classes." << std::endl;
135 std::cout << std::endl;
136 std::cout <<
"Usage:" << std::endl;
137 std::cout <<
" " << filename <<
" [device]" << std::endl;
138 std::cout << std::endl;
139 std::cout <<
" device integer selecting device from enumeration list (default 0)" << std::endl;
140 std::cout <<
" highgui capture devices are prefered" << std::endl;
141 std::cout << std::endl;
142 std::cout <<
"Keyboard Shortcuts:" << std::endl;
143 std::cout <<
" q: quit" << std::endl;
144 std::cout << std::endl;
152 if (plugins.size() < 1) {
153 std::cout <<
"Could not find any capture plugins." << std::endl;
158 std::cout <<
"Available Plugins: ";
160 std::cout << std::endl;
164 if (devices.size() < 1) {
165 std::cout <<
"Could not find any capture devices." << std::endl;
172 selectedDevice = atoi(argv[1]);
174 if (selectedDevice >= (
int)devices.size()) {
179 std::cout <<
"Enumerated Capture Devices:" << std::endl;
181 std::cout << std::endl;
185 std::string uniqueName = devices[selectedDevice].uniqueName();
190 std::stringstream settingsFilename;
191 settingsFilename <<
"camera_settings_" << uniqueName <<
".xml";
198 std::cout <<
"Loading settings: " << settingsFilename.str() << std::endl;
201 std::stringstream title;
207 std::cout <<
"Saving settings: " << settingsFilename.str() << std::endl;
216 std::cout <<
"Could not initialize the selected capture backend." << std::endl;
221 catch (
const std::exception &e) {
222 std::cout <<
"Exception: " << e.what() << endl;
225 std::cout <<
"Exception: unknown" << std::endl;
void GetOpenglProjectionMatrix(double proj_matrix[16], const int width, const int height, const float far_clip=1000.0f, const float near_clip=0.1f)
Get OpenGL matrix Generates the OpenGL projection matrix based on OpenCV intrinsic camera matrix K...
static CvTestbed & Instance()
The one and only instance of CvTestbed is accessed using CvTestbed::Instance()
Capture * createCapture(const CaptureDevice captureDevice)
Create Capture class. Transfers onwership to the caller.
virtual void stop()=0
Stops the camera capture.
void GetMatrixGL(double gl[16], bool mirror=true)
Get the transformation matrix representation of the Pose using OpenGL's transposed format...
virtual bool start()=0
Starts the camera capture.
CaptureDevice captureDevice()
The camera information associated to this capture object.
void SetVideoCallback(void(*_videocallback)(IplImage *image))
Set the videocallback function that will be called for every frame.
static CaptureFactory * instance()
The singleton instance of CaptureFactory.
IplImage * CreateImage(const char *title, CvSize size, int depth, int channels)
Creates an image with given size, depth and channels and stores it with a given 'title' (see CvTestbe...
This file implements a generic marker detector.
void SetRes(int _x_res, int _y_res)
If we have no calibration file we can still adjust the default calibration to current resolution...
std::vector< CaptureDevice > CaptureDeviceVector
Vector of CaptureDevices.
Simple Camera class for calculating distortions, orientation or projections with pre-calibrated camer...
std::string captureType() const
The type of capture backend.
bool StartVideo(Capture *_cap, const char *_wintitle=0)
Start video input from given capture device.
bool SetCalib(const char *calibfile, int _x_res, int _y_res, FILE_FORMAT format=FILE_FORMAT_DEFAULT)
Set the calibration file and the current resolution for which the calibration is adjusted to...
std::vector< M, Eigen::aligned_allocator< M > > * markers
std::vector< std::string > CapturePluginVector
Vector of strings.
void outputEnumeratedPlugins(CaptureFactory::CapturePluginVector &plugins)
MarkerDetector for detecting markers of type M
void SetGlProjectionMatrix(double p[16])
CaptureDeviceVector enumerateDevices(const std::string &captureType="")
Enumerate capture devices currently available.
void Start(int argc, char **argv, int w, int h, float r=300.0)
Pose representation derived from the Rotation class
void DrawableAdd(Drawable *item)
CapturePluginVector enumeratePlugins()
Enumerate capture plugins currently available.
MarkerDetector< MarkerData > marker_detector
void outputEnumeratedDevices(CaptureFactory::CaptureDeviceVector &devices, int selectedDevice)
std::stringstream calibrationFilename
void videocallback(IplImage *image)
void SetVideo(const IplImage *_image)
ALVAR_EXPORT Point< CvPoint2D64f > PointDouble
The default double point type.
unsigned char hidingtex[64 *64 *4]
void ALVAR_EXPORT BuildHideTexture(IplImage *image, IplImage *hide_texture, Camera *cam, double gl_modelview[16], PointDouble topleft, PointDouble botright)
This function is used to construct a texture image which is needed to hide a marker from the original...
Capture interface that plugins must implement.
virtual bool loadSettings(std::string filename)
Load camera settings from a file.
int defaultDevice(CaptureFactory::CaptureDeviceVector &devices)
virtual void setResolution(const unsigned long xResolution, const unsigned long yResolution)
Set the resolution.
int main(int argc, char *argv[])
virtual bool saveSettings(std::string filename)
Save camera settings to a file.