Commit 9817252b authored by Vladislav Vinogradov's avatar Vladislav Vinogradov

added addTextOpenGl function

parent 2a4fb155
......@@ -151,6 +151,11 @@ CV_EXPORTS void pointCloudShow(const string& winname, const gpu::GlCamera& camer
CV_EXPORTS void pointCloudShow(const string& winname, const gpu::GlCamera& camera, InputArray points,
InputArray colors = noArray());
CV_EXPORTS void addTextOpenGl(const string& winname, const string& text, Point org, Scalar color = Scalar::all(255),
const string& fontName = "Courier New", int fontHeight = 12,
int fontWeight = CV_FONT_NORMAL, int fontStyle = CV_STYLE_NORMAL);
CV_EXPORTS void clearTextOpenGl(const string& winname);
//Only for Qt
CV_EXPORTS CvFont fontQt(const string& nameFont, int pointSize=-1,
......
......@@ -63,7 +63,8 @@ enum { CV_FONT_LIGHT = 25,//QFont::Light,
enum { CV_STYLE_NORMAL = 0,//QFont::StyleNormal,
CV_STYLE_ITALIC = 1,//QFont::StyleItalic,
CV_STYLE_OBLIQUE = 2 //QFont::StyleOblique
CV_STYLE_OBLIQUE = 2,//QFont::StyleOblique
CV_STYLE_UNDERLINE = 4
};
/* ---------*/
......@@ -257,6 +258,12 @@ CVAPI(void) cvCreateOpenGLCallback( const char* window_name, CvOpenGLCallback ca
CVAPI(void) cvSetOpenGlContext(const char* window_name);
CVAPI(void) cvUpdateWindow(const char* window_name);
CVAPI(void) cvAddTextOpenGl(const char* winname, const char* text, CvPoint org, CvScalar color CV_DEFAULT(cvScalar(255.0, 255.0, 255.0, 255.0)),
const char* fontName CV_DEFAULT("Courier New"), int fontHeight CV_DEFAULT(12),
int fontWeight CV_DEFAULT(CV_FONT_NORMAL), int fontStyle CV_DEFAULT(CV_STYLE_NORMAL));
CVAPI(void) cvClearTextOpenGl(const char* winname);
/****************************************************************************************\
* Working with Video Files and Cameras *
\****************************************************************************************/
......
......@@ -597,6 +597,35 @@ void cv::pointCloudShow(const string& winname, const gpu::GlCamera& camera, Inpu
#endif
}
// OpenGL text
void cv::addTextOpenGl(const string& winname, const string& text, Point org, Scalar color, const string& fontName, int fontHeight, int fontWeight, int fontStyle)
{
cvAddTextOpenGl(winname.c_str(), text.c_str(), org, color, fontName.c_str(), fontHeight, fontWeight, fontStyle);
}
void cv::clearTextOpenGl(const string& winname)
{
cvClearTextOpenGl(winname.c_str());
}
#if (!defined WIN32 && !defined _WIN32) || defined HAVE_QT
CV_IMPL void cvAddTextOpenGl(const char*, const char*, CvPoint, CvScalar, const char*, int, int, int)
{
CV_Error(CV_OpenGlNotSupported, "This function works only under WIN32");
}
CV_IMPL void cvClearTextOpenGl(const char*)
{
CV_Error(CV_OpenGlNotSupported, "This function works only under WIN32");
}
#endif // (!defined WIN32 && !defined _WIN32) || defined HAVE_QT
// Without OpenGL
#ifndef HAVE_OPENGL
#ifndef HAVE_QT
......@@ -616,6 +645,16 @@ CV_IMPL void cvUpdateWindow(const char*)
CV_Error(CV_OpenGlNotSupported, "The library is compiled without OpenGL support");
}
CV_IMPL void cvAddTextOpenGl(const char*, const char*, CvPoint, CvScalar, const char*, int, int, int)
{
CV_Error(CV_OpenGlNotSupported, "The library is compiled without OpenGL support");
}
CV_IMPL void cvClearTextOpenGl(const char*)
{
CV_Error(CV_OpenGlNotSupported, "The library is compiled without OpenGL support");
}
void icvSetOpenGlCleanCallback(const char*, CvOpenGlCleanCallback, void*)
{
CV_Error(CV_OpenGlNotSupported, "The library is compiled without OpenGL support");
......
This diff is collapsed.
#include <cstring>
#include <cmath>
#include <iostream>
#include <sstream>
#include "opencv2/core/core.hpp"
#include "opencv2/core/gpumat.hpp"
#include "opencv2/highgui/highgui.hpp"
#include "opencv2/imgproc/imgproc.hpp"
#include "opencv2/calib3d/calib3d.hpp"
#include "opencv2/contrib/contrib.hpp"
using namespace std;
using namespace cv;
......@@ -187,13 +189,15 @@ int main(int argc, const char* argv[])
reprojectImageTo3D(disp, points, Q);
namedWindow("OpenGL Sample", WINDOW_OPENGL);
const string windowName = "OpenGL Sample";
namedWindow(windowName, WINDOW_OPENGL);
int fov = 0;
createTrackbar("Fov", "OpenGL Sample", &fov, 100);
createTrackbar("Fov", windowName, &fov, 100);
int mouse[2] = {0, 0};
setMouseCallback("OpenGL Sample", mouseCallback, mouse);
setMouseCallback(windowName, mouseCallback, mouse);
GlArrays pointCloud;
......@@ -211,8 +215,14 @@ int main(int argc, const char* argv[])
const Point3d leftVec(-1.0, 0.0, 0.0);
Point3d pos;
TickMeter tm;
const int step = 20;
int frame = 0;
while (true)
{
tm.start();
int key = waitKey(1);
if (key >= 0)
key = key & 0xff;
......@@ -220,7 +230,7 @@ int main(int argc, const char* argv[])
if (key == 27)
break;
double aspect = getWindowProperty("OpenGL Sample", WND_PROP_ASPECT_RATIO);
double aspect = getWindowProperty(windowName, WND_PROP_ASPECT_RATIO);
const double posStep = 0.1;
......@@ -256,7 +266,21 @@ int main(int argc, const char* argv[])
camera.setCameraPos(pos, yaw, pitch, 0.0);
pointCloudShow("OpenGL Sample", camera, pointCloud);
pointCloudShow(windowName, camera, pointCloud);
tm.stop();
if (frame++ >= step)
{
ostringstream fps;
fps << "FPS: " << step / tm.getTimeSec();
clearTextOpenGl(windowName);
addTextOpenGl(windowName, fps.str(), Point(0, 0), Scalar::all(255), "Courier New", 16);
frame = 0;
tm.reset();
}
}
return 0;
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment