Commit 08fbf667 authored by Vladislav Vinogradov's avatar Vladislav Vinogradov

refactored opengl functionality

* removed OpenGLFuncTab, now extensions are loaded internally
* renamed GlTexture -> GlTexture2D
* added support of GlBuffer and GlTexture2D to InputArray/OutputArray
* added ELEMENT_ARRAY_BUFFER and PIXEL_PACK_BUFFER targets
* added copyFrom/copyTo method for GlBuffer and GlTexture2D
* removed GlFont
* removed pointCloudShow
* removed OpenGLCleanCallback
parent 2eebd8d9
......@@ -91,7 +91,7 @@ class SparseMat;
typedef Mat MatND;
class GlBuffer;
class GlTexture;
class GlTexture2D;
class GlArrays;
class GlCamera;
......@@ -1311,7 +1311,7 @@ public:
STD_VECTOR_MAT = 5 << KIND_SHIFT,
EXPR = 6 << KIND_SHIFT,
OPENGL_BUFFER = 7 << KIND_SHIFT,
OPENGL_TEXTURE = 8 << KIND_SHIFT,
OPENGL_TEXTURE2D = 8 << KIND_SHIFT,
GPU_MAT = 9 << KIND_SHIFT
};
_InputArray();
......@@ -1328,13 +1328,13 @@ public:
_InputArray(const Scalar& s);
_InputArray(const double& val);
_InputArray(const GlBuffer& buf);
_InputArray(const GlTexture& tex);
_InputArray(const GlTexture2D& tex);
_InputArray(const gpu::GpuMat& d_mat);
virtual Mat getMat(int i=-1) const;
virtual void getMatVector(vector<Mat>& mv) const;
virtual GlBuffer getGlBuffer() const;
virtual GlTexture getGlTexture() const;
virtual GlTexture2D getGlTexture2D() const;
virtual gpu::GpuMat getGpuMat() const;
virtual int kind() const;
......@@ -1385,6 +1385,8 @@ public:
template<typename _Tp, int m, int n> _OutputArray(Matx<_Tp, m, n>& matx);
template<typename _Tp> _OutputArray(_Tp* vec, int n);
_OutputArray(gpu::GpuMat& d_mat);
_OutputArray(GlBuffer& buf);
_OutputArray(GlTexture2D& tex);
_OutputArray(const Mat& m);
template<typename _Tp> _OutputArray(const vector<_Tp>& vec);
......@@ -1395,12 +1397,16 @@ public:
template<typename _Tp, int m, int n> _OutputArray(const Matx<_Tp, m, n>& matx);
template<typename _Tp> _OutputArray(const _Tp* vec, int n);
_OutputArray(const gpu::GpuMat& d_mat);
_OutputArray(const GlBuffer& buf);
_OutputArray(const GlTexture2D& tex);
virtual bool fixedSize() const;
virtual bool fixedType() const;
virtual bool needed() const;
virtual Mat& getMatRef(int i=-1) const;
virtual gpu::GpuMat& getGpuMatRef() const;
virtual GlBuffer& getGlBufferRef() const;
virtual GlTexture2D& getGlTexture2DRef() const;
virtual void create(Size sz, int type, int i=-1, bool allowTransposed=false, int fixedDepthMask=0) const;
virtual void create(int rows, int cols, int type, int i=-1, bool allowTransposed=false, int fixedDepthMask=0) const;
virtual void create(int dims, const int* size, int type, int i=-1, bool allowTransposed=false, int fixedDepthMask=0) const;
......
......@@ -750,39 +750,4 @@ typedef struct CvBigFuncTable
(tab).fn_2d[CV_32F] = (void*)FUNCNAME##_32f##FLAG; \
(tab).fn_2d[CV_64F] = (void*)FUNCNAME##_64f##FLAG
#ifdef __cplusplus
//! 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 //__cplusplus
#endif // __OPENCV_CORE_INTERNAL_HPP__
This source diff could not be displayed because it is too large. You can view the blob instead.
This diff is collapsed.
......@@ -922,8 +922,8 @@ _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 double& val) : flags(FIXED_TYPE + FIXED_SIZE + MATX + CV_64F), obj((void*)&val), sz(Size(1,1)) {}
_InputArray::_InputArray(const MatExpr& expr) : flags(FIXED_TYPE + FIXED_SIZE + EXPR), obj((void*)&expr) {}
_InputArray::_InputArray(const GlBuffer& buf) : flags(FIXED_TYPE + FIXED_SIZE + OPENGL_BUFFER), obj((void*)&buf) {}
_InputArray::_InputArray(const GlTexture& tex) : flags(FIXED_TYPE + FIXED_SIZE + OPENGL_TEXTURE), obj((void*)&tex) {}
_InputArray::_InputArray(const GlBuffer& buf) : flags(OPENGL_BUFFER), obj((void*)&buf) {}
_InputArray::_InputArray(const GlTexture2D &tex) : flags(OPENGL_TEXTURE2D), obj((void*)&tex) {}
_InputArray::_InputArray(const gpu::GpuMat& d_mat) : flags(GPU_MAT), obj((void*)&d_mat) {}
Mat _InputArray::getMat(int i) const
......@@ -1076,14 +1076,14 @@ GlBuffer _InputArray::getGlBuffer() const
}
}
GlTexture _InputArray::getGlTexture() const
GlTexture2D _InputArray::getGlTexture2D() const
{
int k = kind();
CV_Assert(k == OPENGL_TEXTURE);
CV_Assert(k == OPENGL_TEXTURE2D);
//if( k == OPENGL_TEXTURE )
{
const GlTexture* tex = (const GlTexture*)obj;
const GlTexture2D* tex = (const GlTexture2D*)obj;
return *tex;
}
}
......@@ -1168,10 +1168,10 @@ Size _InputArray::size(int i) const
return buf->size();
}
if( k == OPENGL_TEXTURE )
if( k == OPENGL_TEXTURE2D )
{
CV_Assert( i < 0 );
const GlTexture* tex = (const GlTexture*)obj;
const GlTexture2D* tex = (const GlTexture2D*)obj;
return tex->size();
}
......@@ -1216,9 +1216,6 @@ int _InputArray::type(int i) const
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();
......@@ -1271,8 +1268,8 @@ bool _InputArray::empty() const
if( k == OPENGL_BUFFER )
return ((const GlBuffer*)obj)->empty();
if( k == OPENGL_TEXTURE )
return ((const GlTexture*)obj)->empty();
if( k == OPENGL_TEXTURE2D )
return ((const GlTexture2D*)obj)->empty();
CV_Assert( k == GPU_MAT );
//if( k == GPU_MAT )
......@@ -1285,10 +1282,14 @@ _OutputArray::~_OutputArray() {}
_OutputArray::_OutputArray(Mat& m) : _InputArray(m) {}
_OutputArray::_OutputArray(vector<Mat>& vec) : _InputArray(vec) {}
_OutputArray::_OutputArray(gpu::GpuMat& d_mat) : _InputArray(d_mat) {}
_OutputArray::_OutputArray(GlBuffer& buf) : _InputArray(buf) {}
_OutputArray::_OutputArray(GlTexture2D& tex) : _InputArray(tex) {}
_OutputArray::_OutputArray(const Mat& m) : _InputArray(m) {flags |= FIXED_SIZE|FIXED_TYPE;}
_OutputArray::_OutputArray(const vector<Mat>& vec) : _InputArray(vec) {flags |= FIXED_SIZE;}
_OutputArray::_OutputArray(const gpu::GpuMat& d_mat) : _InputArray(d_mat) {flags |= FIXED_SIZE|FIXED_TYPE;}
_OutputArray::_OutputArray(const GlBuffer& buf) : _InputArray(buf) {flags |= FIXED_SIZE|FIXED_TYPE;}
_OutputArray::_OutputArray(const GlTexture2D& tex) : _InputArray(tex) {flags |= FIXED_SIZE|FIXED_TYPE;}
bool _OutputArray::fixedSize() const
......@@ -1318,6 +1319,13 @@ void _OutputArray::create(Size _sz, int mtype, int i, bool allowTransposed, int
((gpu::GpuMat*)obj)->create(_sz, mtype);
return;
}
if( k == OPENGL_BUFFER && i < 0 && !allowTransposed && fixedDepthMask == 0 )
{
CV_Assert(!fixedSize() || ((GlBuffer*)obj)->size() == _sz);
CV_Assert(!fixedType() || ((GlBuffer*)obj)->type() == mtype);
((GlBuffer*)obj)->create(_sz, mtype);
return;
}
int sizes[] = {_sz.height, _sz.width};
create(2, sizes, mtype, i, allowTransposed, fixedDepthMask);
}
......@@ -1339,6 +1347,13 @@ void _OutputArray::create(int rows, int cols, int mtype, int i, bool allowTransp
((gpu::GpuMat*)obj)->create(rows, cols, mtype);
return;
}
if( k == OPENGL_BUFFER && i < 0 && !allowTransposed && fixedDepthMask == 0 )
{
CV_Assert(!fixedSize() || ((GlBuffer*)obj)->size() == Size(cols, rows));
CV_Assert(!fixedType() || ((GlBuffer*)obj)->type() == mtype);
((GlBuffer*)obj)->create(rows, cols, mtype);
return;
}
int sizes[] = {rows, cols};
create(2, sizes, mtype, i, allowTransposed, fixedDepthMask);
}
......@@ -1558,6 +1573,18 @@ void _OutputArray::release() const
return;
}
if( k == OPENGL_BUFFER )
{
((GlBuffer*)obj)->release();
return;
}
if( k == OPENGL_TEXTURE2D )
{
((GlTexture2D*)obj)->release();
return;
}
if( k == NONE )
return;
......@@ -1623,6 +1650,20 @@ gpu::GpuMat& _OutputArray::getGpuMatRef() const
return *(gpu::GpuMat*)obj;
}
GlBuffer& _OutputArray::getGlBufferRef() const
{
int k = kind();
CV_Assert( k == OPENGL_BUFFER );
return *(GlBuffer*)obj;
}
GlTexture2D& _OutputArray::getGlTexture2DRef() const
{
int k = kind();
CV_Assert( k == OPENGL_TEXTURE2D );
return *(GlTexture2D*)obj;
}
static _OutputArray _none;
OutputArray noArray() { return _none; }
......
This diff is collapsed.
This diff is collapsed.
......@@ -69,6 +69,7 @@
#include <cuda_runtime.h>
#include "opencv2/core/core.hpp"
#include "opencv2/core/opengl_interop.hpp"
#include "opencv2/highgui/highgui.hpp"
#include "opencv2/calib3d/calib3d.hpp"
#include "opencv2/imgproc/imgproc.hpp"
......
......@@ -125,16 +125,13 @@ CV_EXPORTS_W void setTrackbarPos(const string& trackbarname, const string& winna
// OpenGL support
typedef void (*OpenGlDrawCallback)(void* userdata);
typedef void (CV_CDECL *OpenGlDrawCallback)(void* userdata);
CV_EXPORTS void setOpenGlDrawCallback(const string& winname, OpenGlDrawCallback onOpenGlDraw, void* userdata = 0);
CV_EXPORTS void setOpenGlContext(const string& winname);
CV_EXPORTS void updateWindow(const string& winname);
CV_EXPORTS void pointCloudShow(const string& winname, const GlCamera& camera, const GlArrays& arr);
CV_EXPORTS void pointCloudShow(const string& winname, const GlCamera& camera, InputArray points, InputArray colors = noArray());
//Only for Qt
CV_EXPORTS CvFont fontQt(const string& nameFont, int pointSize=-1,
......
......@@ -206,9 +206,6 @@ void cvSetRatioWindow_QT(const char* name,double prop_value);
double cvGetOpenGlProp_QT(const char* name);
#endif
// OpenGL
typedef void (CV_CDECL *CvOpenGlCleanCallback)(void* userdata);
void icvSetOpenGlCleanCallback(const char* window_name, CvOpenGlCleanCallback callback, void* userdata);
/*namespace cv
......
......@@ -40,6 +40,7 @@
//M*/
#include "precomp.hpp"
#include <map>
#include "opencv2/core/opengl_interop.hpp"
// in later times, use this file as a dispatcher to implementations like cvcap.cpp
......@@ -240,94 +241,15 @@ void cv::updateWindow(const string& windowName)
#ifdef HAVE_OPENGL
namespace
{
const int CV_TEXTURE_MAGIC_VAL = 0x00287653;
const int CV_POINT_CLOUD_MAGIC_VAL = 0x00287654;
struct GlObjBase
{
int flag;
GlObjBase* next;
GlObjBase* prev;
std::string winname;
virtual ~GlObjBase() {}
};
GlObjBase* g_glObjs = 0;
GlObjBase* findGlObjByName(const std::string& winname)
{
GlObjBase* obj = g_glObjs;
while(obj && obj->winname != winname)
obj = obj->next;
return obj;
}
void addGlObj(GlObjBase* glObj)
{
glObj->next = g_glObjs;
glObj->prev = 0;
if (g_glObjs)
g_glObjs->prev = glObj;
g_glObjs = glObj;
}
void removeGlObj(GlObjBase* glObj)
{
if (glObj->prev)
glObj->prev->next = glObj->next;
else
g_glObjs = glObj->next;
if (glObj->next)
glObj->next->prev = glObj->prev;
delete glObj;
}
struct GlObjTex : GlObjBase
{
cv::GlTexture tex;
};
std::map<std::string, cv::GlTexture2D> wndTexs;
std::map<std::string, cv::GlTexture2D> ownWndTexs;
std::map<std::string, cv::GlBuffer> ownWndBufs;
void CV_CDECL glDrawTextureCallback(void* userdata)
{
GlObjTex* texObj = static_cast<GlObjTex*>(userdata);
CV_DbgAssert(texObj->flag == CV_TEXTURE_MAGIC_VAL);
static cv::GlCamera glCamera;
cv::GlTexture2D* texObj = static_cast<cv::GlTexture2D*>(userdata);
glCamera.setupProjectionMatrix();
cv::render(texObj->tex);
}
struct GlObjPointCloud : GlObjBase
{
cv::GlArrays arr;
cv::GlCamera camera;
};
void CV_CDECL glDrawPointCloudCallback(void* userdata)
{
GlObjPointCloud* pointCloudObj = static_cast<GlObjPointCloud*>(userdata);
CV_DbgAssert(pointCloudObj->flag == CV_POINT_CLOUD_MAGIC_VAL);
pointCloudObj->camera.setupProjectionMatrix();
pointCloudObj->camera.setupModelViewMatrix();
cv::render(pointCloudObj->arr);
}
void CV_CDECL glCleanCallback(void* userdata)
{
GlObjBase* glObj = static_cast<GlObjBase*>(userdata);
removeGlObj(glObj);
cv::render(*texObj);
}
}
#endif // HAVE_OPENGL
......@@ -339,7 +261,8 @@ void cv::imshow( const string& winname, InputArray _img )
CvMat c_img = img;
cvShowImage(winname.c_str(), &c_img);
#else
double useGl = getWindowProperty(winname, WND_PROP_OPENGL);
const double useGl = getWindowProperty(winname, WND_PROP_OPENGL);
if (useGl <= 0)
{
Mat img = _img.getMat();
......@@ -348,7 +271,7 @@ void cv::imshow( const string& winname, InputArray _img )
}
else
{
double autoSize = getWindowProperty(winname, WND_PROP_AUTOSIZE);
const double autoSize = getWindowProperty(winname, WND_PROP_AUTOSIZE);
if (autoSize > 0)
{
......@@ -358,142 +281,41 @@ void cv::imshow( const string& winname, InputArray _img )
setOpenGlContext(winname);
GlObjBase* glObj = findGlObjByName(winname);
if (glObj && glObj->flag != CV_TEXTURE_MAGIC_VAL)
if (_img.kind() == _InputArray::OPENGL_TEXTURE2D)
{
icvSetOpenGlCleanCallback(winname.c_str(), 0, 0);
glObj = 0;
}
if (glObj)
{
GlObjTex* texObj = static_cast<GlObjTex*>(glObj);
texObj->tex.copyFrom(_img);
}
else
{
GlObjTex* texObj = new GlObjTex;
texObj->tex.copyFrom(_img);
cv::GlTexture2D& tex = wndTexs[winname];
glObj = texObj;
glObj->flag = CV_TEXTURE_MAGIC_VAL;
glObj->winname = winname;
tex = _img.getGlTexture2D();
addGlObj(glObj);
tex.setAutoRelease(false);
icvSetOpenGlCleanCallback(winname.c_str(), glCleanCallback, glObj);
setOpenGlDrawCallback(winname, glDrawTextureCallback, &tex);
}
setOpenGlDrawCallback(winname, glDrawTextureCallback, glObj);
updateWindow(winname);
}
#endif
}
void cv::pointCloudShow(const string& winname, const GlCamera& camera, const GlArrays& arr)
{
#ifndef HAVE_OPENGL
CV_Error(CV_OpenGlNotSupported, "The library is compiled without OpenGL support");
(void)winname;
(void)camera;
(void)arr;
#else
namedWindow(winname, WINDOW_OPENGL);
setOpenGlContext(winname);
GlObjBase* glObj = findGlObjByName(winname);
if (glObj && glObj->flag != CV_POINT_CLOUD_MAGIC_VAL)
{
icvSetOpenGlCleanCallback(winname.c_str(), 0, 0);
glObj = 0;
}
if (glObj)
{
GlObjPointCloud* pointCloudObj = static_cast<GlObjPointCloud*>(glObj);
pointCloudObj->arr = arr;
pointCloudObj->camera = camera;
}
else
{
GlObjPointCloud* pointCloudObj = new GlObjPointCloud;
pointCloudObj->arr = arr;
pointCloudObj->camera = camera;
glObj = pointCloudObj;
glObj->flag = CV_POINT_CLOUD_MAGIC_VAL;
glObj->winname = winname;
addGlObj(glObj);
icvSetOpenGlCleanCallback(winname.c_str(), glCleanCallback, glObj);
}
setOpenGlDrawCallback(winname, glDrawPointCloudCallback, glObj);
updateWindow(winname);
#endif
}
void cv::pointCloudShow(const std::string& winname, const cv::GlCamera& camera, InputArray points, InputArray colors)
{
#ifndef HAVE_OPENGL
(void)winname;
(void)camera;
(void)points;
(void)colors;
CV_Error(CV_OpenGlNotSupported, "The library is compiled without OpenGL support");
#else
namedWindow(winname, WINDOW_OPENGL);
setOpenGlContext(winname);
GlObjBase* glObj = findGlObjByName(winname);
if (glObj && glObj->flag != CV_POINT_CLOUD_MAGIC_VAL)
{
icvSetOpenGlCleanCallback(winname.c_str(), 0, 0);
glObj = 0;
}
if (glObj)
{
GlObjPointCloud* pointCloudObj = static_cast<GlObjPointCloud*>(glObj);
pointCloudObj->arr.setVertexArray(points);
if (colors.empty())
pointCloudObj->arr.resetColorArray();
else
pointCloudObj->arr.setColorArray(colors);
pointCloudObj->camera = camera;
}
else
{
GlObjPointCloud* pointCloudObj = new GlObjPointCloud;
{
cv::GlTexture2D& tex = ownWndTexs[winname];
pointCloudObj->arr.setVertexArray(points);
if (!colors.empty())
pointCloudObj->arr.setColorArray(colors);
if (_img.kind() == _InputArray::GPU_MAT)
{
cv::GlBuffer& buf = ownWndBufs[winname];
buf.copyFrom(_img);
buf.setAutoRelease(false);
pointCloudObj->camera = camera;
tex.copyFrom(buf);
tex.setAutoRelease(false);
}
else
{
tex.copyFrom(_img);
}
glObj = pointCloudObj;
glObj->flag = CV_POINT_CLOUD_MAGIC_VAL;
glObj->winname = winname;
tex.setAutoRelease(false);
addGlObj(glObj);
setOpenGlDrawCallback(winname, glDrawTextureCallback, &tex);
}
icvSetOpenGlCleanCallback(winname.c_str(), glCleanCallback, glObj);
updateWindow(winname);
}
setOpenGlDrawCallback(winname, glDrawPointCloudCallback, glObj);
updateWindow(winname);
#endif
}
......@@ -516,11 +338,6 @@ CV_IMPL void cvUpdateWindow(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");
}
#endif // !HAVE_OPENGL
#if defined (HAVE_QT)
......
This diff is collapsed.
......@@ -141,7 +141,6 @@ public slots:
void enablePropertiesButtonEachWindow();
void setOpenGlDrawCallback(QString name, void* callback, void* userdata);
void setOpenGlCleanCallback(QString name, void* callback, void* userdata);
void setOpenGlContext(QString name);
void updateWindow(QString name);
double isOpenGl(QString name);
......@@ -312,7 +311,6 @@ public:
static void addSlider2(CvWindow* w, QString name, int* value, int count, CvTrackbarCallback2 on_change CV_DEFAULT(NULL), void* userdata CV_DEFAULT(0));
void setOpenGlDrawCallback(CvOpenGlDrawCallback callback, void* userdata);
void setOpenGlCleanCallback(CvOpenGlCleanCallback callback, void* userdata);
void makeCurrentOpenGlContext();
void updateGl();
bool isOpenGl();
......@@ -397,7 +395,6 @@ public:
virtual void startDisplayInfo(QString text, int delayms) = 0;
virtual void setOpenGlDrawCallback(CvOpenGlDrawCallback callback, void* userdata) = 0;
virtual void setOpenGlCleanCallback(CvOpenGlCleanCallback callback, void* userdata) = 0;
virtual void makeCurrentOpenGlContext() = 0;
virtual void updateGl() = 0;
......@@ -429,7 +426,6 @@ public:
void startDisplayInfo(QString text, int delayms);
void setOpenGlDrawCallback(CvOpenGlDrawCallback callback, void* userdata);
void setOpenGlCleanCallback(CvOpenGlCleanCallback callback, void* userdata);
void makeCurrentOpenGlContext();
void updateGl();
......@@ -456,11 +452,6 @@ private:
CvOpenGlDrawCallback glDrawCallback;
void* glDrawData;
CvOpenGlCleanCallback glCleanCallback;
void* glCleanData;
CvOpenGlFuncTab* glFuncTab;
void icvmouseHandler(QMouseEvent* event, type_mouse_event category, int& cv_event, int& flags);
void icvmouseProcessing(QPointF pt, int cv_event, int flags);
};
......@@ -491,7 +482,6 @@ public:
void startDisplayInfo(QString text, int delayms);
void setOpenGlDrawCallback(CvOpenGlDrawCallback callback, void* userdata);
void setOpenGlCleanCallback(CvOpenGlCleanCallback callback, void* userdata);
void makeCurrentOpenGlContext();
void updateGl();
......
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
......@@ -4,7 +4,6 @@
#include "cvconfig.h"
#include "opencv2/core/core.hpp"
#include "opencv2/core/opengl_interop.hpp"
#include "opencv2/highgui/highgui.hpp"
#include "opencv2/gpu/gpu.hpp"
......@@ -14,12 +13,6 @@ using namespace cv::gpu;
void getFlowField(const Mat& u, const Mat& v, Mat& flowField);
#ifdef HAVE_OPENGL
void needleMapDraw(void* userdata);
#endif
int main(int argc, const char* argv[])
{
try
......@@ -79,12 +72,8 @@ int main(int argc, const char* argv[])
namedWindow("Forward flow");
namedWindow("Backward flow");
namedWindow("Needle Map", WINDOW_OPENGL);
namedWindow("Interpolated frame");
setGlDevice();
cout << "Press:" << endl;
cout << "\tESC to quit" << endl;
cout << "\t'a' to move to the previous frame" << endl;
......@@ -123,14 +112,6 @@ int main(int argc, const char* argv[])
Mat flowFieldBackward;
getFlowField(Mat(d_bu), Mat(d_bv), flowFieldBackward);
#ifdef HAVE_OPENGL
cout << "Create Optical Flow Needle Map..." << endl;
GpuMat d_vertex, d_colors;
createOpticalFlowNeedleMap(d_fu, d_fv, d_vertex, d_colors);
#endif
cout << "Interpolating..." << endl;
// first frame color components
......@@ -195,14 +176,6 @@ int main(int argc, const char* argv[])
imshow("Forward flow", flowFieldForward);
imshow("Backward flow", flowFieldBackward);
#ifdef HAVE_OPENGL
GlArrays arr;
arr.setVertexArray(d_vertex);
arr.setColorArray(d_colors, false);
setOpenGlDrawCallback("Needle Map", needleMapDraw, &arr);
#endif
int currentFrame = 0;
imshow("Interpolated frame", frames[currentFrame]);
......@@ -292,21 +265,3 @@ void getFlowField(const Mat& u, const Mat& v, Mat& flowField)
}
}
}
#ifdef HAVE_OPENGL
void needleMapDraw(void* userdata)
{
const GlArrays* arr = static_cast<const GlArrays*>(userdata);
GlCamera camera;
camera.setOrthoProjection(0.0, 1.0, 1.0, 0.0, 0.0, 1.0);
camera.lookAt(Point3d(0.0, 0.0, 1.0), Point3d(0.0, 0.0, 0.0), Point3d(0.0, 1.0, 0.0));
camera.setupProjectionMatrix();
camera.setupModelViewMatrix();
render(*arr, RenderMode::TRIANGLES);
}
#endif
#include <iostream>
#include <string>
#include "opencv2/core/core.hpp"
#include "opencv2/core/gpumat.hpp"
#include "opencv2/core/opengl_interop.hpp"
#include "opencv2/gpu/gpu.hpp"
#include "opencv2/highgui/highgui.hpp"
#include "opencv2/contrib/contrib.hpp"
using namespace std;
using namespace cv;
using namespace cv::gpu;
struct Timer
{
Timer(const string& msg_)
{
msg = msg_;
tm.reset();
tm.start();
}
~Timer()
{
tm.stop();
cout << msg << " " << tm.getTimeMilli() << " ms\n";
}
string msg;
TickMeter tm;
};
int main(int argc, char* argv[])
{
if (argc < 2)
{
cout << "Usage: " << argv[0] << " image" << endl;
return -1;
}
try
{
bool haveCuda = getCudaEnabledDeviceCount() > 0;
const string openGlMatWnd = "OpenGL Mat";
const string openGlBufferWnd = "OpenGL GlBuffer";
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)
namedWindow(openGlGpuMatWnd, WINDOW_OPENGL | WINDOW_AUTOSIZE);
namedWindow("Mat", WINDOW_AUTOSIZE);
Mat img = imread(argv[1]);
if (haveCuda)
setGlDevice();
setOpenGlContext(openGlBufferWnd);
GlBuffer buf(img, GlBuffer::TEXTURE_BUFFER);
setOpenGlContext(openGlTextureWnd);
GlTexture tex(img);
GpuMat d_img;
if (haveCuda)
d_img.upload(img);
cout << "=== First call\n\n";
{
Timer t("OpenGL Mat ");
imshow(openGlMatWnd, img);
}
{
Timer t("OpenGL GlBuffer ");
imshow(openGlBufferWnd, buf);
}
{
Timer t("OpenGL GlTexture");
imshow(openGlTextureWnd, tex);
}
if (haveCuda)
{
Timer t("OpenGL GpuMat ");
imshow(openGlGpuMatWnd, d_img);
}
{
Timer t("Mat ");
imshow(matWnd, img);
}
waitKey();
cout << "\n=== Second call\n\n";
{
Timer t("OpenGL Mat ");
imshow(openGlMatWnd, img);
}
{
Timer t("OpenGL GlBuffer ");
imshow(openGlBufferWnd, buf);
}
{
Timer t("OpenGL GlTexture");
imshow(openGlTextureWnd, tex);
}
if (haveCuda)
{
Timer t("OpenGL GpuMat ");
imshow(openGlGpuMatWnd, d_img);
}
{
Timer t("Mat ");
imshow(matWnd, img);
}
cout << "\n";
waitKey();
}
catch(const exception& e)
{
cout << e.what() << endl;
}
return 0;
}
This diff is collapsed.
This diff is collapsed.
......@@ -47,7 +47,7 @@ GpuMat d_result[2];
// CPU result
Mat result;
void printHelp()
static void printHelp()
{
std::cout << "Usage: stereo_multi_gpu --left <image> --right <image>\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