Commit bd4239be authored by Vladislav Vinogradov's avatar Vladislav Vinogradov

moved OpenGL wrappers to separate header

added GlBuffer, GlTexture and GpuMat support to InputArray
replaced addTextOpenGl function by render + GlFont
parent 59ea0d8e
...@@ -90,6 +90,11 @@ class Mat; ...@@ -90,6 +90,11 @@ class Mat;
class SparseMat; class SparseMat;
typedef Mat MatND; typedef Mat MatND;
class GlBuffer;
class GlTexture;
class GlArrays;
class GlCamera;
namespace gpu { namespace gpu {
class GpuMat; class GpuMat;
} }
...@@ -1273,10 +1278,19 @@ protected: ...@@ -1273,10 +1278,19 @@ protected:
class CV_EXPORTS _InputArray class CV_EXPORTS _InputArray
{ {
public: public:
enum { KIND_SHIFT=16, NONE=0<<KIND_SHIFT, MAT=1<<KIND_SHIFT, enum {
MATX=2<<KIND_SHIFT, STD_VECTOR=3<<KIND_SHIFT, KIND_SHIFT = 16,
STD_VECTOR_VECTOR=4<<KIND_SHIFT, NONE = 0 << KIND_SHIFT,
STD_VECTOR_MAT=5<<KIND_SHIFT, EXPR=6<<KIND_SHIFT }; MAT = 1 << KIND_SHIFT,
MATX = 2 << KIND_SHIFT,
STD_VECTOR = 3 << KIND_SHIFT,
STD_VECTOR_VECTOR = 4 << KIND_SHIFT,
STD_VECTOR_MAT = 5 << KIND_SHIFT,
EXPR = 6 << KIND_SHIFT,
OPENGL_BUFFER = 7 << KIND_SHIFT,
OPENGL_TEXTURE = 8 << KIND_SHIFT,
GPU_MAT = 9 << KIND_SHIFT
};
_InputArray(); _InputArray();
_InputArray(const Mat& m); _InputArray(const Mat& m);
_InputArray(const MatExpr& expr); _InputArray(const MatExpr& expr);
...@@ -1287,8 +1301,16 @@ public: ...@@ -1287,8 +1301,16 @@ public:
template<typename _Tp, int m, int n> _InputArray(const Matx<_Tp, m, n>& matx); template<typename _Tp, int m, int n> _InputArray(const Matx<_Tp, m, n>& matx);
_InputArray(const Scalar& s); _InputArray(const Scalar& s);
_InputArray(const double& val); _InputArray(const double& val);
_InputArray(const GlBuffer& buf);
_InputArray(const GlTexture& tex);
_InputArray(const gpu::GpuMat& d_mat);
virtual Mat getMat(int i=-1) const; virtual Mat getMat(int i=-1) const;
virtual void getMatVector(vector<Mat>& mv) const; virtual void getMatVector(vector<Mat>& mv) const;
virtual GlBuffer getGlBuffer() const;
virtual GlTexture getGlTexture() const;
virtual gpu::GpuMat getGpuMat() const;
virtual int kind() const; virtual int kind() const;
virtual Size size(int i=-1) const; virtual Size size(int i=-1) const;
virtual size_t total(int i=-1) const; virtual size_t total(int i=-1) const;
......
...@@ -50,9 +50,6 @@ ...@@ -50,9 +50,6 @@
namespace cv { namespace gpu namespace cv { namespace gpu
{ {
////////////////////////////////////////////////////////////////////////
// GpuMat
//! Smart pointer for GPU memory with reference counting. Its interface is mostly similar with cv::Mat. //! Smart pointer for GPU memory with reference counting. Its interface is mostly similar with cv::Mat.
class CV_EXPORTS GpuMat class CV_EXPORTS GpuMat
{ {
...@@ -217,286 +214,10 @@ namespace cv { namespace gpu ...@@ -217,286 +214,10 @@ namespace cv { namespace gpu
CV_EXPORTS void ensureSizeIsEnough(int rows, int cols, int type, GpuMat& m); CV_EXPORTS void ensureSizeIsEnough(int rows, int cols, int type, GpuMat& m);
CV_EXPORTS void ensureSizeIsEnough(Size size, int type, GpuMat& m); CV_EXPORTS void ensureSizeIsEnough(Size size, int type, GpuMat& m);
////////////////////////////////////////////////////////////////////////
// OpenGL
//! set a CUDA device to use OpenGL interoperability
CV_EXPORTS void setGlDevice(int device = 0);
//! Smart pointer for OpenGL buffer memory with reference counting.
class CV_EXPORTS GlBuffer
{
public:
enum Usage
{
ARRAY_BUFFER = 0x8892, // buffer will use for OpenGL arrays (vertices, colors, normals, etc)
TEXTURE_BUFFER = 0x88EC // buffer will ise for OpenGL textures
};
//! create empty buffer
explicit GlBuffer(Usage usage);
//! create buffer
GlBuffer(int rows, int cols, int type, Usage usage);
GlBuffer(Size size, int type, Usage usage);
//! copy from host/device memory
GlBuffer(InputArray mat, Usage usage);
GlBuffer(const GpuMat& d_mat, Usage usage);
GlBuffer(const GlBuffer& other);
~GlBuffer();
GlBuffer& operator =(const GlBuffer& other);
void create(int rows, int cols, int type, Usage usage);
inline void create(Size size, int type, Usage usage) { create(size.height, size.width, type, usage); }
inline void create(int rows, int cols, int type) { create(rows, cols, type, usage()); }
inline void create(Size size, int type) { create(size.height, size.width, type, usage()); }
void release();
//! copy from host/device memory
void copyFrom(InputArray mat);
void copyFrom(const GpuMat& d_mat);
void bind() const;
void unbind() const;
//! map to host memory
Mat mapHost();
void unmapHost();
//! map to device memory
GpuMat mapDevice();
void unmapDevice();
int rows;
int cols;
inline Size size() const { return Size(cols, rows); }
inline bool empty() const { return rows == 0 || cols == 0; }
inline int type() const { return type_; }
inline int depth() const { return CV_MAT_DEPTH(type_); }
inline int channels() const { return CV_MAT_CN(type_); }
inline int elemSize() const { return CV_ELEM_SIZE(type_); }
inline int elemSize1() const { return CV_ELEM_SIZE1(type_); }
inline Usage usage() const { return usage_; }
private:
int type_;
Usage usage_;
class Impl;
Ptr<Impl> impl_;
};
//! Smart pointer for OpenGL 2d texture memory with reference counting.
class CV_EXPORTS GlTexture
{
public:
//! create empty texture
GlTexture();
//! create texture
GlTexture(int rows, int cols, int type);
GlTexture(Size size, int type);
//! copy from host/device memory
explicit GlTexture(InputArray mat, bool bgra = true);
explicit GlTexture(const GlBuffer& buf, bool bgra = true);
GlTexture(const GlTexture& other);
~GlTexture();
GlTexture& operator =(const GlTexture& other);
void create(int rows, int cols, int type);
inline void create(Size size, int type) { create(size.height, size.width, type); }
void release();
//! copy from host/device memory
void copyFrom(InputArray mat, bool bgra = true);
void copyFrom(const GlBuffer& buf, bool bgra = true);
void bind() const;
void unbind() const;
int rows;
int cols;
inline Size size() const { return Size(cols, rows); }
inline bool empty() const { return rows == 0 || cols == 0; }
inline int type() const { return type_; }
inline int depth() const { return CV_MAT_DEPTH(type_); }
inline int channels() const { return CV_MAT_CN(type_); }
inline int elemSize() const { return CV_ELEM_SIZE(type_); }
inline int elemSize1() const { return CV_ELEM_SIZE1(type_); }
private:
int type_;
class Impl;
Ptr<Impl> impl_;
};
//! OpenGL Arrays
class CV_EXPORTS GlArrays
{
public:
inline GlArrays()
: vertex_(GlBuffer::ARRAY_BUFFER), color_(GlBuffer::ARRAY_BUFFER), bgra_(true), normal_(GlBuffer::ARRAY_BUFFER), texCoord_(GlBuffer::ARRAY_BUFFER)
{
}
void setVertexArray(const GlBuffer& vertex);
void setVertexArray(const GpuMat& vertex);
void setVertexArray(InputArray vertex);
inline void resetVertexArray() { vertex_.release(); }
void setColorArray(const GlBuffer& color, bool bgra = true);
void setColorArray(const GpuMat& color, bool bgra = true);
void setColorArray(InputArray color, bool bgra = true);
inline void resetColorArray() { color_.release(); }
void setNormalArray(const GlBuffer& normal);
void setNormalArray(const GpuMat& normal);
void setNormalArray(InputArray normal);
inline void resetNormalArray() { normal_.release(); }
void setTexCoordArray(const GlBuffer& texCoord);
void setTexCoordArray(const GpuMat& texCoord);
void setTexCoordArray(InputArray texCoord);
inline void resetTexCoordArray() { texCoord_.release(); }
void bind() const;
void unbind() const;
inline int rows() const { return vertex_.rows; }
inline int cols() const { return vertex_.cols; }
inline Size size() const { return vertex_.size(); }
inline bool empty() const { return vertex_.empty(); }
private:
GlBuffer vertex_;
GlBuffer color_;
bool bgra_;
GlBuffer normal_;
GlBuffer texCoord_;
};
//! render functions
//! render texture rectangle in window
CV_EXPORTS void render(const GlTexture& tex,
Rect_<double> wndRect = Rect_<double>(0.0, 0.0, 1.0, 1.0),
Rect_<double> texRect = Rect_<double>(0.0, 0.0, 1.0, 1.0));
//! render mode
namespace RenderMode {
enum {
POINTS = 0x0000,
LINES = 0x0001,
LINE_LOOP = 0x0002,
LINE_STRIP = 0x0003,
TRIANGLES = 0x0004,
TRIANGLE_STRIP = 0x0005,
TRIANGLE_FAN = 0x0006,
QUADS = 0x0007,
QUAD_STRIP = 0x0008,
POLYGON = 0x0009
};
}
//! render OpenGL arrays
CV_EXPORTS void render(const GlArrays& arr, int mode = RenderMode::POINTS);
//! OpenGL camera
class CV_EXPORTS GlCamera
{
public:
GlCamera();
void lookAt(Point3d eye, Point3d center, Point3d up);
void setCameraPos(Point3d pos, double yaw, double pitch, double roll);
void setScale(Point3d scale);
void setProjectionMatrix(const Mat& projectionMatrix, bool transpose = true);
void setPerspectiveProjection(double fov, double aspect, double zNear, double zFar);
void setOrthoProjection(double left, double right, double bottom, double top, double zNear, double zFar);
void setupProjectionMatrix() const;
void setupModelViewMatrix() const;
private:
Point3d eye_;
Point3d center_;
Point3d up_;
Point3d pos_;
double yaw_;
double pitch_;
double roll_;
bool useLookAtParams_;
Point3d scale_;
Mat projectionMatrix_;
double fov_;
double aspect_;
double left_;
double right_;
double bottom_;
double top_;
double zNear_;
double zFar_;
bool perspectiveProjection_;
};
//! OpenGL extension table
class CV_EXPORTS GlFuncTab
{
public:
virtual ~GlFuncTab();
virtual void genBuffers(int n, unsigned int* buffers) const = 0;
virtual void deleteBuffers(int n, const unsigned int* buffers) const = 0;
virtual void bufferData(unsigned int target, ptrdiff_t size, const void* data, unsigned int usage) const = 0;
virtual void bufferSubData(unsigned int target, ptrdiff_t offset, ptrdiff_t size, const void* data) const = 0;
virtual void bindBuffer(unsigned int target, unsigned int buffer) const = 0;
virtual void* mapBuffer(unsigned int target, unsigned int access) const = 0;
virtual void unmapBuffer(unsigned int target) const = 0;
virtual bool isGlContextInitialized() const = 0;
};
CV_EXPORTS void setGlFuncTab(const GlFuncTab* tab);
//////////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////////
// Error handling // Error handling
CV_EXPORTS void error(const char* error_string, const char* file, const int line, const char* func = ""); CV_EXPORTS void error(const char* error_string, const char* file, const int line, const char* func = "");
CV_EXPORTS bool checkGlError(const char* file, const int line, const char* func = "");
#if defined(__GNUC__)
#define CV_CheckGlError() CV_DbgAssert( (cv::gpu::checkGlError(__FILE__, __LINE__, __func__)) )
#else
#define CV_CheckGlError() CV_DbgAssert( (cv::gpu::checkGlError(__FILE__, __LINE__)) )
#endif
//////////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////////
//////////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////////
......
...@@ -708,4 +708,36 @@ CvBigFuncTable; ...@@ -708,4 +708,36 @@ CvBigFuncTable;
(tab).fn_2d[CV_32F] = (void*)FUNCNAME##_32f##FLAG; \ (tab).fn_2d[CV_32F] = (void*)FUNCNAME##_32f##FLAG; \
(tab).fn_2d[CV_64F] = (void*)FUNCNAME##_64f##FLAG (tab).fn_2d[CV_64F] = (void*)FUNCNAME##_64f##FLAG
//! OpenGL extension table
class CV_EXPORTS CvOpenGlFuncTab
{
public:
virtual ~CvOpenGlFuncTab();
virtual void genBuffers(int n, unsigned int* buffers) const = 0;
virtual void deleteBuffers(int n, const unsigned int* buffers) const = 0;
virtual void bufferData(unsigned int target, ptrdiff_t size, const void* data, unsigned int usage) const = 0;
virtual void bufferSubData(unsigned int target, ptrdiff_t offset, ptrdiff_t size, const void* data) const = 0;
virtual void bindBuffer(unsigned int target, unsigned int buffer) const = 0;
virtual void* mapBuffer(unsigned int target, unsigned int access) const = 0;
virtual void unmapBuffer(unsigned int target) const = 0;
virtual void generateBitmapFont(const std::string& family, int height, int weight, bool italic, bool underline, int start, int count, int base) const = 0;
virtual bool isGlContextInitialized() const = 0;
};
CV_EXPORTS void icvSetOpenGlFuncTab(const CvOpenGlFuncTab* tab);
CV_EXPORTS bool icvCheckGlError(const char* file, const int line, const char* func = "");
#if defined(__GNUC__)
#define CV_CheckGlError() CV_DbgAssert( (::icvCheckGlError(__FILE__, __LINE__, __func__)) )
#else
#define CV_CheckGlError() CV_DbgAssert( (::icvCheckGlError(__FILE__, __LINE__)) )
#endif
#endif #endif
This diff is collapsed.
This diff is collapsed.
...@@ -41,6 +41,8 @@ ...@@ -41,6 +41,8 @@
//M*/ //M*/
#include "precomp.hpp" #include "precomp.hpp"
#include "opencv2/core/gpumat.hpp"
#include "opencv2/core/opengl_interop.hpp"
/****************************************************************************************\ /****************************************************************************************\
* [scaled] Identity matrix initialization * * [scaled] Identity matrix initialization *
...@@ -873,6 +875,9 @@ _InputArray::_InputArray(const Mat& m) : flags(MAT), obj((void*)&m) {} ...@@ -873,6 +875,9 @@ _InputArray::_InputArray(const Mat& m) : flags(MAT), obj((void*)&m) {}
_InputArray::_InputArray(const vector<Mat>& vec) : flags(STD_VECTOR_MAT), obj((void*)&vec) {} _InputArray::_InputArray(const vector<Mat>& vec) : flags(STD_VECTOR_MAT), obj((void*)&vec) {}
_InputArray::_InputArray(const double& val) : flags(MATX+CV_64F), obj((void*)&val), sz(Size(1,1)) {} _InputArray::_InputArray(const double& val) : flags(MATX+CV_64F), obj((void*)&val), sz(Size(1,1)) {}
_InputArray::_InputArray(const MatExpr& expr) : flags(EXPR), obj((void*)&expr) {} _InputArray::_InputArray(const MatExpr& expr) : flags(EXPR), obj((void*)&expr) {}
_InputArray::_InputArray(const GlBuffer& buf) : flags(OPENGL_BUFFER), obj((void*)&buf) {}
_InputArray::_InputArray(const GlTexture& tex) : flags(OPENGL_TEXTURE), obj((void*)&tex) {}
_InputArray::_InputArray(const gpu::GpuMat& d_mat) : flags(GPU_MAT), obj((void*)&d_mat) {}
Mat _InputArray::getMat(int i) const Mat _InputArray::getMat(int i) const
{ {
...@@ -1011,6 +1016,42 @@ void _InputArray::getMatVector(vector<Mat>& mv) const ...@@ -1011,6 +1016,42 @@ void _InputArray::getMatVector(vector<Mat>& mv) const
return; return;
} }
} }
GlBuffer _InputArray::getGlBuffer() const
{
int k = kind();
CV_Assert(k == OPENGL_BUFFER);
//if( k == OPENGL_BUFFER )
{
const GlBuffer* buf = (const GlBuffer*)obj;
return *buf;
}
}
GlTexture _InputArray::getGlTexture() const
{
int k = kind();
CV_Assert(k == OPENGL_TEXTURE);
//if( k == OPENGL_TEXTURE )
{
const GlTexture* tex = (const GlTexture*)obj;
return *tex;
}
}
gpu::GpuMat _InputArray::getGpuMat() const
{
int k = kind();
CV_Assert(k == GPU_MAT);
//if( k == GPU_MAT )
{
const gpu::GpuMat* d_mat = (const gpu::GpuMat*)obj;
return *d_mat;
}
}
int _InputArray::kind() const int _InputArray::kind() const
{ {
...@@ -1063,8 +1104,7 @@ Size _InputArray::size(int i) const ...@@ -1063,8 +1104,7 @@ Size _InputArray::size(int i) const
return szb == szi ? Size((int)szb, 1) : Size((int)(szb/CV_ELEM_SIZE(flags)), 1); return szb == szi ? Size((int)szb, 1) : Size((int)(szb/CV_ELEM_SIZE(flags)), 1);
} }
CV_Assert( k == STD_VECTOR_MAT ); if( k == STD_VECTOR_MAT )
//if( k == STD_VECTOR_MAT )
{ {
const vector<Mat>& vv = *(const vector<Mat>*)obj; const vector<Mat>& vv = *(const vector<Mat>*)obj;
if( i < 0 ) if( i < 0 )
...@@ -1073,6 +1113,28 @@ Size _InputArray::size(int i) const ...@@ -1073,6 +1113,28 @@ Size _InputArray::size(int i) const
return vv[i].size(); return vv[i].size();
} }
if( k == OPENGL_BUFFER )
{
CV_Assert( i < 0 );
const GlBuffer* buf = (const GlBuffer*)obj;
return buf->size();
}
if( k == OPENGL_TEXTURE )
{
CV_Assert( i < 0 );
const GlTexture* tex = (const GlTexture*)obj;
return tex->size();
}
CV_Assert( k == GPU_MAT );
//if( k == GPU_MAT )
{
CV_Assert( i < 0 );
const gpu::GpuMat* d_mat = (const gpu::GpuMat*)obj;
return d_mat->size();
}
} }
size_t _InputArray::total(int i) const size_t _InputArray::total(int i) const
...@@ -1096,14 +1158,23 @@ int _InputArray::type(int i) const ...@@ -1096,14 +1158,23 @@ int _InputArray::type(int i) const
if( k == NONE ) if( k == NONE )
return -1; return -1;
CV_Assert( k == STD_VECTOR_MAT ); if( k == STD_VECTOR_MAT )
//if( k == STD_VECTOR_MAT )
{ {
const vector<Mat>& vv = *(const vector<Mat>*)obj; const vector<Mat>& vv = *(const vector<Mat>*)obj;
CV_Assert( i < (int)vv.size() ); CV_Assert( i < (int)vv.size() );
return vv[i >= 0 ? i : 0].type(); return vv[i >= 0 ? i : 0].type();
} }
if( k == OPENGL_BUFFER )
return ((const GlBuffer*)obj)->type();
if( k == OPENGL_TEXTURE )
return ((const GlTexture*)obj)->type();
CV_Assert( k == GPU_MAT );
//if( k == GPU_MAT )
return ((const gpu::GpuMat*)obj)->type();
} }
int _InputArray::depth(int i) const int _InputArray::depth(int i) const
...@@ -1144,12 +1215,21 @@ bool _InputArray::empty() const ...@@ -1144,12 +1215,21 @@ bool _InputArray::empty() const
return vv.empty(); return vv.empty();
} }
CV_Assert( k == STD_VECTOR_MAT ); if( k == STD_VECTOR_MAT )
//if( k == STD_VECTOR_MAT )
{ {
const vector<Mat>& vv = *(const vector<Mat>*)obj; const vector<Mat>& vv = *(const vector<Mat>*)obj;
return vv.empty(); return vv.empty();
} }
if( k == OPENGL_BUFFER )
return ((const GlBuffer*)obj)->empty();
if( k == OPENGL_TEXTURE )
return ((const GlTexture*)obj)->empty();
CV_Assert( k == GPU_MAT );
//if( k == GPU_MAT )
return ((const gpu::GpuMat*)obj)->empty();
} }
......
This diff is collapsed.
...@@ -44,7 +44,6 @@ ...@@ -44,7 +44,6 @@
#define __OPENCV_HIGHGUI_HPP__ #define __OPENCV_HIGHGUI_HPP__
#include "opencv2/core/core.hpp" #include "opencv2/core/core.hpp"
#include "opencv2/core/gpumat.hpp"
#include "opencv2/highgui/highgui_c.h" #include "opencv2/highgui/highgui_c.h"
#ifdef __cplusplus #ifdef __cplusplus
...@@ -129,7 +128,7 @@ CV_EXPORTS_W void setTrackbarPos(const string& trackbarname, const string& winna ...@@ -129,7 +128,7 @@ CV_EXPORTS_W void setTrackbarPos(const string& trackbarname, const string& winna
typedef void (CV_CDECL *OpenGLCallback)(void* userdata); typedef void (CV_CDECL *OpenGLCallback)(void* userdata);
CV_EXPORTS void createOpenGLCallback(const string& winname, OpenGLCallback onOpenGlDraw, void* userdata = 0); CV_EXPORTS void createOpenGLCallback(const string& winname, OpenGLCallback onOpenGlDraw, void* userdata = 0);
typedef void (CV_CDECL *OpenGlDrawCallback)(void* userdata); typedef void (*OpenGlDrawCallback)(void* userdata);
static inline void setOpenGlDrawCallback(const string& winname, OpenGlDrawCallback onOpenGlDraw, void* userdata = 0) static inline void setOpenGlDrawCallback(const string& winname, OpenGlDrawCallback onOpenGlDraw, void* userdata = 0)
{ {
createOpenGLCallback(winname, onOpenGlDraw, userdata); createOpenGLCallback(winname, onOpenGlDraw, userdata);
...@@ -139,22 +138,8 @@ CV_EXPORTS void setOpenGlContext(const string& winname); ...@@ -139,22 +138,8 @@ CV_EXPORTS void setOpenGlContext(const string& winname);
CV_EXPORTS void updateWindow(const string& winname); CV_EXPORTS void updateWindow(const string& winname);
CV_EXPORTS void imshow(const string& winname, const gpu::GlTexture& tex); CV_EXPORTS void pointCloudShow(const string& winname, const GlCamera& camera, const GlArrays& arr);
CV_EXPORTS void imshow(const string& winname, const gpu::GlBuffer& buf); CV_EXPORTS void pointCloudShow(const string& winname, const GlCamera& camera, InputArray points, InputArray colors = noArray());
CV_EXPORTS void imshow(const string& winname, const gpu::GpuMat& d_mat);
CV_EXPORTS void pointCloudShow(const string& winname, const gpu::GlCamera& camera, const gpu::GlArrays& arr);
CV_EXPORTS void pointCloudShow(const string& winname, const gpu::GlCamera& camera, const gpu::GlBuffer& points,
const gpu::GlBuffer& colors = gpu::GlBuffer(gpu::GlBuffer::ARRAY_BUFFER));
CV_EXPORTS void pointCloudShow(const string& winname, const gpu::GlCamera& camera, const gpu::GpuMat& points,
const gpu::GpuMat& colors = gpu::GpuMat());
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 //Only for Qt
......
...@@ -63,8 +63,7 @@ enum { CV_FONT_LIGHT = 25,//QFont::Light, ...@@ -63,8 +63,7 @@ enum { CV_FONT_LIGHT = 25,//QFont::Light,
enum { CV_STYLE_NORMAL = 0,//QFont::StyleNormal, enum { CV_STYLE_NORMAL = 0,//QFont::StyleNormal,
CV_STYLE_ITALIC = 1,//QFont::StyleItalic, CV_STYLE_ITALIC = 1,//QFont::StyleItalic,
CV_STYLE_OBLIQUE = 2,//QFont::StyleOblique CV_STYLE_OBLIQUE = 2 //QFont::StyleOblique
CV_STYLE_UNDERLINE = 4
}; };
/* ---------*/ /* ---------*/
...@@ -258,11 +257,6 @@ CVAPI(void) cvCreateOpenGLCallback( const char* window_name, CvOpenGLCallback ca ...@@ -258,11 +257,6 @@ CVAPI(void) cvCreateOpenGLCallback( const char* window_name, CvOpenGLCallback ca
CVAPI(void) cvSetOpenGlContext(const char* window_name); CVAPI(void) cvSetOpenGlContext(const char* window_name);
CVAPI(void) cvUpdateWindow(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 * * Working with Video Files and Cameras *
......
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
...@@ -3,6 +3,7 @@ ...@@ -3,6 +3,7 @@
#include "opencv2/core/core.hpp" #include "opencv2/core/core.hpp"
#include "opencv2/core/gpumat.hpp" #include "opencv2/core/gpumat.hpp"
#include "opencv2/core/opengl_interop.hpp"
#include "opencv2/gpu/gpu.hpp" #include "opencv2/gpu/gpu.hpp"
#include "opencv2/highgui/highgui.hpp" #include "opencv2/highgui/highgui.hpp"
#include "opencv2/contrib/contrib.hpp" #include "opencv2/contrib/contrib.hpp"
...@@ -43,11 +44,17 @@ int main(int argc, char* argv[]) ...@@ -43,11 +44,17 @@ int main(int argc, char* argv[])
{ {
bool haveCuda = getCudaEnabledDeviceCount() > 0; bool haveCuda = getCudaEnabledDeviceCount() > 0;
namedWindow("OpenGL Mat", WINDOW_OPENGL | WINDOW_AUTOSIZE); const string openGlMatWnd = "OpenGL Mat";
namedWindow("OpenGL GlBuffer", WINDOW_OPENGL | WINDOW_AUTOSIZE); const string openGlBufferWnd = "OpenGL GlBuffer";
namedWindow("OpenGL GlTexture", WINDOW_OPENGL | WINDOW_AUTOSIZE); const string openGlTextureWnd = "OpenGL GlTexture";
const string openGlGpuMatWnd = "OpenGL GpuMat";
const string matWnd = "Mat";
namedWindow(openGlMatWnd, WINDOW_OPENGL | WINDOW_AUTOSIZE);
namedWindow(openGlBufferWnd, WINDOW_OPENGL | WINDOW_AUTOSIZE);
namedWindow(openGlTextureWnd, WINDOW_OPENGL | WINDOW_AUTOSIZE);
if (haveCuda) if (haveCuda)
namedWindow("OpenGL GpuMat", WINDOW_OPENGL | WINDOW_AUTOSIZE); namedWindow(openGlGpuMatWnd, WINDOW_OPENGL | WINDOW_AUTOSIZE);
namedWindow("Mat", WINDOW_AUTOSIZE); namedWindow("Mat", WINDOW_AUTOSIZE);
Mat img = imread(argv[1]); Mat img = imread(argv[1]);
...@@ -55,10 +62,10 @@ int main(int argc, char* argv[]) ...@@ -55,10 +62,10 @@ int main(int argc, char* argv[])
if (haveCuda) if (haveCuda)
setGlDevice(); setGlDevice();
setOpenGlContext("OpenGL GlBuffer"); setOpenGlContext(openGlBufferWnd);
GlBuffer buf(img, GlBuffer::TEXTURE_BUFFER); GlBuffer buf(img, GlBuffer::TEXTURE_BUFFER);
setOpenGlContext("OpenGL GlTexture"); setOpenGlContext(openGlTextureWnd);
GlTexture tex(img); GlTexture tex(img);
GpuMat d_img; GpuMat d_img;
...@@ -69,48 +76,50 @@ int main(int argc, char* argv[]) ...@@ -69,48 +76,50 @@ int main(int argc, char* argv[])
{ {
Timer t("OpenGL Mat "); Timer t("OpenGL Mat ");
imshow("OpenGL Mat", img); imshow(openGlMatWnd, img);
} }
{ {
Timer t("OpenGL GlBuffer "); Timer t("OpenGL GlBuffer ");
imshow("OpenGL GlBuffer", buf); imshow(openGlBufferWnd, buf);
} }
{ {
Timer t("OpenGL GlTexture"); Timer t("OpenGL GlTexture");
imshow("OpenGL GlTexture", tex); imshow(openGlTextureWnd, tex);
} }
if (haveCuda) if (haveCuda)
{ {
Timer t("OpenGL GpuMat "); Timer t("OpenGL GpuMat ");
imshow("OpenGL GpuMat", d_img); imshow(openGlGpuMatWnd, d_img);
} }
{ {
Timer t("Mat "); Timer t("Mat ");
imshow("Mat", img); imshow(matWnd, img);
} }
waitKey();
cout << "\n=== Second call\n\n"; cout << "\n=== Second call\n\n";
{ {
Timer t("OpenGL Mat "); Timer t("OpenGL Mat ");
imshow("OpenGL Mat", img); imshow(openGlMatWnd, img);
} }
{ {
Timer t("OpenGL GlBuffer "); Timer t("OpenGL GlBuffer ");
imshow("OpenGL GlBuffer", buf); imshow(openGlBufferWnd, buf);
} }
{ {
Timer t("OpenGL GlTexture"); Timer t("OpenGL GlTexture");
imshow("OpenGL GlTexture", tex); imshow(openGlTextureWnd, tex);
} }
if (haveCuda) if (haveCuda)
{ {
Timer t("OpenGL GpuMat "); Timer t("OpenGL GpuMat ");
imshow("OpenGL GpuMat", d_img); imshow(openGlGpuMatWnd, d_img);
} }
{ {
Timer t("Mat "); Timer t("Mat ");
imshow("Mat", img); imshow(matWnd, img);
} }
cout << "\n"; cout << "\n";
......
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