updated OpenGL functionality:
* removed OpenGLFuncTab, now extensions are loaded internally * 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 * added Access parameter to GlBuffer::mapHost * added autoRelease parameter to all create methods
This commit is contained in:
parent
39baa2237e
commit
e06c3ec7c5
@ -1387,6 +1387,8 @@ public:
|
|||||||
template<typename _Tp, int m, int n> _OutputArray(Matx<_Tp, m, n>& matx);
|
template<typename _Tp, int m, int n> _OutputArray(Matx<_Tp, m, n>& matx);
|
||||||
template<typename _Tp> _OutputArray(_Tp* vec, int n);
|
template<typename _Tp> _OutputArray(_Tp* vec, int n);
|
||||||
_OutputArray(gpu::GpuMat& d_mat);
|
_OutputArray(gpu::GpuMat& d_mat);
|
||||||
|
_OutputArray(GlBuffer& buf);
|
||||||
|
_OutputArray(GlTexture& tex);
|
||||||
|
|
||||||
_OutputArray(const Mat& m);
|
_OutputArray(const Mat& m);
|
||||||
template<typename _Tp> _OutputArray(const vector<_Tp>& vec);
|
template<typename _Tp> _OutputArray(const vector<_Tp>& vec);
|
||||||
@ -1397,12 +1399,16 @@ public:
|
|||||||
template<typename _Tp, int m, int n> _OutputArray(const Matx<_Tp, m, n>& matx);
|
template<typename _Tp, int m, int n> _OutputArray(const Matx<_Tp, m, n>& matx);
|
||||||
template<typename _Tp> _OutputArray(const _Tp* vec, int n);
|
template<typename _Tp> _OutputArray(const _Tp* vec, int n);
|
||||||
_OutputArray(const gpu::GpuMat& d_mat);
|
_OutputArray(const gpu::GpuMat& d_mat);
|
||||||
|
_OutputArray(const GlBuffer& buf);
|
||||||
|
_OutputArray(const GlTexture& tex);
|
||||||
|
|
||||||
virtual bool fixedSize() const;
|
virtual bool fixedSize() const;
|
||||||
virtual bool fixedType() const;
|
virtual bool fixedType() const;
|
||||||
virtual bool needed() const;
|
virtual bool needed() const;
|
||||||
virtual Mat& getMatRef(int i=-1) const;
|
virtual Mat& getMatRef(int i=-1) const;
|
||||||
/*virtual*/ gpu::GpuMat& getGpuMatRef() const;
|
/*virtual*/ gpu::GpuMat& getGpuMatRef() const;
|
||||||
|
/*virtual*/ GlBuffer& getGlBufferRef() const;
|
||||||
|
/*virtual*/ GlTexture& getGlTextureRef() const;
|
||||||
virtual void create(Size sz, int type, int i=-1, bool allowTransposed=false, int fixedDepthMask=0) 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 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;
|
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_32F] = (void*)FUNCNAME##_32f##FLAG; \
|
||||||
(tab).fn_2d[CV_64F] = (void*)FUNCNAME##_64f##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__
|
#endif // __OPENCV_CORE_INTERNAL_HPP__
|
||||||
|
@ -47,117 +47,169 @@
|
|||||||
|
|
||||||
#include "opencv2/core/core.hpp"
|
#include "opencv2/core/core.hpp"
|
||||||
|
|
||||||
namespace cv
|
namespace cv {
|
||||||
{
|
|
||||||
|
CV_EXPORTS bool checkGlError(const char* file, const int line, const char* func = "");
|
||||||
|
|
||||||
|
#if defined(__GNUC__)
|
||||||
|
#define CV_CheckGlError() CV_DbgAssert( (cv::checkGlError(__FILE__, __LINE__, __func__)) )
|
||||||
|
#else
|
||||||
|
#define CV_CheckGlError() CV_DbgAssert( (cv::checkGlError(__FILE__, __LINE__)) )
|
||||||
|
#endif
|
||||||
|
|
||||||
|
/////////////////// OpenGL Objects ///////////////////
|
||||||
|
|
||||||
//! Smart pointer for OpenGL buffer memory with reference counting.
|
//! Smart pointer for OpenGL buffer memory with reference counting.
|
||||||
class CV_EXPORTS GlBuffer
|
class CV_EXPORTS GlBuffer
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
enum Usage
|
enum Target
|
||||||
{
|
{
|
||||||
ARRAY_BUFFER = 0x8892, // buffer will use for OpenGL arrays (vertices, colors, normals, etc)
|
ARRAY_BUFFER = 0x8892, //!< The buffer will be used as a source for vertex data
|
||||||
TEXTURE_BUFFER = 0x88EC // buffer will ise for OpenGL textures
|
ELEMENT_ARRAY_BUFFER = 0x8893, //!< The buffer will be used for indices (in glDrawElements, for example)
|
||||||
|
PIXEL_PACK_BUFFER = 0x88EB, //!< The buffer will be used for reading from OpenGL textures
|
||||||
|
PIXEL_UNPACK_BUFFER = 0x88EC //!< The buffer will be used for writing to OpenGL textures
|
||||||
|
};
|
||||||
|
|
||||||
|
enum Access
|
||||||
|
{
|
||||||
|
READ_ONLY = 0x88B8,
|
||||||
|
WRITE_ONLY = 0x88B9,
|
||||||
|
READ_WRITE = 0x88BA
|
||||||
};
|
};
|
||||||
|
|
||||||
//! create empty buffer
|
//! create empty buffer
|
||||||
explicit GlBuffer(Usage usage);
|
GlBuffer();
|
||||||
|
|
||||||
|
//! create buffer from existed buffer id
|
||||||
|
GlBuffer(int arows, int acols, int atype, unsigned int abufId, bool autoRelease = false);
|
||||||
|
GlBuffer(Size asize, int atype, unsigned int abufId, bool autoRelease = false);
|
||||||
|
|
||||||
//! create buffer
|
//! create buffer
|
||||||
GlBuffer(int rows, int cols, int type, Usage usage);
|
GlBuffer(int arows, int acols, int atype, Target target = ARRAY_BUFFER, bool autoRelease = false);
|
||||||
GlBuffer(Size size, int type, Usage usage);
|
GlBuffer(Size asize, int atype, Target target = ARRAY_BUFFER, bool autoRelease = false);
|
||||||
|
|
||||||
//! copy from host/device memory
|
//! copy from host/device memory
|
||||||
GlBuffer(InputArray mat, Usage usage);
|
explicit GlBuffer(InputArray arr, Target target = ARRAY_BUFFER, bool autoRelease = false);
|
||||||
|
|
||||||
void create(int rows, int cols, int type, Usage usage);
|
//! create buffer
|
||||||
void create(Size size, int type, Usage usage);
|
void create(int arows, int acols, int atype, Target target = ARRAY_BUFFER, bool autoRelease = false);
|
||||||
void create(int rows, int cols, int type);
|
void create(Size asize, int atype, Target target = ARRAY_BUFFER, bool autoRelease = false) { create(asize.height, asize.width, atype, target, autoRelease); }
|
||||||
void create(Size size, int type);
|
|
||||||
|
|
||||||
|
//! release memory and delete buffer object
|
||||||
void release();
|
void release();
|
||||||
|
|
||||||
//! copy from host/device memory
|
//! set auto release mode (if true, release will be called in object's destructor)
|
||||||
void copyFrom(InputArray mat);
|
void setAutoRelease(bool flag);
|
||||||
|
|
||||||
void bind() const;
|
//! copy from host/device memory
|
||||||
void unbind() const;
|
void copyFrom(InputArray arr, Target target = ARRAY_BUFFER, bool autoRelease = false);
|
||||||
|
|
||||||
|
//! copy to host/device memory
|
||||||
|
void copyTo(OutputArray arr, Target target = ARRAY_BUFFER, bool autoRelease = false) const;
|
||||||
|
|
||||||
|
//! create copy of current buffer
|
||||||
|
GlBuffer clone(Target target = ARRAY_BUFFER, bool autoRelease = false) const;
|
||||||
|
|
||||||
|
//! bind buffer for specified target
|
||||||
|
void bind(Target target) const;
|
||||||
|
|
||||||
|
//! unbind any buffers from specified target
|
||||||
|
static void unbind(Target target);
|
||||||
|
|
||||||
//! map to host memory
|
//! map to host memory
|
||||||
Mat mapHost();
|
Mat mapHost(Access access);
|
||||||
void unmapHost();
|
void unmapHost();
|
||||||
|
|
||||||
//! map to device memory
|
//! map to device memory
|
||||||
gpu::GpuMat mapDevice();
|
gpu::GpuMat mapDevice();
|
||||||
void unmapDevice();
|
void unmapDevice();
|
||||||
|
|
||||||
inline int rows() const { return rows_; }
|
int rows() const { return rows_; }
|
||||||
inline int cols() const { return cols_; }
|
int cols() const { return cols_; }
|
||||||
inline Size size() const { return Size(cols_, rows_); }
|
Size size() const { return Size(cols_, rows_); }
|
||||||
inline bool empty() const { return rows_ == 0 || cols_ == 0; }
|
bool empty() const { return rows_ == 0 || cols_ == 0; }
|
||||||
|
|
||||||
inline int type() const { return type_; }
|
int type() const { return type_; }
|
||||||
inline int depth() const { return CV_MAT_DEPTH(type_); }
|
int depth() const { return CV_MAT_DEPTH(type_); }
|
||||||
inline int channels() const { return CV_MAT_CN(type_); }
|
int channels() const { return CV_MAT_CN(type_); }
|
||||||
inline int elemSize() const { return CV_ELEM_SIZE(type_); }
|
int elemSize() const { return CV_ELEM_SIZE(type_); }
|
||||||
inline int elemSize1() const { return CV_ELEM_SIZE1(type_); }
|
int elemSize1() const { return CV_ELEM_SIZE1(type_); }
|
||||||
|
|
||||||
inline Usage usage() const { return usage_; }
|
unsigned int bufId() const;
|
||||||
|
|
||||||
class Impl;
|
class Impl;
|
||||||
|
|
||||||
private:
|
private:
|
||||||
|
Ptr<Impl> impl_;
|
||||||
int rows_;
|
int rows_;
|
||||||
int cols_;
|
int cols_;
|
||||||
int type_;
|
int type_;
|
||||||
Usage usage_;
|
|
||||||
|
|
||||||
Ptr<Impl> impl_;
|
|
||||||
};
|
};
|
||||||
|
|
||||||
template <> CV_EXPORTS void Ptr<GlBuffer::Impl>::delete_obj();
|
template <> CV_EXPORTS void Ptr<GlBuffer::Impl>::delete_obj();
|
||||||
|
|
||||||
//! Smart pointer for OpenGL 2d texture memory with reference counting.
|
//! Smart pointer for OpenGL 2D texture memory with reference counting.
|
||||||
class CV_EXPORTS GlTexture
|
class CV_EXPORTS GlTexture
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
|
enum Format
|
||||||
|
{
|
||||||
|
NONE = 0,
|
||||||
|
DEPTH_COMPONENT = 0x1902, //!< Depth
|
||||||
|
RGB = 0x1907, //!< Red, Green, Blue
|
||||||
|
RGBA = 0x1908 //!< Red, Green, Blue, Alpha
|
||||||
|
};
|
||||||
|
|
||||||
//! create empty texture
|
//! create empty texture
|
||||||
GlTexture();
|
GlTexture();
|
||||||
|
|
||||||
|
//! create texture from existed texture id
|
||||||
|
GlTexture(int arows, int acols, Format aformat, unsigned int atexId, bool autoRelease = false);
|
||||||
|
GlTexture(Size asize, Format aformat, unsigned int atexId, bool autoRelease = false);
|
||||||
|
|
||||||
//! create texture
|
//! create texture
|
||||||
GlTexture(int rows, int cols, int type);
|
GlTexture(int arows, int acols, Format aformat, bool autoRelease = false);
|
||||||
GlTexture(Size size, int type);
|
GlTexture(Size asize, Format aformat, bool autoRelease = false);
|
||||||
|
|
||||||
//! copy from host/device memory
|
//! copy from host/device memory
|
||||||
explicit GlTexture(InputArray mat, bool bgra = true);
|
explicit GlTexture(InputArray arr, bool autoRelease = false);
|
||||||
|
|
||||||
void create(int rows, int cols, int type);
|
//! create texture
|
||||||
void create(Size size, int type);
|
void create(int arows, int acols, Format aformat, bool autoRelease = false);
|
||||||
|
void create(Size asize, Format aformat, bool autoRelease = false) { create(asize.height, asize.width, aformat, autoRelease); }
|
||||||
|
|
||||||
|
//! release memory and delete texture object
|
||||||
void release();
|
void release();
|
||||||
|
|
||||||
|
//! set auto release mode (if true, release will be called in object's destructor)
|
||||||
|
void setAutoRelease(bool flag);
|
||||||
|
|
||||||
//! copy from host/device memory
|
//! copy from host/device memory
|
||||||
void copyFrom(InputArray mat, bool bgra = true);
|
void copyFrom(InputArray arr, bool autoRelease = false);
|
||||||
|
|
||||||
|
//! copy to host/device memory
|
||||||
|
void copyTo(OutputArray arr, int ddepth = CV_32F, bool autoRelease = false) const;
|
||||||
|
|
||||||
|
//! bind texture to current active texture unit for GL_TEXTURE_2D target
|
||||||
void bind() const;
|
void bind() const;
|
||||||
void unbind() const;
|
|
||||||
|
|
||||||
inline int rows() const { return rows_; }
|
int rows() const { return rows_; }
|
||||||
inline int cols() const { return cols_; }
|
int cols() const { return cols_; }
|
||||||
inline Size size() const { return Size(cols_, rows_); }
|
Size size() const { return Size(cols_, rows_); }
|
||||||
inline bool empty() const { return rows_ == 0 || cols_ == 0; }
|
bool empty() const { return rows_ == 0 || cols_ == 0; }
|
||||||
|
|
||||||
inline int type() const { return type_; }
|
Format format() const { return format_; }
|
||||||
inline int depth() const { return CV_MAT_DEPTH(type_); }
|
|
||||||
inline int channels() const { return CV_MAT_CN(type_); }
|
unsigned int texId() const;
|
||||||
inline int elemSize() const { return CV_ELEM_SIZE(type_); }
|
|
||||||
inline int elemSize1() const { return CV_ELEM_SIZE1(type_); }
|
|
||||||
|
|
||||||
class Impl;
|
class Impl;
|
||||||
|
|
||||||
private:
|
private:
|
||||||
|
Ptr<Impl> impl_;
|
||||||
int rows_;
|
int rows_;
|
||||||
int cols_;
|
int cols_;
|
||||||
int type_;
|
Format format_;
|
||||||
|
|
||||||
Ptr<Impl> impl_;
|
|
||||||
GlBuffer buf_;
|
|
||||||
};
|
};
|
||||||
|
|
||||||
template <> CV_EXPORTS void Ptr<GlTexture::Impl>::delete_obj();
|
template <> CV_EXPORTS void Ptr<GlTexture::Impl>::delete_obj();
|
||||||
@ -166,83 +218,38 @@ template <> CV_EXPORTS void Ptr<GlTexture::Impl>::delete_obj();
|
|||||||
class CV_EXPORTS GlArrays
|
class CV_EXPORTS GlArrays
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
inline GlArrays()
|
GlArrays();
|
||||||
: vertex_(GlBuffer::ARRAY_BUFFER), color_(GlBuffer::ARRAY_BUFFER), bgra_(true), normal_(GlBuffer::ARRAY_BUFFER), texCoord_(GlBuffer::ARRAY_BUFFER)
|
|
||||||
{
|
|
||||||
}
|
|
||||||
|
|
||||||
void setVertexArray(InputArray vertex);
|
void setVertexArray(InputArray vertex);
|
||||||
inline void resetVertexArray() { vertex_.release(); }
|
void resetVertexArray();
|
||||||
|
|
||||||
void setColorArray(InputArray color, bool bgra = true);
|
void setColorArray(InputArray color);
|
||||||
inline void resetColorArray() { color_.release(); }
|
void resetColorArray();
|
||||||
|
|
||||||
void setNormalArray(InputArray normal);
|
void setNormalArray(InputArray normal);
|
||||||
inline void resetNormalArray() { normal_.release(); }
|
void resetNormalArray();
|
||||||
|
|
||||||
void setTexCoordArray(InputArray texCoord);
|
void setTexCoordArray(InputArray texCoord);
|
||||||
inline void resetTexCoordArray() { texCoord_.release(); }
|
void resetTexCoordArray();
|
||||||
|
|
||||||
|
void release();
|
||||||
|
|
||||||
|
void setAutoRelease(bool flag);
|
||||||
|
|
||||||
void bind() const;
|
void bind() const;
|
||||||
void unbind() const;
|
|
||||||
|
|
||||||
inline int rows() const { return vertex_.rows(); }
|
int size() const { return size_; }
|
||||||
inline int cols() const { return vertex_.cols(); }
|
bool empty() const { return size_ == 0; }
|
||||||
inline Size size() const { return vertex_.size(); }
|
|
||||||
inline bool empty() const { return vertex_.empty(); }
|
|
||||||
|
|
||||||
private:
|
private:
|
||||||
|
int size_;
|
||||||
GlBuffer vertex_;
|
GlBuffer vertex_;
|
||||||
GlBuffer color_;
|
GlBuffer color_;
|
||||||
bool bgra_;
|
|
||||||
GlBuffer normal_;
|
GlBuffer normal_;
|
||||||
GlBuffer texCoord_;
|
GlBuffer texCoord_;
|
||||||
};
|
};
|
||||||
|
|
||||||
//! OpenGL Font
|
/////////////////// Render Functions ///////////////////
|
||||||
class CV_EXPORTS GlFont
|
|
||||||
{
|
|
||||||
public:
|
|
||||||
enum Weight
|
|
||||||
{
|
|
||||||
WEIGHT_LIGHT = 300,
|
|
||||||
WEIGHT_NORMAL = 400,
|
|
||||||
WEIGHT_SEMIBOLD = 600,
|
|
||||||
WEIGHT_BOLD = 700,
|
|
||||||
WEIGHT_BLACK = 900
|
|
||||||
};
|
|
||||||
|
|
||||||
enum Style
|
|
||||||
{
|
|
||||||
STYLE_NORMAL = 0,
|
|
||||||
STYLE_ITALIC = 1,
|
|
||||||
STYLE_UNDERLINE = 2
|
|
||||||
};
|
|
||||||
|
|
||||||
static Ptr<GlFont> get(const std::string& family, int height = 12, Weight weight = WEIGHT_NORMAL, Style style = STYLE_NORMAL);
|
|
||||||
|
|
||||||
void draw(const char* str, int len) const;
|
|
||||||
|
|
||||||
inline const std::string& family() const { return family_; }
|
|
||||||
inline int height() const { return height_; }
|
|
||||||
inline Weight weight() const { return weight_; }
|
|
||||||
inline Style style() const { return style_; }
|
|
||||||
|
|
||||||
private:
|
|
||||||
GlFont(const std::string& family, int height, Weight weight, Style style);
|
|
||||||
|
|
||||||
std::string family_;
|
|
||||||
int height_;
|
|
||||||
Weight weight_;
|
|
||||||
Style style_;
|
|
||||||
|
|
||||||
unsigned int base_;
|
|
||||||
|
|
||||||
GlFont(const GlFont&);
|
|
||||||
GlFont& operator =(const GlFont&);
|
|
||||||
};
|
|
||||||
|
|
||||||
//! render functions
|
|
||||||
|
|
||||||
//! render texture rectangle in window
|
//! render texture rectangle in window
|
||||||
CV_EXPORTS void render(const GlTexture& tex,
|
CV_EXPORTS void render(const GlTexture& tex,
|
||||||
@ -267,67 +274,13 @@ namespace RenderMode {
|
|||||||
|
|
||||||
//! render OpenGL arrays
|
//! render OpenGL arrays
|
||||||
CV_EXPORTS void render(const GlArrays& arr, int mode = RenderMode::POINTS, Scalar color = Scalar::all(255));
|
CV_EXPORTS void render(const GlArrays& arr, int mode = RenderMode::POINTS, Scalar color = Scalar::all(255));
|
||||||
|
CV_EXPORTS void render(const GlArrays& arr, InputArray indices, int mode = RenderMode::POINTS, Scalar color = Scalar::all(255));
|
||||||
|
|
||||||
CV_EXPORTS void render(const std::string& str, const Ptr<GlFont>& font, Scalar color, Point2d pos);
|
namespace gpu {
|
||||||
|
|
||||||
//! 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_;
|
|
||||||
};
|
|
||||||
|
|
||||||
inline void GlBuffer::create(Size _size, int _type, Usage _usage) { create(_size.height, _size.width, _type, _usage); }
|
|
||||||
inline void GlBuffer::create(int _rows, int _cols, int _type) { create(_rows, _cols, _type, usage()); }
|
|
||||||
inline void GlBuffer::create(Size _size, int _type) { create(_size.height, _size.width, _type, usage()); }
|
|
||||||
inline void GlTexture::create(Size _size, int _type) { create(_size.height, _size.width, _type); }
|
|
||||||
|
|
||||||
namespace gpu
|
|
||||||
{
|
|
||||||
//! set a CUDA device to use OpenGL interoperability
|
//! set a CUDA device to use OpenGL interoperability
|
||||||
CV_EXPORTS void setGlDevice(int device = 0);
|
CV_EXPORTS void setGlDevice(int device = 0);
|
||||||
}
|
}
|
||||||
|
|
||||||
} // namespace cv
|
} // namespace cv
|
||||||
|
|
||||||
#endif // __cplusplus
|
#endif // __cplusplus
|
||||||
|
2718
modules/core/src/gl_core_3_1.cpp
Normal file
2718
modules/core/src/gl_core_3_1.cpp
Normal file
File diff suppressed because it is too large
Load Diff
1331
modules/core/src/gl_core_3_1.hpp
Normal file
1331
modules/core/src/gl_core_3_1.hpp
Normal file
File diff suppressed because it is too large
Load Diff
@ -925,8 +925,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 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 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 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 GlBuffer& buf) : flags(OPENGL_BUFFER), obj((void*)&buf) {}
|
||||||
_InputArray::_InputArray(const GlTexture& tex) : flags(FIXED_TYPE + FIXED_SIZE + OPENGL_TEXTURE), obj((void*)&tex) {}
|
_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) {}
|
_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
|
||||||
@ -1237,9 +1237,6 @@ int _InputArray::type(int i) const
|
|||||||
if( k == OPENGL_BUFFER )
|
if( k == OPENGL_BUFFER )
|
||||||
return ((const GlBuffer*)obj)->type();
|
return ((const GlBuffer*)obj)->type();
|
||||||
|
|
||||||
if( k == OPENGL_TEXTURE )
|
|
||||||
return ((const GlTexture*)obj)->type();
|
|
||||||
|
|
||||||
CV_Assert( k == GPU_MAT );
|
CV_Assert( k == GPU_MAT );
|
||||||
//if( k == GPU_MAT )
|
//if( k == GPU_MAT )
|
||||||
return ((const gpu::GpuMat*)obj)->type();
|
return ((const gpu::GpuMat*)obj)->type();
|
||||||
@ -1308,10 +1305,14 @@ _OutputArray::~_OutputArray() {}
|
|||||||
_OutputArray::_OutputArray(Mat& m) : _InputArray(m) {}
|
_OutputArray::_OutputArray(Mat& m) : _InputArray(m) {}
|
||||||
_OutputArray::_OutputArray(vector<Mat>& vec) : _InputArray(vec) {}
|
_OutputArray::_OutputArray(vector<Mat>& vec) : _InputArray(vec) {}
|
||||||
_OutputArray::_OutputArray(gpu::GpuMat& d_mat) : _InputArray(d_mat) {}
|
_OutputArray::_OutputArray(gpu::GpuMat& d_mat) : _InputArray(d_mat) {}
|
||||||
|
_OutputArray::_OutputArray(GlBuffer& buf) : _InputArray(buf) {}
|
||||||
|
_OutputArray::_OutputArray(GlTexture& tex) : _InputArray(tex) {}
|
||||||
|
|
||||||
_OutputArray::_OutputArray(const Mat& m) : _InputArray(m) {flags |= FIXED_SIZE|FIXED_TYPE;}
|
_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 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 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 GlTexture& tex) : _InputArray(tex) {flags |= FIXED_SIZE|FIXED_TYPE;}
|
||||||
|
|
||||||
|
|
||||||
bool _OutputArray::fixedSize() const
|
bool _OutputArray::fixedSize() const
|
||||||
@ -1341,6 +1342,13 @@ void _OutputArray::create(Size _sz, int mtype, int i, bool allowTransposed, int
|
|||||||
((gpu::GpuMat*)obj)->create(_sz, mtype);
|
((gpu::GpuMat*)obj)->create(_sz, mtype);
|
||||||
return;
|
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};
|
int sizes[] = {_sz.height, _sz.width};
|
||||||
create(2, sizes, mtype, i, allowTransposed, fixedDepthMask);
|
create(2, sizes, mtype, i, allowTransposed, fixedDepthMask);
|
||||||
}
|
}
|
||||||
@ -1362,6 +1370,13 @@ void _OutputArray::create(int rows, int cols, int mtype, int i, bool allowTransp
|
|||||||
((gpu::GpuMat*)obj)->create(rows, cols, mtype);
|
((gpu::GpuMat*)obj)->create(rows, cols, mtype);
|
||||||
return;
|
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};
|
int sizes[] = {rows, cols};
|
||||||
create(2, sizes, mtype, i, allowTransposed, fixedDepthMask);
|
create(2, sizes, mtype, i, allowTransposed, fixedDepthMask);
|
||||||
}
|
}
|
||||||
@ -1581,6 +1596,18 @@ void _OutputArray::release() const
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if( k == OPENGL_BUFFER )
|
||||||
|
{
|
||||||
|
((GlBuffer*)obj)->release();
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
if( k == OPENGL_TEXTURE )
|
||||||
|
{
|
||||||
|
((GlTexture*)obj)->release();
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
if( k == NONE )
|
if( k == NONE )
|
||||||
return;
|
return;
|
||||||
|
|
||||||
@ -1646,6 +1673,20 @@ gpu::GpuMat& _OutputArray::getGpuMatRef() const
|
|||||||
return *(gpu::GpuMat*)obj;
|
return *(gpu::GpuMat*)obj;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
GlBuffer& _OutputArray::getGlBufferRef() const
|
||||||
|
{
|
||||||
|
int k = kind();
|
||||||
|
CV_Assert( k == OPENGL_BUFFER );
|
||||||
|
return *(GlBuffer*)obj;
|
||||||
|
}
|
||||||
|
|
||||||
|
GlTexture& _OutputArray::getGlTextureRef() const
|
||||||
|
{
|
||||||
|
int k = kind();
|
||||||
|
CV_Assert( k == OPENGL_TEXTURE );
|
||||||
|
return *(GlTexture*)obj;
|
||||||
|
}
|
||||||
|
|
||||||
static _OutputArray _none;
|
static _OutputArray _none;
|
||||||
OutputArray noArray() { return _none; }
|
OutputArray noArray() { return _none; }
|
||||||
|
|
||||||
|
File diff suppressed because it is too large
Load Diff
508
modules/gpu/test/test_opengl.cpp
Normal file
508
modules/gpu/test/test_opengl.cpp
Normal file
@ -0,0 +1,508 @@
|
|||||||
|
/*M///////////////////////////////////////////////////////////////////////////////////////
|
||||||
|
//
|
||||||
|
// IMPORTANT: READ BEFORE DOWNLOADING, COPYING, INSTALLING OR USING.
|
||||||
|
//
|
||||||
|
// By downloading, copying, installing or using the software you agree to this license.
|
||||||
|
// If you do not agree to this license, do not download, install,
|
||||||
|
// copy or use the software.
|
||||||
|
//
|
||||||
|
//
|
||||||
|
// Intel License Agreement
|
||||||
|
// For Open Source Computer Vision Library
|
||||||
|
//
|
||||||
|
// Copyright (C) 2000, Intel Corporation, all rights reserved.
|
||||||
|
// Third party copyrights are property of their respective owners.
|
||||||
|
//
|
||||||
|
// Redistribution and use in source and binary forms, with or without modification,
|
||||||
|
// are permitted provided that the following conditions are met:
|
||||||
|
//
|
||||||
|
// * Redistribution's of source code must retain the above copyright notice,
|
||||||
|
// this list of conditions and the following disclaimer.
|
||||||
|
//
|
||||||
|
// * Redistribution's in binary form must reproduce the above copyright notice,
|
||||||
|
// this list of conditions and the following disclaimer in the documentation
|
||||||
|
// and/or other materials provided with the distribution.
|
||||||
|
//
|
||||||
|
// * The name of Intel Corporation may not be used to endorse or promote products
|
||||||
|
// derived from this software without specific prior written permission.
|
||||||
|
//
|
||||||
|
// This software is provided by the copyright holders and contributors "as is" and
|
||||||
|
// any express or implied warranties, including, but not limited to, the implied
|
||||||
|
// warranties of merchantability and fitness for a particular purpose are disclaimed.
|
||||||
|
// In no event shall the Intel Corporation or contributors be liable for any direct,
|
||||||
|
// indirect, incidental, special, exemplary, or consequential damages
|
||||||
|
// (including, but not limited to, procurement of substitute goods or services;
|
||||||
|
// loss of use, data, or profits; or business interruption) however caused
|
||||||
|
// and on any theory of liability, whether in contract, strict liability,
|
||||||
|
// or tort (including negligence or otherwise) arising in any way out of
|
||||||
|
// the use of this software, even if advised of the possibility of such damage.
|
||||||
|
//
|
||||||
|
//M*/
|
||||||
|
|
||||||
|
#include "test_precomp.hpp"
|
||||||
|
|
||||||
|
#if defined(HAVE_CUDA) && defined(HAVE_OPENGL)
|
||||||
|
|
||||||
|
/////////////////////////////////////////////
|
||||||
|
// GlBuffer
|
||||||
|
|
||||||
|
PARAM_TEST_CASE(GlBuffer, cv::Size, MatType)
|
||||||
|
{
|
||||||
|
static void SetUpTestCase()
|
||||||
|
{
|
||||||
|
cv::namedWindow("test", cv::WINDOW_OPENGL);
|
||||||
|
}
|
||||||
|
|
||||||
|
static void TearDownTestCase()
|
||||||
|
{
|
||||||
|
cv::destroyAllWindows();
|
||||||
|
}
|
||||||
|
|
||||||
|
cv::Size size;
|
||||||
|
int type;
|
||||||
|
|
||||||
|
virtual void SetUp()
|
||||||
|
{
|
||||||
|
size = GET_PARAM(0);
|
||||||
|
type = GET_PARAM(1);
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
GPU_TEST_P(GlBuffer, Constructor1)
|
||||||
|
{
|
||||||
|
cv::GlBuffer buf(size.height, size.width, type, cv::GlBuffer::ARRAY_BUFFER, true);
|
||||||
|
|
||||||
|
EXPECT_EQ(size.height, buf.rows());
|
||||||
|
EXPECT_EQ(size.width, buf.cols());
|
||||||
|
EXPECT_EQ(type, buf.type());
|
||||||
|
}
|
||||||
|
|
||||||
|
GPU_TEST_P(GlBuffer, Constructor2)
|
||||||
|
{
|
||||||
|
cv::GlBuffer buf(size, type, cv::GlBuffer::ARRAY_BUFFER, true);
|
||||||
|
|
||||||
|
EXPECT_EQ(size.height, buf.rows());
|
||||||
|
EXPECT_EQ(size.width, buf.cols());
|
||||||
|
EXPECT_EQ(type, buf.type());
|
||||||
|
}
|
||||||
|
|
||||||
|
GPU_TEST_P(GlBuffer, ConstructorFromMat)
|
||||||
|
{
|
||||||
|
cv::Mat gold = randomMat(size, type);
|
||||||
|
|
||||||
|
cv::GlBuffer buf(gold, cv::GlBuffer::ARRAY_BUFFER, true);
|
||||||
|
|
||||||
|
cv::Mat bufData;
|
||||||
|
buf.copyTo(bufData);
|
||||||
|
|
||||||
|
EXPECT_MAT_NEAR(gold, bufData, 0);
|
||||||
|
}
|
||||||
|
|
||||||
|
GPU_TEST_P(GlBuffer, ConstructorFromGpuMat)
|
||||||
|
{
|
||||||
|
cv::Mat gold = randomMat(size, type);
|
||||||
|
cv::gpu::GpuMat d_gold(gold);
|
||||||
|
|
||||||
|
cv::GlBuffer buf(d_gold, cv::GlBuffer::ARRAY_BUFFER);
|
||||||
|
|
||||||
|
cv::Mat bufData;
|
||||||
|
buf.copyTo(bufData);
|
||||||
|
|
||||||
|
EXPECT_MAT_NEAR(gold, bufData, 0);
|
||||||
|
}
|
||||||
|
|
||||||
|
GPU_TEST_P(GlBuffer, ConstructorFromGlBuffer)
|
||||||
|
{
|
||||||
|
cv::GlBuffer buf_gold(size, type, cv::GlBuffer::ARRAY_BUFFER, true);
|
||||||
|
|
||||||
|
cv::GlBuffer buf(buf_gold);
|
||||||
|
|
||||||
|
EXPECT_EQ(buf_gold.bufId(), buf.bufId());
|
||||||
|
EXPECT_EQ(buf_gold.rows(), buf.rows());
|
||||||
|
EXPECT_EQ(buf_gold.cols(), buf.cols());
|
||||||
|
EXPECT_EQ(buf_gold.type(), buf.type());
|
||||||
|
}
|
||||||
|
|
||||||
|
GPU_TEST_P(GlBuffer, ConstructorFromGlTexture)
|
||||||
|
{
|
||||||
|
const int depth = CV_MAT_DEPTH(type);
|
||||||
|
const int cn = CV_MAT_CN(type);
|
||||||
|
|
||||||
|
if (depth != CV_32F || cn == 2)
|
||||||
|
return;
|
||||||
|
|
||||||
|
cv::Mat gold = randomMat(size, type, 0, 1.0);
|
||||||
|
cv::GlTexture tex_gold(gold, true);
|
||||||
|
|
||||||
|
cv::GlBuffer buf(tex_gold, cv::GlBuffer::PIXEL_PACK_BUFFER, true);
|
||||||
|
|
||||||
|
cv::Mat bufData;
|
||||||
|
buf.copyTo(bufData);
|
||||||
|
|
||||||
|
EXPECT_MAT_NEAR(gold, bufData, 1e-2);
|
||||||
|
}
|
||||||
|
|
||||||
|
GPU_TEST_P(GlBuffer, Create)
|
||||||
|
{
|
||||||
|
cv::GlBuffer buf;
|
||||||
|
buf.create(size.height, size.width, type, cv::GlBuffer::ARRAY_BUFFER, true);
|
||||||
|
|
||||||
|
EXPECT_EQ(size.height, buf.rows());
|
||||||
|
EXPECT_EQ(size.width, buf.cols());
|
||||||
|
EXPECT_EQ(type, buf.type());
|
||||||
|
}
|
||||||
|
|
||||||
|
GPU_TEST_P(GlBuffer, CopyFromMat)
|
||||||
|
{
|
||||||
|
cv::Mat gold = randomMat(size, type);
|
||||||
|
|
||||||
|
cv::GlBuffer buf;
|
||||||
|
buf.copyFrom(gold, cv::GlBuffer::ARRAY_BUFFER, true);
|
||||||
|
|
||||||
|
cv::Mat bufData;
|
||||||
|
buf.copyTo(bufData);
|
||||||
|
|
||||||
|
EXPECT_MAT_NEAR(gold, bufData, 0);
|
||||||
|
}
|
||||||
|
|
||||||
|
GPU_TEST_P(GlBuffer, CopyFromGpuMat)
|
||||||
|
{
|
||||||
|
cv::Mat gold = randomMat(size, type);
|
||||||
|
cv::gpu::GpuMat d_gold(gold);
|
||||||
|
|
||||||
|
cv::GlBuffer buf;
|
||||||
|
buf.copyFrom(d_gold, cv::GlBuffer::ARRAY_BUFFER, true);
|
||||||
|
|
||||||
|
cv::Mat bufData;
|
||||||
|
buf.copyTo(bufData);
|
||||||
|
|
||||||
|
EXPECT_MAT_NEAR(gold, bufData, 0);
|
||||||
|
}
|
||||||
|
|
||||||
|
GPU_TEST_P(GlBuffer, CopyFromGlBuffer)
|
||||||
|
{
|
||||||
|
cv::Mat gold = randomMat(size, type);
|
||||||
|
cv::GlBuffer buf_gold(gold, cv::GlBuffer::ARRAY_BUFFER, true);
|
||||||
|
|
||||||
|
cv::GlBuffer buf;
|
||||||
|
buf.copyFrom(buf_gold, cv::GlBuffer::ARRAY_BUFFER, true);
|
||||||
|
|
||||||
|
EXPECT_NE(buf_gold.bufId(), buf.bufId());
|
||||||
|
|
||||||
|
cv::Mat bufData;
|
||||||
|
buf.copyTo(bufData);
|
||||||
|
|
||||||
|
EXPECT_MAT_NEAR(gold, bufData, 0);
|
||||||
|
}
|
||||||
|
|
||||||
|
GPU_TEST_P(GlBuffer, CopyFromGlTexture)
|
||||||
|
{
|
||||||
|
const int depth = CV_MAT_DEPTH(type);
|
||||||
|
const int cn = CV_MAT_CN(type);
|
||||||
|
|
||||||
|
if (depth != CV_32F || cn == 2)
|
||||||
|
return;
|
||||||
|
|
||||||
|
cv::Mat gold = randomMat(size, type, 0, 1.0);
|
||||||
|
cv::GlTexture tex_gold(gold, true);
|
||||||
|
|
||||||
|
cv::GlBuffer buf;
|
||||||
|
buf.copyFrom(tex_gold, cv::GlBuffer::ARRAY_BUFFER, true);
|
||||||
|
|
||||||
|
cv::Mat bufData;
|
||||||
|
buf.copyTo(bufData);
|
||||||
|
|
||||||
|
EXPECT_MAT_NEAR(gold, bufData, 1e-2);
|
||||||
|
}
|
||||||
|
|
||||||
|
GPU_TEST_P(GlBuffer, CopyToGpuMat)
|
||||||
|
{
|
||||||
|
cv::Mat gold = randomMat(size, type);
|
||||||
|
|
||||||
|
cv::GlBuffer buf(gold, cv::GlBuffer::ARRAY_BUFFER, true);
|
||||||
|
|
||||||
|
cv::gpu::GpuMat dst;
|
||||||
|
buf.copyTo(dst);
|
||||||
|
|
||||||
|
EXPECT_MAT_NEAR(gold, dst, 0);
|
||||||
|
}
|
||||||
|
|
||||||
|
GPU_TEST_P(GlBuffer, CopyToGlBuffer)
|
||||||
|
{
|
||||||
|
cv::Mat gold = randomMat(size, type);
|
||||||
|
|
||||||
|
cv::GlBuffer buf(gold, cv::GlBuffer::ARRAY_BUFFER, true);
|
||||||
|
|
||||||
|
cv::GlBuffer dst;
|
||||||
|
buf.copyTo(dst, cv::GlBuffer::ARRAY_BUFFER, true);
|
||||||
|
|
||||||
|
EXPECT_NE(buf.bufId(), dst.bufId());
|
||||||
|
|
||||||
|
cv::Mat bufData;
|
||||||
|
dst.copyTo(bufData);
|
||||||
|
|
||||||
|
EXPECT_MAT_NEAR(gold, bufData, 0);
|
||||||
|
}
|
||||||
|
|
||||||
|
GPU_TEST_P(GlBuffer, CopyToGlTexture)
|
||||||
|
{
|
||||||
|
const int depth = CV_MAT_DEPTH(type);
|
||||||
|
const int cn = CV_MAT_CN(type);
|
||||||
|
|
||||||
|
if (depth != CV_32F || cn == 2)
|
||||||
|
return;
|
||||||
|
|
||||||
|
cv::Mat gold = randomMat(size, type, 0, 1.0);
|
||||||
|
|
||||||
|
cv::GlBuffer buf(gold, cv::GlBuffer::PIXEL_PACK_BUFFER, true);
|
||||||
|
|
||||||
|
cv::GlTexture tex;
|
||||||
|
buf.copyTo(tex, cv::GlBuffer::PIXEL_PACK_BUFFER, true);
|
||||||
|
|
||||||
|
cv::Mat texData;
|
||||||
|
tex.copyTo(texData);
|
||||||
|
|
||||||
|
EXPECT_MAT_NEAR(gold, texData, 1e-2);
|
||||||
|
}
|
||||||
|
|
||||||
|
GPU_TEST_P(GlBuffer, Clone)
|
||||||
|
{
|
||||||
|
cv::Mat gold = randomMat(size, type);
|
||||||
|
|
||||||
|
cv::GlBuffer buf(gold, cv::GlBuffer::ARRAY_BUFFER, true);
|
||||||
|
|
||||||
|
cv::GlBuffer dst = buf.clone(cv::GlBuffer::ARRAY_BUFFER, true);
|
||||||
|
|
||||||
|
EXPECT_NE(buf.bufId(), dst.bufId());
|
||||||
|
|
||||||
|
cv::Mat bufData;
|
||||||
|
dst.copyTo(bufData);
|
||||||
|
|
||||||
|
EXPECT_MAT_NEAR(gold, bufData, 0);
|
||||||
|
}
|
||||||
|
|
||||||
|
GPU_TEST_P(GlBuffer, MapHostRead)
|
||||||
|
{
|
||||||
|
cv::Mat gold = randomMat(size, type);
|
||||||
|
|
||||||
|
cv::GlBuffer buf(gold, cv::GlBuffer::ARRAY_BUFFER, true);
|
||||||
|
|
||||||
|
cv::Mat dst = buf.mapHost(cv::GlBuffer::READ_ONLY);
|
||||||
|
|
||||||
|
EXPECT_MAT_NEAR(gold, dst, 0);
|
||||||
|
|
||||||
|
buf.unmapHost();
|
||||||
|
}
|
||||||
|
|
||||||
|
GPU_TEST_P(GlBuffer, MapHostWrite)
|
||||||
|
{
|
||||||
|
cv::Mat gold = randomMat(size, type);
|
||||||
|
|
||||||
|
cv::GlBuffer buf(size, type, cv::GlBuffer::ARRAY_BUFFER, true);
|
||||||
|
|
||||||
|
cv::Mat dst = buf.mapHost(cv::GlBuffer::WRITE_ONLY);
|
||||||
|
gold.copyTo(dst);
|
||||||
|
buf.unmapHost();
|
||||||
|
dst.release();
|
||||||
|
|
||||||
|
cv::Mat bufData;
|
||||||
|
buf.copyTo(bufData);
|
||||||
|
|
||||||
|
EXPECT_MAT_NEAR(gold, bufData, 0);
|
||||||
|
}
|
||||||
|
|
||||||
|
GPU_TEST_P(GlBuffer, MapDevice)
|
||||||
|
{
|
||||||
|
cv::Mat gold = randomMat(size, type);
|
||||||
|
|
||||||
|
cv::GlBuffer buf(gold, cv::GlBuffer::ARRAY_BUFFER, true);
|
||||||
|
|
||||||
|
cv::gpu::GpuMat dst = buf.mapDevice();
|
||||||
|
|
||||||
|
EXPECT_MAT_NEAR(gold, dst, 0);
|
||||||
|
|
||||||
|
buf.unmapDevice();
|
||||||
|
}
|
||||||
|
|
||||||
|
INSTANTIATE_TEST_CASE_P(OpenGL, GlBuffer, testing::Combine(DIFFERENT_SIZES, ALL_TYPES));
|
||||||
|
|
||||||
|
/////////////////////////////////////////////
|
||||||
|
// GlTexture
|
||||||
|
|
||||||
|
PARAM_TEST_CASE(GlTexture, cv::Size, MatType)
|
||||||
|
{
|
||||||
|
static void SetUpTestCase()
|
||||||
|
{
|
||||||
|
cv::namedWindow("test", cv::WINDOW_OPENGL);
|
||||||
|
}
|
||||||
|
|
||||||
|
static void TearDownTestCase()
|
||||||
|
{
|
||||||
|
cv::destroyAllWindows();
|
||||||
|
}
|
||||||
|
|
||||||
|
cv::Size size;
|
||||||
|
int type;
|
||||||
|
int depth;
|
||||||
|
int cn;
|
||||||
|
cv::GlTexture::Format format;
|
||||||
|
|
||||||
|
virtual void SetUp()
|
||||||
|
{
|
||||||
|
size = GET_PARAM(0);
|
||||||
|
type = GET_PARAM(1);
|
||||||
|
|
||||||
|
depth = CV_MAT_DEPTH(type);
|
||||||
|
cn = CV_MAT_CN(type);
|
||||||
|
format = cn == 1 ? cv::GlTexture::DEPTH_COMPONENT : cn == 3 ? cv::GlTexture::RGB : cn == 4 ? cv::GlTexture::RGBA : cv::GlTexture::NONE;
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
GPU_TEST_P(GlTexture, Constructor1)
|
||||||
|
{
|
||||||
|
cv::GlTexture tex(size.height, size.width, format, true);
|
||||||
|
|
||||||
|
EXPECT_EQ(size.height, tex.rows());
|
||||||
|
EXPECT_EQ(size.width, tex.cols());
|
||||||
|
EXPECT_EQ(format, tex.format());
|
||||||
|
}
|
||||||
|
|
||||||
|
GPU_TEST_P(GlTexture, Constructor2)
|
||||||
|
{
|
||||||
|
cv::GlTexture tex(size, format, true);
|
||||||
|
|
||||||
|
EXPECT_EQ(size.height, tex.rows());
|
||||||
|
EXPECT_EQ(size.width, tex.cols());
|
||||||
|
EXPECT_EQ(format, tex.format());
|
||||||
|
}
|
||||||
|
|
||||||
|
GPU_TEST_P(GlTexture, ConstructorFromMat)
|
||||||
|
{
|
||||||
|
cv::Mat gold = randomMat(size, type, 0, depth == CV_8U ? 255 : 1);
|
||||||
|
|
||||||
|
cv::GlTexture tex(gold, true);
|
||||||
|
|
||||||
|
cv::Mat texData;
|
||||||
|
tex.copyTo(texData, depth);
|
||||||
|
|
||||||
|
EXPECT_MAT_NEAR(gold, texData, 1e-2);
|
||||||
|
}
|
||||||
|
|
||||||
|
GPU_TEST_P(GlTexture, ConstructorFromGpuMat)
|
||||||
|
{
|
||||||
|
cv::Mat gold = randomMat(size, type, 0, depth == CV_8U ? 255 : 1);
|
||||||
|
cv::gpu::GpuMat d_gold(gold);
|
||||||
|
|
||||||
|
cv::GlTexture tex(d_gold, true);
|
||||||
|
|
||||||
|
cv::Mat texData;
|
||||||
|
tex.copyTo(texData, depth);
|
||||||
|
|
||||||
|
EXPECT_MAT_NEAR(gold, texData, 1e-2);
|
||||||
|
}
|
||||||
|
|
||||||
|
GPU_TEST_P(GlTexture, ConstructorFromGlBuffer)
|
||||||
|
{
|
||||||
|
cv::Mat gold = randomMat(size, type, 0, depth == CV_8U ? 255 : 1);
|
||||||
|
cv::GlBuffer buf_gold(gold, cv::GlBuffer::PIXEL_UNPACK_BUFFER, true);
|
||||||
|
|
||||||
|
cv::GlTexture tex(buf_gold, true);
|
||||||
|
|
||||||
|
cv::Mat texData;
|
||||||
|
tex.copyTo(texData, depth);
|
||||||
|
|
||||||
|
EXPECT_MAT_NEAR(gold, texData, 1e-2);
|
||||||
|
}
|
||||||
|
|
||||||
|
GPU_TEST_P(GlTexture, ConstructorFromGlTexture)
|
||||||
|
{
|
||||||
|
cv::GlTexture tex_gold(size, format, true);
|
||||||
|
cv::GlTexture tex(tex_gold);
|
||||||
|
|
||||||
|
EXPECT_EQ(tex_gold.texId(), tex.texId());
|
||||||
|
EXPECT_EQ(tex_gold.rows(), tex.rows());
|
||||||
|
EXPECT_EQ(tex_gold.cols(), tex.cols());
|
||||||
|
EXPECT_EQ(tex_gold.format(), tex.format());
|
||||||
|
}
|
||||||
|
|
||||||
|
GPU_TEST_P(GlTexture, Create)
|
||||||
|
{
|
||||||
|
cv::GlTexture tex;
|
||||||
|
tex.create(size.height, size.width, format, true);
|
||||||
|
|
||||||
|
EXPECT_EQ(size.height, tex.rows());
|
||||||
|
EXPECT_EQ(size.width, tex.cols());
|
||||||
|
EXPECT_EQ(format, tex.format());
|
||||||
|
}
|
||||||
|
|
||||||
|
GPU_TEST_P(GlTexture, CopyFromMat)
|
||||||
|
{
|
||||||
|
cv::Mat gold = randomMat(size, type, 0, depth == CV_8U ? 255 : 1);
|
||||||
|
|
||||||
|
cv::GlTexture tex;
|
||||||
|
tex.copyFrom(gold, true);
|
||||||
|
|
||||||
|
cv::Mat texData;
|
||||||
|
tex.copyTo(texData, depth);
|
||||||
|
|
||||||
|
EXPECT_MAT_NEAR(gold, texData, 1e-2);
|
||||||
|
}
|
||||||
|
|
||||||
|
GPU_TEST_P(GlTexture, CopyFromGpuMat)
|
||||||
|
{
|
||||||
|
cv::Mat gold = randomMat(size, type, 0, depth == CV_8U ? 255 : 1);
|
||||||
|
cv::gpu::GpuMat d_gold(gold);
|
||||||
|
|
||||||
|
cv::GlTexture tex;
|
||||||
|
tex.copyFrom(d_gold, true);
|
||||||
|
|
||||||
|
cv::Mat texData;
|
||||||
|
tex.copyTo(texData, depth);
|
||||||
|
|
||||||
|
EXPECT_MAT_NEAR(gold, texData, 1e-2);
|
||||||
|
}
|
||||||
|
|
||||||
|
GPU_TEST_P(GlTexture, CopyFromGlBuffer)
|
||||||
|
{
|
||||||
|
cv::Mat gold = randomMat(size, type, 0, depth == CV_8U ? 255 : 1);
|
||||||
|
cv::GlBuffer buf_gold(gold, cv::GlBuffer::PIXEL_UNPACK_BUFFER, true);
|
||||||
|
|
||||||
|
cv::GlTexture tex;
|
||||||
|
tex.copyFrom(buf_gold, true);
|
||||||
|
|
||||||
|
cv::Mat texData;
|
||||||
|
tex.copyTo(texData, depth);
|
||||||
|
|
||||||
|
EXPECT_MAT_NEAR(gold, texData, 1e-2);
|
||||||
|
}
|
||||||
|
|
||||||
|
GPU_TEST_P(GlTexture, CopyToGpuMat)
|
||||||
|
{
|
||||||
|
cv::Mat gold = randomMat(size, type, 0, depth == CV_8U ? 255 : 1);
|
||||||
|
|
||||||
|
cv::GlTexture tex(gold, true);
|
||||||
|
|
||||||
|
cv::gpu::GpuMat dst;
|
||||||
|
tex.copyTo(dst, depth);
|
||||||
|
|
||||||
|
EXPECT_MAT_NEAR(gold, dst, 1e-2);
|
||||||
|
}
|
||||||
|
|
||||||
|
GPU_TEST_P(GlTexture, CopyToGlBuffer)
|
||||||
|
{
|
||||||
|
cv::Mat gold = randomMat(size, type, 0, depth == CV_8U ? 255 : 1);
|
||||||
|
|
||||||
|
cv::GlTexture tex(gold, true);
|
||||||
|
|
||||||
|
cv::GlBuffer dst;
|
||||||
|
tex.copyTo(dst, depth, true);
|
||||||
|
|
||||||
|
cv::Mat bufData;
|
||||||
|
dst.copyTo(bufData);
|
||||||
|
|
||||||
|
EXPECT_MAT_NEAR(gold, bufData, 1e-2);
|
||||||
|
}
|
||||||
|
|
||||||
|
INSTANTIATE_TEST_CASE_P(OpenGL, GlTexture, testing::Combine(DIFFERENT_SIZES, testing::Values(CV_8UC1, CV_8UC3, CV_8UC4, CV_32FC1, CV_32FC3, CV_32FC4)));
|
||||||
|
|
||||||
|
#endif
|
@ -70,6 +70,7 @@
|
|||||||
#include <cuda_runtime.h>
|
#include <cuda_runtime.h>
|
||||||
|
|
||||||
#include "opencv2/core/core.hpp"
|
#include "opencv2/core/core.hpp"
|
||||||
|
#include "opencv2/core/opengl_interop.hpp"
|
||||||
#include "opencv2/highgui/highgui.hpp"
|
#include "opencv2/highgui/highgui.hpp"
|
||||||
#include "opencv2/calib3d/calib3d.hpp"
|
#include "opencv2/calib3d/calib3d.hpp"
|
||||||
#include "opencv2/imgproc/imgproc.hpp"
|
#include "opencv2/imgproc/imgproc.hpp"
|
||||||
|
@ -125,16 +125,13 @@ CV_EXPORTS_W void setTrackbarPos(const string& trackbarname, const string& winna
|
|||||||
|
|
||||||
// OpenGL support
|
// 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 setOpenGlDrawCallback(const string& winname, OpenGlDrawCallback onOpenGlDraw, void* userdata = 0);
|
||||||
|
|
||||||
CV_EXPORTS void setOpenGlContext(const string& winname);
|
CV_EXPORTS void setOpenGlContext(const string& winname);
|
||||||
|
|
||||||
CV_EXPORTS void updateWindow(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
|
//Only for Qt
|
||||||
|
|
||||||
CV_EXPORTS CvFont fontQt(const string& nameFont, int pointSize=-1,
|
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);
|
double cvGetOpenGlProp_QT(const char* name);
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
// OpenGL
|
|
||||||
typedef void (CV_CDECL *CvOpenGlCleanCallback)(void* userdata);
|
|
||||||
void icvSetOpenGlCleanCallback(const char* window_name, CvOpenGlCleanCallback callback, void* userdata);
|
|
||||||
|
|
||||||
|
|
||||||
/*namespace cv
|
/*namespace cv
|
||||||
|
@ -40,6 +40,7 @@
|
|||||||
//M*/
|
//M*/
|
||||||
|
|
||||||
#include "precomp.hpp"
|
#include "precomp.hpp"
|
||||||
|
#include <map>
|
||||||
#include "opencv2/core/opengl_interop.hpp"
|
#include "opencv2/core/opengl_interop.hpp"
|
||||||
|
|
||||||
// in later times, use this file as a dispatcher to implementations like cvcap.cpp
|
// 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
|
#ifdef HAVE_OPENGL
|
||||||
namespace
|
namespace
|
||||||
{
|
{
|
||||||
const int CV_TEXTURE_MAGIC_VAL = 0x00287653;
|
std::map<std::string, cv::GlTexture> wndTexs;
|
||||||
const int CV_POINT_CLOUD_MAGIC_VAL = 0x00287654;
|
std::map<std::string, cv::GlTexture> ownWndTexs;
|
||||||
|
std::map<std::string, cv::GlBuffer> ownWndBufs;
|
||||||
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;
|
|
||||||
};
|
|
||||||
|
|
||||||
void CV_CDECL glDrawTextureCallback(void* userdata)
|
void CV_CDECL glDrawTextureCallback(void* userdata)
|
||||||
{
|
{
|
||||||
GlObjTex* texObj = static_cast<GlObjTex*>(userdata);
|
cv::GlTexture* texObj = static_cast<cv::GlTexture*>(userdata);
|
||||||
|
|
||||||
CV_DbgAssert(texObj->flag == CV_TEXTURE_MAGIC_VAL);
|
cv::render(*texObj);
|
||||||
|
|
||||||
static cv::GlCamera glCamera;
|
|
||||||
|
|
||||||
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);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
#endif // HAVE_OPENGL
|
#endif // HAVE_OPENGL
|
||||||
@ -339,7 +261,8 @@ void cv::imshow( const string& winname, InputArray _img )
|
|||||||
CvMat c_img = img;
|
CvMat c_img = img;
|
||||||
cvShowImage(winname.c_str(), &c_img);
|
cvShowImage(winname.c_str(), &c_img);
|
||||||
#else
|
#else
|
||||||
double useGl = getWindowProperty(winname, WND_PROP_OPENGL);
|
const double useGl = getWindowProperty(winname, WND_PROP_OPENGL);
|
||||||
|
|
||||||
if (useGl <= 0)
|
if (useGl <= 0)
|
||||||
{
|
{
|
||||||
Mat img = _img.getMat();
|
Mat img = _img.getMat();
|
||||||
@ -348,7 +271,7 @@ void cv::imshow( const string& winname, InputArray _img )
|
|||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
double autoSize = getWindowProperty(winname, WND_PROP_AUTOSIZE);
|
const double autoSize = getWindowProperty(winname, WND_PROP_AUTOSIZE);
|
||||||
|
|
||||||
if (autoSize > 0)
|
if (autoSize > 0)
|
||||||
{
|
{
|
||||||
@ -358,145 +281,44 @@ void cv::imshow( const string& winname, InputArray _img )
|
|||||||
|
|
||||||
setOpenGlContext(winname);
|
setOpenGlContext(winname);
|
||||||
|
|
||||||
GlObjBase* glObj = findGlObjByName(winname);
|
if (_img.kind() == _InputArray::OPENGL_TEXTURE)
|
||||||
|
|
||||||
if (glObj && glObj->flag != CV_TEXTURE_MAGIC_VAL)
|
|
||||||
{
|
{
|
||||||
icvSetOpenGlCleanCallback(winname.c_str(), 0, 0);
|
cv::GlTexture& tex = wndTexs[winname];
|
||||||
glObj = 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (glObj)
|
tex = _img.getGlTexture();
|
||||||
{
|
|
||||||
GlObjTex* texObj = static_cast<GlObjTex*>(glObj);
|
tex.setAutoRelease(false);
|
||||||
texObj->tex.copyFrom(_img);
|
|
||||||
|
setOpenGlDrawCallback(winname, glDrawTextureCallback, &tex);
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
GlObjTex* texObj = new GlObjTex;
|
cv::GlTexture& tex = ownWndTexs[winname];
|
||||||
texObj->tex.copyFrom(_img);
|
|
||||||
|
|
||||||
glObj = texObj;
|
if (_img.kind() == _InputArray::GPU_MAT)
|
||||||
glObj->flag = CV_TEXTURE_MAGIC_VAL;
|
{
|
||||||
glObj->winname = winname;
|
cv::GlBuffer& buf = ownWndBufs[winname];
|
||||||
|
buf.copyFrom(_img);
|
||||||
|
buf.setAutoRelease(false);
|
||||||
|
|
||||||
addGlObj(glObj);
|
tex.copyFrom(buf);
|
||||||
|
tex.setAutoRelease(false);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
tex.copyFrom(_img);
|
||||||
|
}
|
||||||
|
|
||||||
icvSetOpenGlCleanCallback(winname.c_str(), glCleanCallback, glObj);
|
tex.setAutoRelease(false);
|
||||||
|
|
||||||
|
setOpenGlDrawCallback(winname, glDrawTextureCallback, &tex);
|
||||||
}
|
}
|
||||||
|
|
||||||
setOpenGlDrawCallback(winname, glDrawTextureCallback, glObj);
|
|
||||||
|
|
||||||
updateWindow(winname);
|
updateWindow(winname);
|
||||||
}
|
}
|
||||||
#endif
|
#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;
|
|
||||||
|
|
||||||
pointCloudObj->arr.setVertexArray(points);
|
|
||||||
if (!colors.empty())
|
|
||||||
pointCloudObj->arr.setColorArray(colors);
|
|
||||||
|
|
||||||
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
|
|
||||||
}
|
|
||||||
|
|
||||||
// Without OpenGL
|
// Without OpenGL
|
||||||
|
|
||||||
#ifndef HAVE_OPENGL
|
#ifndef HAVE_OPENGL
|
||||||
@ -516,11 +338,6 @@ CV_IMPL void cvUpdateWindow(const char*)
|
|||||||
CV_Error(CV_OpenGlNotSupported, "The library is compiled without OpenGL support");
|
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
|
#endif // !HAVE_OPENGL
|
||||||
|
|
||||||
#if defined (HAVE_QT)
|
#if defined (HAVE_QT)
|
||||||
|
@ -685,20 +685,6 @@ CV_IMPL void cvSetOpenGlDrawCallback(const char* window_name, CvOpenGlDrawCallba
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
void icvSetOpenGlCleanCallback(const char* window_name, CvOpenGlCleanCallback callback, void* userdata)
|
|
||||||
{
|
|
||||||
if (!guiMainThread)
|
|
||||||
CV_Error( CV_StsNullPtr, "NULL guiReceiver (please create a window)" );
|
|
||||||
|
|
||||||
QMetaObject::invokeMethod(guiMainThread,
|
|
||||||
"setOpenGlCleanCallback",
|
|
||||||
Qt::AutoConnection,
|
|
||||||
Q_ARG(QString, QString(window_name)),
|
|
||||||
Q_ARG(void*, (void*)callback),
|
|
||||||
Q_ARG(void*, userdata));
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
CV_IMPL void cvSetOpenGlContext(const char* window_name)
|
CV_IMPL void cvSetOpenGlContext(const char* window_name)
|
||||||
{
|
{
|
||||||
if (!guiMainThread)
|
if (!guiMainThread)
|
||||||
@ -1175,14 +1161,6 @@ void GuiReceiver::setOpenGlDrawCallback(QString name, void* callback, void* user
|
|||||||
w->setOpenGlDrawCallback((CvOpenGlDrawCallback) callback, userdata);
|
w->setOpenGlDrawCallback((CvOpenGlDrawCallback) callback, userdata);
|
||||||
}
|
}
|
||||||
|
|
||||||
void GuiReceiver::setOpenGlCleanCallback(QString name, void* callback, void* userdata)
|
|
||||||
{
|
|
||||||
QPointer<CvWindow> w = icvFindWindowByName(name);
|
|
||||||
|
|
||||||
if (w)
|
|
||||||
w->setOpenGlCleanCallback((CvOpenGlCleanCallback) callback, userdata);
|
|
||||||
}
|
|
||||||
|
|
||||||
void GuiReceiver::setOpenGlContext(QString name)
|
void GuiReceiver::setOpenGlContext(QString name)
|
||||||
{
|
{
|
||||||
QPointer<CvWindow> w = icvFindWindowByName(name);
|
QPointer<CvWindow> w = icvFindWindowByName(name);
|
||||||
@ -1828,12 +1806,6 @@ void CvWindow::setOpenGlDrawCallback(CvOpenGlDrawCallback callback, void* userda
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
void CvWindow::setOpenGlCleanCallback(CvOpenGlCleanCallback callback, void* userdata)
|
|
||||||
{
|
|
||||||
myView->setOpenGlCleanCallback(callback, userdata);
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
void CvWindow::makeCurrentOpenGlContext()
|
void CvWindow::makeCurrentOpenGlContext()
|
||||||
{
|
{
|
||||||
myView->makeCurrentOpenGlContext();
|
myView->makeCurrentOpenGlContext();
|
||||||
@ -2420,12 +2392,6 @@ void DefaultViewPort::setOpenGlDrawCallback(CvOpenGlDrawCallback /*callback*/, v
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
void DefaultViewPort::setOpenGlCleanCallback(CvOpenGlCleanCallback /*callback*/, void* /*userdata*/)
|
|
||||||
{
|
|
||||||
CV_Error(CV_OpenGlNotSupported, "Window doesn't support OpenGL");
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
void DefaultViewPort::makeCurrentOpenGlContext()
|
void DefaultViewPort::makeCurrentOpenGlContext()
|
||||||
{
|
{
|
||||||
CV_Error(CV_OpenGlNotSupported, "Window doesn't support OpenGL");
|
CV_Error(CV_OpenGlNotSupported, "Window doesn't support OpenGL");
|
||||||
@ -3074,19 +3040,10 @@ OpenGlViewPort::OpenGlViewPort(QWidget* _parent) : QGLWidget(_parent), size(-1,
|
|||||||
|
|
||||||
glDrawCallback = 0;
|
glDrawCallback = 0;
|
||||||
glDrawData = 0;
|
glDrawData = 0;
|
||||||
|
|
||||||
glCleanCallback = 0;
|
|
||||||
glCleanData = 0;
|
|
||||||
|
|
||||||
glFuncTab = 0;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
OpenGlViewPort::~OpenGlViewPort()
|
OpenGlViewPort::~OpenGlViewPort()
|
||||||
{
|
{
|
||||||
if (glFuncTab)
|
|
||||||
delete glFuncTab;
|
|
||||||
|
|
||||||
setOpenGlCleanCallback(0, 0);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
QWidget* OpenGlViewPort::getWidget()
|
QWidget* OpenGlViewPort::getWidget()
|
||||||
@ -3131,21 +3088,9 @@ void OpenGlViewPort::setOpenGlDrawCallback(CvOpenGlDrawCallback callback, void*
|
|||||||
glDrawData = userdata;
|
glDrawData = userdata;
|
||||||
}
|
}
|
||||||
|
|
||||||
void OpenGlViewPort::setOpenGlCleanCallback(CvOpenGlCleanCallback callback, void* userdata)
|
|
||||||
{
|
|
||||||
makeCurrentOpenGlContext();
|
|
||||||
|
|
||||||
if (glCleanCallback)
|
|
||||||
glCleanCallback(glCleanData);
|
|
||||||
|
|
||||||
glCleanCallback = callback;
|
|
||||||
glCleanData = userdata;
|
|
||||||
}
|
|
||||||
|
|
||||||
void OpenGlViewPort::makeCurrentOpenGlContext()
|
void OpenGlViewPort::makeCurrentOpenGlContext()
|
||||||
{
|
{
|
||||||
makeCurrent();
|
makeCurrent();
|
||||||
icvSetOpenGlFuncTab(glFuncTab);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void OpenGlViewPort::updateGl()
|
void OpenGlViewPort::updateGl()
|
||||||
@ -3153,255 +3098,9 @@ void OpenGlViewPort::updateGl()
|
|||||||
QGLWidget::updateGL();
|
QGLWidget::updateGL();
|
||||||
}
|
}
|
||||||
|
|
||||||
#ifndef APIENTRY
|
|
||||||
#define APIENTRY
|
|
||||||
#endif
|
|
||||||
|
|
||||||
#ifndef APIENTRYP
|
|
||||||
#define APIENTRYP APIENTRY *
|
|
||||||
#endif
|
|
||||||
|
|
||||||
#ifndef GL_VERSION_1_5
|
|
||||||
/* GL types for handling large vertex buffer objects */
|
|
||||||
typedef ptrdiff_t GLintptr;
|
|
||||||
typedef ptrdiff_t GLsizeiptr;
|
|
||||||
#endif
|
|
||||||
|
|
||||||
typedef void (APIENTRYP PFNGLGENBUFFERSPROC ) (GLsizei n, GLuint *buffers);
|
|
||||||
typedef void (APIENTRYP PFNGLDELETEBUFFERSPROC) (GLsizei n, const GLuint *buffers);
|
|
||||||
|
|
||||||
typedef void (APIENTRYP PFNGLBUFFERDATAPROC ) (GLenum target, GLsizeiptr size, const GLvoid *data, GLenum usage);
|
|
||||||
typedef void (APIENTRYP PFNGLBUFFERSUBDATAPROC) (GLenum target, GLintptr offset, GLsizeiptr size, const GLvoid* data);
|
|
||||||
|
|
||||||
typedef void (APIENTRYP PFNGLBINDBUFFERPROC ) (GLenum target, GLuint buffer);
|
|
||||||
|
|
||||||
typedef GLvoid* (APIENTRYP PFNGLMAPBUFFERPROC) (GLenum target, GLenum access);
|
|
||||||
typedef GLboolean (APIENTRYP PFNGLUNMAPBUFFERPROC) (GLenum target);
|
|
||||||
|
|
||||||
class GlFuncTab_QT : public CvOpenGlFuncTab
|
|
||||||
{
|
|
||||||
public:
|
|
||||||
#ifdef Q_WS_WIN
|
|
||||||
GlFuncTab_QT(HDC hDC);
|
|
||||||
#else
|
|
||||||
GlFuncTab_QT();
|
|
||||||
#endif
|
|
||||||
|
|
||||||
void genBuffers(int n, unsigned int* buffers) const;
|
|
||||||
void deleteBuffers(int n, const unsigned int* buffers) const;
|
|
||||||
|
|
||||||
void bufferData(unsigned int target, ptrdiff_t size, const void* data, unsigned int usage) const;
|
|
||||||
void bufferSubData(unsigned int target, ptrdiff_t offset, ptrdiff_t size, const void* data) const;
|
|
||||||
|
|
||||||
void bindBuffer(unsigned int target, unsigned int buffer) const;
|
|
||||||
|
|
||||||
void* mapBuffer(unsigned int target, unsigned int access) const;
|
|
||||||
void unmapBuffer(unsigned int target) const;
|
|
||||||
|
|
||||||
void generateBitmapFont(const std::string& family, int height, int weight, bool italic, bool underline, int start, int count, int base) const;
|
|
||||||
|
|
||||||
bool isGlContextInitialized() const;
|
|
||||||
|
|
||||||
PFNGLGENBUFFERSPROC glGenBuffersExt;
|
|
||||||
PFNGLDELETEBUFFERSPROC glDeleteBuffersExt;
|
|
||||||
|
|
||||||
PFNGLBUFFERDATAPROC glBufferDataExt;
|
|
||||||
PFNGLBUFFERSUBDATAPROC glBufferSubDataExt;
|
|
||||||
|
|
||||||
PFNGLBINDBUFFERPROC glBindBufferExt;
|
|
||||||
|
|
||||||
PFNGLMAPBUFFERPROC glMapBufferExt;
|
|
||||||
PFNGLUNMAPBUFFERPROC glUnmapBufferExt;
|
|
||||||
|
|
||||||
bool initialized;
|
|
||||||
|
|
||||||
#ifdef Q_WS_WIN
|
|
||||||
HDC hDC;
|
|
||||||
#endif
|
|
||||||
};
|
|
||||||
|
|
||||||
#ifdef Q_WS_WIN
|
|
||||||
GlFuncTab_QT::GlFuncTab_QT(HDC hDC_) : hDC(hDC_)
|
|
||||||
#else
|
|
||||||
GlFuncTab_QT::GlFuncTab_QT()
|
|
||||||
#endif
|
|
||||||
{
|
|
||||||
glGenBuffersExt = 0;
|
|
||||||
glDeleteBuffersExt = 0;
|
|
||||||
|
|
||||||
glBufferDataExt = 0;
|
|
||||||
glBufferSubDataExt = 0;
|
|
||||||
|
|
||||||
glBindBufferExt = 0;
|
|
||||||
|
|
||||||
glMapBufferExt = 0;
|
|
||||||
glUnmapBufferExt = 0;
|
|
||||||
|
|
||||||
initialized = false;
|
|
||||||
}
|
|
||||||
|
|
||||||
void GlFuncTab_QT::genBuffers(int n, unsigned int* buffers) const
|
|
||||||
{
|
|
||||||
CV_FUNCNAME( "GlFuncTab_QT::genBuffers" );
|
|
||||||
|
|
||||||
__BEGIN__;
|
|
||||||
|
|
||||||
if (!glGenBuffersExt)
|
|
||||||
CV_ERROR(CV_OpenGlApiCallError, "Current OpenGL implementation doesn't support required extension");
|
|
||||||
|
|
||||||
glGenBuffersExt(n, buffers);
|
|
||||||
CV_CheckGlError();
|
|
||||||
|
|
||||||
__END__;
|
|
||||||
}
|
|
||||||
|
|
||||||
void GlFuncTab_QT::deleteBuffers(int n, const unsigned int* buffers) const
|
|
||||||
{
|
|
||||||
CV_FUNCNAME( "GlFuncTab_QT::deleteBuffers" );
|
|
||||||
|
|
||||||
__BEGIN__;
|
|
||||||
|
|
||||||
if (!glDeleteBuffersExt)
|
|
||||||
CV_ERROR(CV_OpenGlApiCallError, "Current OpenGL implementation doesn't support required extension");
|
|
||||||
|
|
||||||
glDeleteBuffersExt(n, buffers);
|
|
||||||
CV_CheckGlError();
|
|
||||||
|
|
||||||
__END__;
|
|
||||||
}
|
|
||||||
|
|
||||||
void GlFuncTab_QT::bufferData(unsigned int target, ptrdiff_t size, const void* data, unsigned int usage) const
|
|
||||||
{
|
|
||||||
CV_FUNCNAME( "GlFuncTab_QT::bufferData" );
|
|
||||||
|
|
||||||
__BEGIN__;
|
|
||||||
|
|
||||||
if (!glBufferDataExt)
|
|
||||||
CV_ERROR(CV_OpenGlApiCallError, "Current OpenGL implementation doesn't support required extension");
|
|
||||||
|
|
||||||
glBufferDataExt(target, size, data, usage);
|
|
||||||
CV_CheckGlError();
|
|
||||||
|
|
||||||
__END__;
|
|
||||||
}
|
|
||||||
|
|
||||||
void GlFuncTab_QT::bufferSubData(unsigned int target, ptrdiff_t offset, ptrdiff_t size, const void* data) const
|
|
||||||
{
|
|
||||||
CV_FUNCNAME( "GlFuncTab_QT::bufferSubData" );
|
|
||||||
|
|
||||||
__BEGIN__;
|
|
||||||
|
|
||||||
if (!glBufferSubDataExt)
|
|
||||||
CV_ERROR(CV_OpenGlApiCallError, "Current OpenGL implementation doesn't support required extension");
|
|
||||||
|
|
||||||
glBufferSubDataExt(target, offset, size, data);
|
|
||||||
CV_CheckGlError();
|
|
||||||
|
|
||||||
__END__;
|
|
||||||
}
|
|
||||||
|
|
||||||
void GlFuncTab_QT::bindBuffer(unsigned int target, unsigned int buffer) const
|
|
||||||
{
|
|
||||||
CV_FUNCNAME( "GlFuncTab_QT::bindBuffer" );
|
|
||||||
|
|
||||||
__BEGIN__;
|
|
||||||
|
|
||||||
if (!glBindBufferExt)
|
|
||||||
CV_ERROR(CV_OpenGlApiCallError, "Current OpenGL implementation doesn't support required extension");
|
|
||||||
|
|
||||||
glBindBufferExt(target, buffer);
|
|
||||||
CV_CheckGlError();
|
|
||||||
|
|
||||||
__END__;
|
|
||||||
}
|
|
||||||
|
|
||||||
void* GlFuncTab_QT::mapBuffer(unsigned int target, unsigned int access) const
|
|
||||||
{
|
|
||||||
CV_FUNCNAME( "GlFuncTab_QT::mapBuffer" );
|
|
||||||
|
|
||||||
void* res = 0;
|
|
||||||
|
|
||||||
__BEGIN__;
|
|
||||||
|
|
||||||
if (!glMapBufferExt)
|
|
||||||
CV_ERROR(CV_OpenGlApiCallError, "Current OpenGL implementation doesn't support required extension");
|
|
||||||
|
|
||||||
res = glMapBufferExt(target, access);
|
|
||||||
CV_CheckGlError();
|
|
||||||
|
|
||||||
__END__;
|
|
||||||
|
|
||||||
return res;
|
|
||||||
}
|
|
||||||
|
|
||||||
void GlFuncTab_QT::unmapBuffer(unsigned int target) const
|
|
||||||
{
|
|
||||||
CV_FUNCNAME( "GlFuncTab_QT::unmapBuffer" );
|
|
||||||
|
|
||||||
__BEGIN__;
|
|
||||||
|
|
||||||
if (!glUnmapBufferExt)
|
|
||||||
CV_ERROR(CV_OpenGlApiCallError, "Current OpenGL implementation doesn't support required extension");
|
|
||||||
|
|
||||||
glUnmapBufferExt(target);
|
|
||||||
CV_CheckGlError();
|
|
||||||
|
|
||||||
__END__;
|
|
||||||
}
|
|
||||||
|
|
||||||
void GlFuncTab_QT::generateBitmapFont(const std::string& family, int height, int weight, bool italic, bool /*underline*/, int start, int count, int base) const
|
|
||||||
{
|
|
||||||
#ifdef Q_WS_WIN
|
|
||||||
CV_FUNCNAME( "GlFuncTab_QT::generateBitmapFont" );
|
|
||||||
#endif
|
|
||||||
|
|
||||||
QFont font(QString(family.c_str()), height, weight, italic);
|
|
||||||
|
|
||||||
__BEGIN__;
|
|
||||||
|
|
||||||
#ifndef Q_WS_WIN
|
|
||||||
font.setStyleStrategy(QFont::OpenGLCompatible);
|
|
||||||
if (font.handle())
|
|
||||||
glXUseXFont(font.handle(), start, count, base);
|
|
||||||
#else
|
|
||||||
SelectObject(hDC, font.handle());
|
|
||||||
if (!wglUseFontBitmaps(hDC, start, count, base))
|
|
||||||
CV_ERROR(CV_OpenGlApiCallError, "Can't create font");
|
|
||||||
#endif
|
|
||||||
|
|
||||||
__END__;
|
|
||||||
}
|
|
||||||
|
|
||||||
bool GlFuncTab_QT::isGlContextInitialized() const
|
|
||||||
{
|
|
||||||
return initialized;
|
|
||||||
}
|
|
||||||
|
|
||||||
void OpenGlViewPort::initializeGL()
|
void OpenGlViewPort::initializeGL()
|
||||||
{
|
{
|
||||||
glHint(GL_PERSPECTIVE_CORRECTION_HINT, GL_NICEST);
|
glHint(GL_PERSPECTIVE_CORRECTION_HINT, GL_NICEST);
|
||||||
|
|
||||||
#ifdef Q_WS_WIN
|
|
||||||
std::auto_ptr<GlFuncTab_QT> qglFuncTab(new GlFuncTab_QT(getDC()));
|
|
||||||
#else
|
|
||||||
std::auto_ptr<GlFuncTab_QT> qglFuncTab(new GlFuncTab_QT);
|
|
||||||
#endif
|
|
||||||
|
|
||||||
// Load extensions
|
|
||||||
|
|
||||||
qglFuncTab->glGenBuffersExt = (PFNGLGENBUFFERSPROC)context()->getProcAddress("glGenBuffers");
|
|
||||||
qglFuncTab->glDeleteBuffersExt = (PFNGLDELETEBUFFERSPROC)context()->getProcAddress("glDeleteBuffers");
|
|
||||||
qglFuncTab->glBufferDataExt = (PFNGLBUFFERDATAPROC)context()->getProcAddress("glBufferData");
|
|
||||||
qglFuncTab->glBufferSubDataExt = (PFNGLBUFFERSUBDATAPROC)context()->getProcAddress("glBufferSubData");
|
|
||||||
qglFuncTab->glBindBufferExt = (PFNGLBINDBUFFERPROC)context()->getProcAddress("glBindBuffer");
|
|
||||||
qglFuncTab->glMapBufferExt = (PFNGLMAPBUFFERPROC)context()->getProcAddress("glMapBuffer");
|
|
||||||
qglFuncTab->glUnmapBufferExt = (PFNGLUNMAPBUFFERPROC)context()->getProcAddress("glUnmapBuffer");
|
|
||||||
|
|
||||||
qglFuncTab->initialized = true;
|
|
||||||
|
|
||||||
glFuncTab = qglFuncTab.release();
|
|
||||||
|
|
||||||
icvSetOpenGlFuncTab(glFuncTab);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void OpenGlViewPort::resizeGL(int w, int h)
|
void OpenGlViewPort::resizeGL(int w, int h)
|
||||||
@ -3411,14 +3110,10 @@ void OpenGlViewPort::resizeGL(int w, int h)
|
|||||||
|
|
||||||
void OpenGlViewPort::paintGL()
|
void OpenGlViewPort::paintGL()
|
||||||
{
|
{
|
||||||
icvSetOpenGlFuncTab(glFuncTab);
|
|
||||||
|
|
||||||
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
|
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
|
||||||
|
|
||||||
if (glDrawCallback)
|
if (glDrawCallback)
|
||||||
glDrawCallback(glDrawData);
|
glDrawCallback(glDrawData);
|
||||||
|
|
||||||
CV_CheckGlError();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void OpenGlViewPort::mousePressEvent(QMouseEvent* evnt)
|
void OpenGlViewPort::mousePressEvent(QMouseEvent* evnt)
|
||||||
|
@ -141,7 +141,6 @@ public slots:
|
|||||||
void enablePropertiesButtonEachWindow();
|
void enablePropertiesButtonEachWindow();
|
||||||
|
|
||||||
void setOpenGlDrawCallback(QString name, void* callback, void* userdata);
|
void setOpenGlDrawCallback(QString name, void* callback, void* userdata);
|
||||||
void setOpenGlCleanCallback(QString name, void* callback, void* userdata);
|
|
||||||
void setOpenGlContext(QString name);
|
void setOpenGlContext(QString name);
|
||||||
void updateWindow(QString name);
|
void updateWindow(QString name);
|
||||||
double isOpenGl(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));
|
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 setOpenGlDrawCallback(CvOpenGlDrawCallback callback, void* userdata);
|
||||||
void setOpenGlCleanCallback(CvOpenGlCleanCallback callback, void* userdata);
|
|
||||||
void makeCurrentOpenGlContext();
|
void makeCurrentOpenGlContext();
|
||||||
void updateGl();
|
void updateGl();
|
||||||
bool isOpenGl();
|
bool isOpenGl();
|
||||||
@ -397,7 +395,6 @@ public:
|
|||||||
virtual void startDisplayInfo(QString text, int delayms) = 0;
|
virtual void startDisplayInfo(QString text, int delayms) = 0;
|
||||||
|
|
||||||
virtual void setOpenGlDrawCallback(CvOpenGlDrawCallback callback, void* userdata) = 0;
|
virtual void setOpenGlDrawCallback(CvOpenGlDrawCallback callback, void* userdata) = 0;
|
||||||
virtual void setOpenGlCleanCallback(CvOpenGlCleanCallback callback, void* userdata) = 0;
|
|
||||||
virtual void makeCurrentOpenGlContext() = 0;
|
virtual void makeCurrentOpenGlContext() = 0;
|
||||||
virtual void updateGl() = 0;
|
virtual void updateGl() = 0;
|
||||||
|
|
||||||
@ -429,7 +426,6 @@ public:
|
|||||||
void startDisplayInfo(QString text, int delayms);
|
void startDisplayInfo(QString text, int delayms);
|
||||||
|
|
||||||
void setOpenGlDrawCallback(CvOpenGlDrawCallback callback, void* userdata);
|
void setOpenGlDrawCallback(CvOpenGlDrawCallback callback, void* userdata);
|
||||||
void setOpenGlCleanCallback(CvOpenGlCleanCallback callback, void* userdata);
|
|
||||||
void makeCurrentOpenGlContext();
|
void makeCurrentOpenGlContext();
|
||||||
void updateGl();
|
void updateGl();
|
||||||
|
|
||||||
@ -456,11 +452,6 @@ private:
|
|||||||
CvOpenGlDrawCallback glDrawCallback;
|
CvOpenGlDrawCallback glDrawCallback;
|
||||||
void* glDrawData;
|
void* glDrawData;
|
||||||
|
|
||||||
CvOpenGlCleanCallback glCleanCallback;
|
|
||||||
void* glCleanData;
|
|
||||||
|
|
||||||
CvOpenGlFuncTab* glFuncTab;
|
|
||||||
|
|
||||||
void icvmouseHandler(QMouseEvent* event, type_mouse_event category, int& cv_event, int& flags);
|
void icvmouseHandler(QMouseEvent* event, type_mouse_event category, int& cv_event, int& flags);
|
||||||
void icvmouseProcessing(QPointF pt, 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 startDisplayInfo(QString text, int delayms);
|
||||||
|
|
||||||
void setOpenGlDrawCallback(CvOpenGlDrawCallback callback, void* userdata);
|
void setOpenGlDrawCallback(CvOpenGlDrawCallback callback, void* userdata);
|
||||||
void setOpenGlCleanCallback(CvOpenGlCleanCallback callback, void* userdata);
|
|
||||||
void makeCurrentOpenGlContext();
|
void makeCurrentOpenGlContext();
|
||||||
void updateGl();
|
void updateGl();
|
||||||
|
|
||||||
|
@ -417,9 +417,6 @@ typedef struct CvWindow
|
|||||||
|
|
||||||
CvOpenGlDrawCallback glDrawCallback;
|
CvOpenGlDrawCallback glDrawCallback;
|
||||||
void* glDrawData;
|
void* glDrawData;
|
||||||
|
|
||||||
CvOpenGlCleanCallback glCleanCallback;
|
|
||||||
void* glCleanData;
|
|
||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
CvWindow;
|
CvWindow;
|
||||||
@ -692,238 +689,6 @@ double cvGetOpenGlProp_GTK(const char* name)
|
|||||||
|
|
||||||
namespace
|
namespace
|
||||||
{
|
{
|
||||||
class GlFuncTab_GTK : public CvOpenGlFuncTab
|
|
||||||
{
|
|
||||||
public:
|
|
||||||
GlFuncTab_GTK();
|
|
||||||
|
|
||||||
void genBuffers(int n, unsigned int* buffers) const;
|
|
||||||
void deleteBuffers(int n, const unsigned int* buffers) const;
|
|
||||||
|
|
||||||
void bufferData(unsigned int target, ptrdiff_t size, const void* data, unsigned int usage) const;
|
|
||||||
void bufferSubData(unsigned int target, ptrdiff_t offset, ptrdiff_t size, const void* data) const;
|
|
||||||
|
|
||||||
void bindBuffer(unsigned int target, unsigned int buffer) const;
|
|
||||||
|
|
||||||
void* mapBuffer(unsigned int target, unsigned int access) const;
|
|
||||||
void unmapBuffer(unsigned int target) const;
|
|
||||||
|
|
||||||
void generateBitmapFont(const std::string& family, int height, int weight, bool italic, bool underline, int start, int count, int base) const;
|
|
||||||
|
|
||||||
bool isGlContextInitialized() const;
|
|
||||||
|
|
||||||
PFNGLGENBUFFERSPROC glGenBuffersExt;
|
|
||||||
PFNGLDELETEBUFFERSPROC glDeleteBuffersExt;
|
|
||||||
|
|
||||||
PFNGLBUFFERDATAPROC glBufferDataExt;
|
|
||||||
PFNGLBUFFERSUBDATAPROC glBufferSubDataExt;
|
|
||||||
|
|
||||||
PFNGLBINDBUFFERPROC glBindBufferExt;
|
|
||||||
|
|
||||||
PFNGLMAPBUFFERPROC glMapBufferExt;
|
|
||||||
PFNGLUNMAPBUFFERPROC glUnmapBufferExt;
|
|
||||||
|
|
||||||
bool initialized;
|
|
||||||
};
|
|
||||||
|
|
||||||
GlFuncTab_GTK::GlFuncTab_GTK()
|
|
||||||
{
|
|
||||||
glGenBuffersExt = 0;
|
|
||||||
glDeleteBuffersExt = 0;
|
|
||||||
|
|
||||||
glBufferDataExt = 0;
|
|
||||||
glBufferSubDataExt = 0;
|
|
||||||
|
|
||||||
glBindBufferExt = 0;
|
|
||||||
|
|
||||||
glMapBufferExt = 0;
|
|
||||||
glUnmapBufferExt = 0;
|
|
||||||
|
|
||||||
initialized = false;
|
|
||||||
}
|
|
||||||
|
|
||||||
void GlFuncTab_GTK::genBuffers(int n, unsigned int* buffers) const
|
|
||||||
{
|
|
||||||
CV_FUNCNAME( "GlFuncTab_GTK::genBuffers" );
|
|
||||||
|
|
||||||
__BEGIN__;
|
|
||||||
|
|
||||||
if (!glGenBuffersExt)
|
|
||||||
CV_ERROR(CV_OpenGlApiCallError, "Current OpenGL implementation doesn't support required extension");
|
|
||||||
|
|
||||||
glGenBuffersExt(n, buffers);
|
|
||||||
CV_CheckGlError();
|
|
||||||
|
|
||||||
__END__;
|
|
||||||
}
|
|
||||||
|
|
||||||
void GlFuncTab_GTK::deleteBuffers(int n, const unsigned int* buffers) const
|
|
||||||
{
|
|
||||||
CV_FUNCNAME( "GlFuncTab_GTK::deleteBuffers" );
|
|
||||||
|
|
||||||
__BEGIN__;
|
|
||||||
|
|
||||||
if (!glDeleteBuffersExt)
|
|
||||||
CV_ERROR(CV_OpenGlApiCallError, "Current OpenGL implementation doesn't support required extension");
|
|
||||||
|
|
||||||
glDeleteBuffersExt(n, buffers);
|
|
||||||
CV_CheckGlError();
|
|
||||||
|
|
||||||
__END__;
|
|
||||||
}
|
|
||||||
|
|
||||||
void GlFuncTab_GTK::bufferData(unsigned int target, ptrdiff_t size, const void* data, unsigned int usage) const
|
|
||||||
{
|
|
||||||
CV_FUNCNAME( "GlFuncTab_GTK::bufferData" );
|
|
||||||
|
|
||||||
__BEGIN__;
|
|
||||||
|
|
||||||
if (!glBufferDataExt)
|
|
||||||
CV_ERROR(CV_OpenGlApiCallError, "Current OpenGL implementation doesn't support required extension");
|
|
||||||
|
|
||||||
glBufferDataExt(target, size, data, usage);
|
|
||||||
CV_CheckGlError();
|
|
||||||
|
|
||||||
__END__;
|
|
||||||
}
|
|
||||||
|
|
||||||
void GlFuncTab_GTK::bufferSubData(unsigned int target, ptrdiff_t offset, ptrdiff_t size, const void* data) const
|
|
||||||
{
|
|
||||||
CV_FUNCNAME( "GlFuncTab_GTK::bufferSubData" );
|
|
||||||
|
|
||||||
__BEGIN__;
|
|
||||||
|
|
||||||
if (!glBufferSubDataExt)
|
|
||||||
CV_ERROR(CV_OpenGlApiCallError, "Current OpenGL implementation doesn't support required extension");
|
|
||||||
|
|
||||||
glBufferSubDataExt(target, offset, size, data);
|
|
||||||
CV_CheckGlError();
|
|
||||||
|
|
||||||
__END__;
|
|
||||||
}
|
|
||||||
|
|
||||||
void GlFuncTab_GTK::bindBuffer(unsigned int target, unsigned int buffer) const
|
|
||||||
{
|
|
||||||
CV_FUNCNAME( "GlFuncTab_GTK::bindBuffer" );
|
|
||||||
|
|
||||||
__BEGIN__;
|
|
||||||
|
|
||||||
if (!glBindBufferExt)
|
|
||||||
CV_ERROR(CV_OpenGlApiCallError, "Current OpenGL implementation doesn't support required extension");
|
|
||||||
|
|
||||||
glBindBufferExt(target, buffer);
|
|
||||||
CV_CheckGlError();
|
|
||||||
|
|
||||||
__END__;
|
|
||||||
}
|
|
||||||
|
|
||||||
void* GlFuncTab_GTK::mapBuffer(unsigned int target, unsigned int access) const
|
|
||||||
{
|
|
||||||
CV_FUNCNAME( "GlFuncTab_GTK::mapBuffer" );
|
|
||||||
|
|
||||||
void* res = 0;
|
|
||||||
|
|
||||||
__BEGIN__;
|
|
||||||
|
|
||||||
if (!glMapBufferExt)
|
|
||||||
CV_ERROR(CV_OpenGlApiCallError, "Current OpenGL implementation doesn't support required extension");
|
|
||||||
|
|
||||||
res = glMapBufferExt(target, access);
|
|
||||||
CV_CheckGlError();
|
|
||||||
|
|
||||||
__END__;
|
|
||||||
|
|
||||||
return res;
|
|
||||||
}
|
|
||||||
|
|
||||||
void GlFuncTab_GTK::unmapBuffer(unsigned int target) const
|
|
||||||
{
|
|
||||||
CV_FUNCNAME( "GlFuncTab_GTK::unmapBuffer" );
|
|
||||||
|
|
||||||
__BEGIN__;
|
|
||||||
|
|
||||||
if (!glUnmapBufferExt)
|
|
||||||
CV_ERROR(CV_OpenGlApiCallError, "Current OpenGL implementation doesn't support required extension");
|
|
||||||
|
|
||||||
glUnmapBufferExt(target);
|
|
||||||
CV_CheckGlError();
|
|
||||||
|
|
||||||
__END__;
|
|
||||||
}
|
|
||||||
|
|
||||||
void GlFuncTab_GTK::generateBitmapFont(const std::string& family, int height, int weight, bool italic, bool /*underline*/, int start, int count, int base) const
|
|
||||||
{
|
|
||||||
PangoFontDescription* fontDecr;
|
|
||||||
PangoFont* pangoFont;
|
|
||||||
|
|
||||||
CV_FUNCNAME( "GlFuncTab_GTK::generateBitmapFont" );
|
|
||||||
|
|
||||||
__BEGIN__;
|
|
||||||
|
|
||||||
fontDecr = pango_font_description_new();
|
|
||||||
|
|
||||||
pango_font_description_set_size(fontDecr, height);
|
|
||||||
|
|
||||||
pango_font_description_set_family_static(fontDecr, family.c_str());
|
|
||||||
|
|
||||||
pango_font_description_set_weight(fontDecr, static_cast<PangoWeight>(weight));
|
|
||||||
|
|
||||||
pango_font_description_set_style(fontDecr, italic ? PANGO_STYLE_ITALIC : PANGO_STYLE_NORMAL);
|
|
||||||
|
|
||||||
pangoFont = gdk_gl_font_use_pango_font(fontDecr, start, count, base);
|
|
||||||
|
|
||||||
pango_font_description_free(fontDecr);
|
|
||||||
|
|
||||||
if (!pangoFont)
|
|
||||||
CV_ERROR(CV_OpenGlApiCallError, "Can't create font");
|
|
||||||
|
|
||||||
__END__;
|
|
||||||
}
|
|
||||||
|
|
||||||
bool GlFuncTab_GTK::isGlContextInitialized() const
|
|
||||||
{
|
|
||||||
return initialized;
|
|
||||||
}
|
|
||||||
|
|
||||||
void initGl()
|
|
||||||
{
|
|
||||||
static GlFuncTab_GTK glFuncTab;
|
|
||||||
static bool first = true;
|
|
||||||
|
|
||||||
if (first)
|
|
||||||
{
|
|
||||||
// Load extensions
|
|
||||||
GdkGLProc func;
|
|
||||||
|
|
||||||
func = gdk_gl_get_proc_address("glGenBuffers");
|
|
||||||
glFuncTab.glGenBuffersExt = (PFNGLGENBUFFERSPROC)func;
|
|
||||||
|
|
||||||
func = gdk_gl_get_proc_address("glDeleteBuffers");
|
|
||||||
glFuncTab.glDeleteBuffersExt = (PFNGLDELETEBUFFERSPROC)func;
|
|
||||||
|
|
||||||
func = gdk_gl_get_proc_address("glBufferData");
|
|
||||||
glFuncTab.glBufferDataExt = (PFNGLBUFFERDATAPROC)func;
|
|
||||||
|
|
||||||
func = gdk_gl_get_proc_address("glBufferSubData");
|
|
||||||
glFuncTab.glBufferSubDataExt = (PFNGLBUFFERSUBDATAPROC)func;
|
|
||||||
|
|
||||||
func = gdk_gl_get_proc_address("glBindBuffer");
|
|
||||||
glFuncTab.glBindBufferExt = (PFNGLBINDBUFFERPROC)func;
|
|
||||||
|
|
||||||
func = gdk_gl_get_proc_address("glMapBuffer");
|
|
||||||
glFuncTab.glMapBufferExt = (PFNGLMAPBUFFERPROC)func;
|
|
||||||
|
|
||||||
func = gdk_gl_get_proc_address("glUnmapBuffer");
|
|
||||||
glFuncTab.glUnmapBufferExt = (PFNGLUNMAPBUFFERPROC)func;
|
|
||||||
|
|
||||||
glFuncTab.initialized = true;
|
|
||||||
|
|
||||||
icvSetOpenGlFuncTab(&glFuncTab);
|
|
||||||
|
|
||||||
first = false;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
void createGlContext(CvWindow* window)
|
void createGlContext(CvWindow* window)
|
||||||
{
|
{
|
||||||
GdkGLConfig* glconfig;
|
GdkGLConfig* glconfig;
|
||||||
@ -932,8 +697,6 @@ namespace
|
|||||||
|
|
||||||
__BEGIN__;
|
__BEGIN__;
|
||||||
|
|
||||||
window->useGl = false;
|
|
||||||
|
|
||||||
// Try double-buffered visual
|
// Try double-buffered visual
|
||||||
glconfig = gdk_gl_config_new_by_mode((GdkGLConfigMode)(GDK_GL_MODE_RGB | GDK_GL_MODE_DEPTH | GDK_GL_MODE_DOUBLE));
|
glconfig = gdk_gl_config_new_by_mode((GdkGLConfigMode)(GDK_GL_MODE_RGB | GDK_GL_MODE_DEPTH | GDK_GL_MODE_DOUBLE));
|
||||||
if (!glconfig)
|
if (!glconfig)
|
||||||
@ -943,24 +706,11 @@ namespace
|
|||||||
if (!gtk_widget_set_gl_capability(window->widget, glconfig, NULL, TRUE, GDK_GL_RGBA_TYPE))
|
if (!gtk_widget_set_gl_capability(window->widget, glconfig, NULL, TRUE, GDK_GL_RGBA_TYPE))
|
||||||
CV_ERROR( CV_OpenGlApiCallError, "Can't Create A GL Device Context" );
|
CV_ERROR( CV_OpenGlApiCallError, "Can't Create A GL Device Context" );
|
||||||
|
|
||||||
initGl();
|
|
||||||
|
|
||||||
window->useGl = true;
|
window->useGl = true;
|
||||||
|
|
||||||
__END__;
|
__END__;
|
||||||
}
|
}
|
||||||
|
|
||||||
void releaseGlContext(CvWindow* window)
|
|
||||||
{
|
|
||||||
//CV_FUNCNAME( "releaseGlContext" );
|
|
||||||
|
|
||||||
//__BEGIN__;
|
|
||||||
|
|
||||||
window->useGl = false;
|
|
||||||
|
|
||||||
//__END__;
|
|
||||||
}
|
|
||||||
|
|
||||||
void drawGl(CvWindow* window)
|
void drawGl(CvWindow* window)
|
||||||
{
|
{
|
||||||
CV_FUNCNAME( "drawGl" );
|
CV_FUNCNAME( "drawGl" );
|
||||||
@ -980,8 +730,6 @@ namespace
|
|||||||
if (window->glDrawCallback)
|
if (window->glDrawCallback)
|
||||||
window->glDrawCallback(window->glDrawData);
|
window->glDrawCallback(window->glDrawData);
|
||||||
|
|
||||||
CV_CheckGlError();
|
|
||||||
|
|
||||||
if (gdk_gl_drawable_is_double_buffered (gldrawable))
|
if (gdk_gl_drawable_is_double_buffered (gldrawable))
|
||||||
gdk_gl_drawable_swap_buffers(gldrawable);
|
gdk_gl_drawable_swap_buffers(gldrawable);
|
||||||
else
|
else
|
||||||
@ -1101,9 +849,6 @@ CV_IMPL int cvNamedWindow( const char* name, int flags )
|
|||||||
|
|
||||||
window->glDrawCallback = 0;
|
window->glDrawCallback = 0;
|
||||||
window->glDrawData = 0;
|
window->glDrawData = 0;
|
||||||
|
|
||||||
window->glCleanCallback = 0;
|
|
||||||
window->glCleanData = 0;
|
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
//
|
//
|
||||||
@ -1233,40 +978,6 @@ CV_IMPL void cvSetOpenGlDrawCallback(const char* name, CvOpenGlDrawCallback call
|
|||||||
__END__;
|
__END__;
|
||||||
}
|
}
|
||||||
|
|
||||||
void icvSetOpenGlCleanCallback(const char* name, CvOpenGlCleanCallback callback, void* userdata)
|
|
||||||
{
|
|
||||||
CvWindow* window;
|
|
||||||
GdkGLContext* glcontext;
|
|
||||||
GdkGLDrawable* gldrawable;
|
|
||||||
|
|
||||||
CV_FUNCNAME( "icvSetOpenGlCleanCallback" );
|
|
||||||
|
|
||||||
__BEGIN__;
|
|
||||||
|
|
||||||
if (!name)
|
|
||||||
CV_ERROR(CV_StsNullPtr, "NULL name string");
|
|
||||||
|
|
||||||
window = icvFindWindowByName(name);
|
|
||||||
if (!window)
|
|
||||||
EXIT;
|
|
||||||
|
|
||||||
if (!window->useGl)
|
|
||||||
CV_ERROR( CV_OpenGlNotSupported, "Window doesn't support OpenGL" );
|
|
||||||
|
|
||||||
glcontext = gtk_widget_get_gl_context(window->widget);
|
|
||||||
gldrawable = gtk_widget_get_gl_drawable(window->widget);
|
|
||||||
|
|
||||||
gdk_gl_drawable_make_current(gldrawable, glcontext);
|
|
||||||
|
|
||||||
if (window->glCleanCallback)
|
|
||||||
window->glCleanCallback(window->glCleanData);
|
|
||||||
|
|
||||||
window->glCleanCallback = callback;
|
|
||||||
window->glCleanData = userdata;
|
|
||||||
|
|
||||||
__END__;
|
|
||||||
}
|
|
||||||
|
|
||||||
#endif // HAVE_OPENGL
|
#endif // HAVE_OPENGL
|
||||||
|
|
||||||
|
|
||||||
@ -1276,25 +987,6 @@ static void icvDeleteWindow( CvWindow* window )
|
|||||||
{
|
{
|
||||||
CvTrackbar* trackbar;
|
CvTrackbar* trackbar;
|
||||||
|
|
||||||
#ifdef HAVE_OPENGL
|
|
||||||
if (window->useGl)
|
|
||||||
{
|
|
||||||
GdkGLContext* glcontext = gtk_widget_get_gl_context(window->widget);
|
|
||||||
GdkGLDrawable* gldrawable = gtk_widget_get_gl_drawable(window->widget);
|
|
||||||
|
|
||||||
gdk_gl_drawable_make_current(gldrawable, glcontext);
|
|
||||||
|
|
||||||
if (window->glCleanCallback)
|
|
||||||
{
|
|
||||||
window->glCleanCallback(window->glCleanData);
|
|
||||||
window->glCleanCallback = 0;
|
|
||||||
window->glCleanData = 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
releaseGlContext(window);
|
|
||||||
}
|
|
||||||
#endif
|
|
||||||
|
|
||||||
if( window->prev )
|
if( window->prev )
|
||||||
window->prev->next = window->next;
|
window->prev->next = window->next;
|
||||||
else
|
else
|
||||||
|
@ -192,11 +192,6 @@ typedef struct CvWindow
|
|||||||
|
|
||||||
CvOpenGlDrawCallback glDrawCallback;
|
CvOpenGlDrawCallback glDrawCallback;
|
||||||
void* glDrawData;
|
void* glDrawData;
|
||||||
|
|
||||||
CvOpenGlCleanCallback glCleanCallback;
|
|
||||||
void* glCleanData;
|
|
||||||
|
|
||||||
CvOpenGlFuncTab* glFuncTab;
|
|
||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
CvWindow;
|
CvWindow;
|
||||||
@ -580,272 +575,8 @@ double cvGetOpenGlProp_W32(const char* name)
|
|||||||
|
|
||||||
#ifdef HAVE_OPENGL
|
#ifdef HAVE_OPENGL
|
||||||
|
|
||||||
#ifndef APIENTRY
|
|
||||||
#define APIENTRY
|
|
||||||
#endif
|
|
||||||
|
|
||||||
#ifndef APIENTRYP
|
|
||||||
#define APIENTRYP APIENTRY *
|
|
||||||
#endif
|
|
||||||
|
|
||||||
#ifndef GL_VERSION_1_5
|
|
||||||
/* GL types for handling large vertex buffer objects */
|
|
||||||
typedef ptrdiff_t GLintptr;
|
|
||||||
typedef ptrdiff_t GLsizeiptr;
|
|
||||||
#endif
|
|
||||||
|
|
||||||
namespace
|
namespace
|
||||||
{
|
{
|
||||||
typedef void (APIENTRYP PFNGLGENBUFFERSPROC ) (GLsizei n, GLuint *buffers);
|
|
||||||
typedef void (APIENTRYP PFNGLDELETEBUFFERSPROC) (GLsizei n, const GLuint *buffers);
|
|
||||||
|
|
||||||
typedef void (APIENTRYP PFNGLBUFFERDATAPROC ) (GLenum target, GLsizeiptr size, const GLvoid *data, GLenum usage);
|
|
||||||
typedef void (APIENTRYP PFNGLBUFFERSUBDATAPROC) (GLenum target, GLintptr offset, GLsizeiptr size, const GLvoid* data);
|
|
||||||
|
|
||||||
typedef void (APIENTRYP PFNGLBINDBUFFERPROC ) (GLenum target, GLuint buffer);
|
|
||||||
|
|
||||||
typedef GLvoid* (APIENTRYP PFNGLMAPBUFFERPROC) (GLenum target, GLenum access);
|
|
||||||
typedef GLboolean (APIENTRYP PFNGLUNMAPBUFFERPROC) (GLenum target);
|
|
||||||
|
|
||||||
class GlFuncTab_W32 : public CvOpenGlFuncTab
|
|
||||||
{
|
|
||||||
public:
|
|
||||||
GlFuncTab_W32(HDC hDC);
|
|
||||||
|
|
||||||
void genBuffers(int n, unsigned int* buffers) const;
|
|
||||||
void deleteBuffers(int n, const unsigned int* buffers) const;
|
|
||||||
|
|
||||||
void bufferData(unsigned int target, ptrdiff_t size, const void* data, unsigned int usage) const;
|
|
||||||
void bufferSubData(unsigned int target, ptrdiff_t offset, ptrdiff_t size, const void* data) const;
|
|
||||||
|
|
||||||
void bindBuffer(unsigned int target, unsigned int buffer) const;
|
|
||||||
|
|
||||||
void* mapBuffer(unsigned int target, unsigned int access) const;
|
|
||||||
void unmapBuffer(unsigned int target) const;
|
|
||||||
|
|
||||||
void generateBitmapFont(const std::string& family, int height, int weight, bool italic, bool underline, int start, int count, int base) const;
|
|
||||||
|
|
||||||
bool isGlContextInitialized() const;
|
|
||||||
|
|
||||||
PFNGLGENBUFFERSPROC glGenBuffersExt;
|
|
||||||
PFNGLDELETEBUFFERSPROC glDeleteBuffersExt;
|
|
||||||
|
|
||||||
PFNGLBUFFERDATAPROC glBufferDataExt;
|
|
||||||
PFNGLBUFFERSUBDATAPROC glBufferSubDataExt;
|
|
||||||
|
|
||||||
PFNGLBINDBUFFERPROC glBindBufferExt;
|
|
||||||
|
|
||||||
PFNGLMAPBUFFERPROC glMapBufferExt;
|
|
||||||
PFNGLUNMAPBUFFERPROC glUnmapBufferExt;
|
|
||||||
|
|
||||||
bool initialized;
|
|
||||||
|
|
||||||
HDC hDC;
|
|
||||||
};
|
|
||||||
|
|
||||||
GlFuncTab_W32::GlFuncTab_W32(HDC hDC_)
|
|
||||||
{
|
|
||||||
glGenBuffersExt = 0;
|
|
||||||
glDeleteBuffersExt = 0;
|
|
||||||
|
|
||||||
glBufferDataExt = 0;
|
|
||||||
glBufferSubDataExt = 0;
|
|
||||||
|
|
||||||
glBindBufferExt = 0;
|
|
||||||
|
|
||||||
glMapBufferExt = 0;
|
|
||||||
glUnmapBufferExt = 0;
|
|
||||||
|
|
||||||
initialized = false;
|
|
||||||
|
|
||||||
hDC = hDC_;
|
|
||||||
}
|
|
||||||
|
|
||||||
void GlFuncTab_W32::genBuffers(int n, unsigned int* buffers) const
|
|
||||||
{
|
|
||||||
CV_FUNCNAME( "GlFuncTab_W32::genBuffers" );
|
|
||||||
|
|
||||||
__BEGIN__;
|
|
||||||
|
|
||||||
if (!glGenBuffersExt)
|
|
||||||
CV_ERROR(CV_OpenGlApiCallError, "Current OpenGL implementation doesn't support required extension");
|
|
||||||
|
|
||||||
glGenBuffersExt(n, buffers);
|
|
||||||
CV_CheckGlError();
|
|
||||||
|
|
||||||
__END__;
|
|
||||||
}
|
|
||||||
|
|
||||||
void GlFuncTab_W32::deleteBuffers(int n, const unsigned int* buffers) const
|
|
||||||
{
|
|
||||||
CV_FUNCNAME( "GlFuncTab_W32::deleteBuffers" );
|
|
||||||
|
|
||||||
__BEGIN__;
|
|
||||||
|
|
||||||
if (!glDeleteBuffersExt)
|
|
||||||
CV_ERROR(CV_OpenGlApiCallError, "Current OpenGL implementation doesn't support required extension");
|
|
||||||
|
|
||||||
glDeleteBuffersExt(n, buffers);
|
|
||||||
CV_CheckGlError();
|
|
||||||
|
|
||||||
__END__;
|
|
||||||
}
|
|
||||||
|
|
||||||
void GlFuncTab_W32::bufferData(unsigned int target, ptrdiff_t size, const void* data, unsigned int usage) const
|
|
||||||
{
|
|
||||||
CV_FUNCNAME( "GlFuncTab_W32::bufferData" );
|
|
||||||
|
|
||||||
__BEGIN__;
|
|
||||||
|
|
||||||
if (!glBufferDataExt)
|
|
||||||
CV_ERROR(CV_OpenGlApiCallError, "Current OpenGL implementation doesn't support required extension");
|
|
||||||
|
|
||||||
glBufferDataExt(target, size, data, usage);
|
|
||||||
CV_CheckGlError();
|
|
||||||
|
|
||||||
__END__;
|
|
||||||
}
|
|
||||||
|
|
||||||
void GlFuncTab_W32::bufferSubData(unsigned int target, ptrdiff_t offset, ptrdiff_t size, const void* data) const
|
|
||||||
{
|
|
||||||
CV_FUNCNAME( "GlFuncTab_W32::bufferSubData" );
|
|
||||||
|
|
||||||
__BEGIN__;
|
|
||||||
|
|
||||||
if (!glBufferSubDataExt)
|
|
||||||
CV_ERROR(CV_OpenGlApiCallError, "Current OpenGL implementation doesn't support required extension");
|
|
||||||
|
|
||||||
glBufferSubDataExt(target, offset, size, data);
|
|
||||||
CV_CheckGlError();
|
|
||||||
|
|
||||||
__END__;
|
|
||||||
}
|
|
||||||
|
|
||||||
void GlFuncTab_W32::bindBuffer(unsigned int target, unsigned int buffer) const
|
|
||||||
{
|
|
||||||
CV_FUNCNAME( "GlFuncTab_W32::bindBuffer" );
|
|
||||||
|
|
||||||
__BEGIN__;
|
|
||||||
|
|
||||||
if (!glBindBufferExt)
|
|
||||||
CV_ERROR(CV_OpenGlApiCallError, "Current OpenGL implementation doesn't support required extension");
|
|
||||||
|
|
||||||
glBindBufferExt(target, buffer);
|
|
||||||
CV_CheckGlError();
|
|
||||||
|
|
||||||
__END__;
|
|
||||||
}
|
|
||||||
|
|
||||||
void* GlFuncTab_W32::mapBuffer(unsigned int target, unsigned int access) const
|
|
||||||
{
|
|
||||||
CV_FUNCNAME( "GlFuncTab_W32::mapBuffer" );
|
|
||||||
|
|
||||||
void* res = 0;
|
|
||||||
|
|
||||||
__BEGIN__;
|
|
||||||
|
|
||||||
if (!glMapBufferExt)
|
|
||||||
CV_ERROR(CV_OpenGlApiCallError, "Current OpenGL implementation doesn't support required extension");
|
|
||||||
|
|
||||||
res = glMapBufferExt(target, access);
|
|
||||||
CV_CheckGlError();
|
|
||||||
|
|
||||||
__END__;
|
|
||||||
|
|
||||||
return res;
|
|
||||||
}
|
|
||||||
|
|
||||||
void GlFuncTab_W32::unmapBuffer(unsigned int target) const
|
|
||||||
{
|
|
||||||
CV_FUNCNAME( "GlFuncTab_W32::unmapBuffer" );
|
|
||||||
|
|
||||||
__BEGIN__;
|
|
||||||
|
|
||||||
if (!glUnmapBufferExt)
|
|
||||||
CV_ERROR(CV_OpenGlApiCallError, "Current OpenGL implementation doesn't support required extension");
|
|
||||||
|
|
||||||
glUnmapBufferExt(target);
|
|
||||||
CV_CheckGlError();
|
|
||||||
|
|
||||||
__END__;
|
|
||||||
}
|
|
||||||
|
|
||||||
void GlFuncTab_W32::generateBitmapFont(const std::string& family, int height, int weight, bool italic, bool underline, int start, int count, int base) const
|
|
||||||
{
|
|
||||||
HFONT font;
|
|
||||||
|
|
||||||
CV_FUNCNAME( "GlFuncTab_W32::generateBitmapFont" );
|
|
||||||
|
|
||||||
__BEGIN__;
|
|
||||||
|
|
||||||
font = CreateFont
|
|
||||||
(
|
|
||||||
-height, // height
|
|
||||||
0, // cell width
|
|
||||||
0, // Angle of Escapement
|
|
||||||
0, // Orientation Angle
|
|
||||||
weight, // font weight
|
|
||||||
italic ? TRUE : FALSE, // Italic
|
|
||||||
underline ? TRUE : FALSE, // Underline
|
|
||||||
FALSE, // StrikeOut
|
|
||||||
ANSI_CHARSET, // CharSet
|
|
||||||
OUT_TT_PRECIS, // OutPrecision
|
|
||||||
CLIP_DEFAULT_PRECIS, // ClipPrecision
|
|
||||||
ANTIALIASED_QUALITY, // Quality
|
|
||||||
FF_DONTCARE | DEFAULT_PITCH, // PitchAndFamily
|
|
||||||
family.c_str() // FaceName
|
|
||||||
);
|
|
||||||
|
|
||||||
SelectObject(hDC, font);
|
|
||||||
|
|
||||||
if (!wglUseFontBitmaps(hDC, start, count, base))
|
|
||||||
CV_ERROR(CV_OpenGlApiCallError, "Can't create font");
|
|
||||||
|
|
||||||
__END__;
|
|
||||||
}
|
|
||||||
|
|
||||||
bool GlFuncTab_W32::isGlContextInitialized() const
|
|
||||||
{
|
|
||||||
return initialized;
|
|
||||||
}
|
|
||||||
|
|
||||||
void initGl(CvWindow* window)
|
|
||||||
{
|
|
||||||
glHint(GL_PERSPECTIVE_CORRECTION_HINT, GL_NICEST);
|
|
||||||
|
|
||||||
std::auto_ptr<GlFuncTab_W32> glFuncTab(new GlFuncTab_W32(window->dc));
|
|
||||||
|
|
||||||
// Load extensions
|
|
||||||
PROC func;
|
|
||||||
|
|
||||||
func = wglGetProcAddress("glGenBuffers");
|
|
||||||
glFuncTab->glGenBuffersExt = (PFNGLGENBUFFERSPROC)func;
|
|
||||||
|
|
||||||
func = wglGetProcAddress("glDeleteBuffers");
|
|
||||||
glFuncTab->glDeleteBuffersExt = (PFNGLDELETEBUFFERSPROC)func;
|
|
||||||
|
|
||||||
func = wglGetProcAddress("glBufferData");
|
|
||||||
glFuncTab->glBufferDataExt = (PFNGLBUFFERDATAPROC)func;
|
|
||||||
|
|
||||||
func = wglGetProcAddress("glBufferSubData");
|
|
||||||
glFuncTab->glBufferSubDataExt = (PFNGLBUFFERSUBDATAPROC)func;
|
|
||||||
|
|
||||||
func = wglGetProcAddress("glBindBuffer");
|
|
||||||
glFuncTab->glBindBufferExt = (PFNGLBINDBUFFERPROC)func;
|
|
||||||
|
|
||||||
func = wglGetProcAddress("glMapBuffer");
|
|
||||||
glFuncTab->glMapBufferExt = (PFNGLMAPBUFFERPROC)func;
|
|
||||||
|
|
||||||
func = wglGetProcAddress("glUnmapBuffer");
|
|
||||||
glFuncTab->glUnmapBufferExt = (PFNGLUNMAPBUFFERPROC)func;
|
|
||||||
|
|
||||||
glFuncTab->initialized = true;
|
|
||||||
|
|
||||||
window->glFuncTab = glFuncTab.release();
|
|
||||||
|
|
||||||
icvSetOpenGlFuncTab(window->glFuncTab);
|
|
||||||
}
|
|
||||||
|
|
||||||
void createGlContext(HWND hWnd, HDC& hGLDC, HGLRC& hGLRC, bool& useGl)
|
void createGlContext(HWND hWnd, HDC& hGLDC, HGLRC& hGLRC, bool& useGl)
|
||||||
{
|
{
|
||||||
CV_FUNCNAME( "createGlContext" );
|
CV_FUNCNAME( "createGlContext" );
|
||||||
@ -907,8 +638,6 @@ namespace
|
|||||||
|
|
||||||
__BEGIN__;
|
__BEGIN__;
|
||||||
|
|
||||||
delete window->glFuncTab;
|
|
||||||
|
|
||||||
if (window->hGLRC)
|
if (window->hGLRC)
|
||||||
{
|
{
|
||||||
wglDeleteContext(window->hGLRC);
|
wglDeleteContext(window->hGLRC);
|
||||||
@ -940,8 +669,6 @@ namespace
|
|||||||
if (window->glDrawCallback)
|
if (window->glDrawCallback)
|
||||||
window->glDrawCallback(window->glDrawData);
|
window->glDrawCallback(window->glDrawData);
|
||||||
|
|
||||||
CV_CheckGlError();
|
|
||||||
|
|
||||||
if (!SwapBuffers(window->dc))
|
if (!SwapBuffers(window->dc))
|
||||||
CV_ERROR( CV_OpenGlApiCallError, "Can't swap OpenGL buffers" );
|
CV_ERROR( CV_OpenGlApiCallError, "Can't swap OpenGL buffers" );
|
||||||
|
|
||||||
@ -1042,7 +769,6 @@ CV_IMPL int cvNamedWindow( const char* name, int flags )
|
|||||||
#ifndef HAVE_OPENGL
|
#ifndef HAVE_OPENGL
|
||||||
window->dc = CreateCompatibleDC(0);
|
window->dc = CreateCompatibleDC(0);
|
||||||
#else
|
#else
|
||||||
window->glFuncTab = 0;
|
|
||||||
if (!useGl)
|
if (!useGl)
|
||||||
{
|
{
|
||||||
window->dc = CreateCompatibleDC(0);
|
window->dc = CreateCompatibleDC(0);
|
||||||
@ -1054,14 +780,10 @@ CV_IMPL int cvNamedWindow( const char* name, int flags )
|
|||||||
window->dc = hGLDC;
|
window->dc = hGLDC;
|
||||||
window->hGLRC = hGLRC;
|
window->hGLRC = hGLRC;
|
||||||
window->useGl = true;
|
window->useGl = true;
|
||||||
initGl(window);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
window->glDrawCallback = 0;
|
window->glDrawCallback = 0;
|
||||||
window->glDrawData = 0;
|
window->glDrawData = 0;
|
||||||
|
|
||||||
window->glCleanCallback = 0;
|
|
||||||
window->glCleanData = 0;
|
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
window->last_key = 0;
|
window->last_key = 0;
|
||||||
@ -1112,8 +834,6 @@ CV_IMPL void cvSetOpenGlContext(const char* name)
|
|||||||
if (!wglMakeCurrent(window->dc, window->hGLRC))
|
if (!wglMakeCurrent(window->dc, window->hGLRC))
|
||||||
CV_ERROR( CV_OpenGlApiCallError, "Can't Activate The GL Rendering Context" );
|
CV_ERROR( CV_OpenGlApiCallError, "Can't Activate The GL Rendering Context" );
|
||||||
|
|
||||||
icvSetOpenGlFuncTab(window->glFuncTab);
|
|
||||||
|
|
||||||
__END__;
|
__END__;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -1161,30 +881,6 @@ CV_IMPL void cvSetOpenGlDrawCallback(const char* name, CvOpenGlDrawCallback call
|
|||||||
__END__;
|
__END__;
|
||||||
}
|
}
|
||||||
|
|
||||||
void icvSetOpenGlCleanCallback(const char* name, CvOpenGlCleanCallback callback, void* userdata)
|
|
||||||
{
|
|
||||||
CV_FUNCNAME( "icvSetOpenGlCleanCallback" );
|
|
||||||
|
|
||||||
__BEGIN__;
|
|
||||||
|
|
||||||
CvWindow* window;
|
|
||||||
|
|
||||||
if (!name)
|
|
||||||
CV_ERROR(CV_StsNullPtr, "NULL name string");
|
|
||||||
|
|
||||||
window = icvFindWindowByName(name);
|
|
||||||
if (!window)
|
|
||||||
EXIT;
|
|
||||||
|
|
||||||
if (window->glCleanCallback)
|
|
||||||
window->glCleanCallback(window->glCleanData);
|
|
||||||
|
|
||||||
window->glCleanCallback = callback;
|
|
||||||
window->glCleanData = userdata;
|
|
||||||
|
|
||||||
__END__;
|
|
||||||
}
|
|
||||||
|
|
||||||
#endif // HAVE_OPENGL
|
#endif // HAVE_OPENGL
|
||||||
|
|
||||||
static void icvRemoveWindow( CvWindow* window )
|
static void icvRemoveWindow( CvWindow* window )
|
||||||
@ -1194,18 +890,7 @@ static void icvRemoveWindow( CvWindow* window )
|
|||||||
|
|
||||||
#ifdef HAVE_OPENGL
|
#ifdef HAVE_OPENGL
|
||||||
if (window->useGl)
|
if (window->useGl)
|
||||||
{
|
|
||||||
wglMakeCurrent(window->dc, window->hGLRC);
|
|
||||||
|
|
||||||
if (window->glCleanCallback)
|
|
||||||
{
|
|
||||||
window->glCleanCallback(window->glCleanData);
|
|
||||||
window->glCleanCallback = 0;
|
|
||||||
window->glCleanData = 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
releaseGlContext(window);
|
releaseGlContext(window);
|
||||||
}
|
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
if( window->frame )
|
if( window->frame )
|
||||||
|
@ -1,353 +0,0 @@
|
|||||||
#include <cctype>
|
|
||||||
#include <cstring>
|
|
||||||
#include <cmath>
|
|
||||||
#include <iostream>
|
|
||||||
#include <sstream>
|
|
||||||
|
|
||||||
#include "opencv2/core/core.hpp"
|
|
||||||
#include "opencv2/core/opengl_interop.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;
|
|
||||||
using namespace cv::gpu;
|
|
||||||
|
|
||||||
class PointCloudRenderer
|
|
||||||
{
|
|
||||||
public:
|
|
||||||
PointCloudRenderer(const Mat& points, const Mat& img, double scale);
|
|
||||||
|
|
||||||
void onMouseEvent(int event, int x, int y, int flags);
|
|
||||||
void draw();
|
|
||||||
void update(int key, double aspect);
|
|
||||||
|
|
||||||
int fov_;
|
|
||||||
|
|
||||||
private:
|
|
||||||
int mouse_dx_;
|
|
||||||
int mouse_dy_;
|
|
||||||
|
|
||||||
double yaw_;
|
|
||||||
double pitch_;
|
|
||||||
Point3d pos_;
|
|
||||||
|
|
||||||
TickMeter tm_;
|
|
||||||
static const int step_;
|
|
||||||
int frame_;
|
|
||||||
|
|
||||||
GlCamera camera_;
|
|
||||||
GlArrays pointCloud_;
|
|
||||||
string fps_;
|
|
||||||
};
|
|
||||||
|
|
||||||
bool stop = false;
|
|
||||||
|
|
||||||
static void mouseCallback(int event, int x, int y, int flags, void* userdata)
|
|
||||||
{
|
|
||||||
if (stop)
|
|
||||||
return;
|
|
||||||
|
|
||||||
PointCloudRenderer* renderer = static_cast<PointCloudRenderer*>(userdata);
|
|
||||||
renderer->onMouseEvent(event, x, y, flags);
|
|
||||||
}
|
|
||||||
|
|
||||||
static void openGlDrawCallback(void* userdata)
|
|
||||||
{
|
|
||||||
if (stop)
|
|
||||||
return;
|
|
||||||
|
|
||||||
PointCloudRenderer* renderer = static_cast<PointCloudRenderer*>(userdata);
|
|
||||||
renderer->draw();
|
|
||||||
}
|
|
||||||
|
|
||||||
int main(int argc, const char* argv[])
|
|
||||||
{
|
|
||||||
const char* keys =
|
|
||||||
"{ l | left | | left image file name }"
|
|
||||||
"{ r | right | | right image file name }"
|
|
||||||
"{ i | intrinsic | | intrinsic camera parameters file name }"
|
|
||||||
"{ e | extrinsic | | extrinsic camera parameters file name }"
|
|
||||||
"{ d | ndisp | 256 | number of disparities }"
|
|
||||||
"{ s | scale | 1.0 | scale factor for point cloud }"
|
|
||||||
"{ h | help | false | print help message }";
|
|
||||||
|
|
||||||
CommandLineParser cmd(argc, argv, keys);
|
|
||||||
|
|
||||||
if (cmd.get<bool>("help"))
|
|
||||||
{
|
|
||||||
cout << "Avaible options:" << endl;
|
|
||||||
cmd.printParams();
|
|
||||||
return 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
string left = cmd.get<string>("left");
|
|
||||||
string right = cmd.get<string>("right");
|
|
||||||
string intrinsic = cmd.get<string>("intrinsic");
|
|
||||||
string extrinsic = cmd.get<string>("extrinsic");
|
|
||||||
int ndisp = cmd.get<int>("ndisp");
|
|
||||||
double scale = cmd.get<double>("scale");
|
|
||||||
|
|
||||||
if (left.empty() || right.empty())
|
|
||||||
{
|
|
||||||
cout << "Missed input images" << endl;
|
|
||||||
cout << "Avaible options:" << endl;
|
|
||||||
cmd.printParams();
|
|
||||||
return 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (intrinsic.empty() ^ extrinsic.empty())
|
|
||||||
{
|
|
||||||
cout << "Boss camera parameters must be specified" << endl;
|
|
||||||
cout << "Avaible options:" << endl;
|
|
||||||
cmd.printParams();
|
|
||||||
return 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
Mat imgLeftColor = imread(left, IMREAD_COLOR);
|
|
||||||
Mat imgRightColor = imread(right, IMREAD_COLOR);
|
|
||||||
|
|
||||||
if (imgLeftColor.empty())
|
|
||||||
{
|
|
||||||
cout << "Can't load image " << left << endl;
|
|
||||||
return -1;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (imgRightColor.empty())
|
|
||||||
{
|
|
||||||
cout << "Can't load image " << right << endl;
|
|
||||||
return -1;
|
|
||||||
}
|
|
||||||
|
|
||||||
Mat Q = Mat::eye(4, 4, CV_32F);
|
|
||||||
if (!intrinsic.empty() && !extrinsic.empty())
|
|
||||||
{
|
|
||||||
FileStorage fs;
|
|
||||||
|
|
||||||
// reading intrinsic parameters
|
|
||||||
fs.open(intrinsic, CV_STORAGE_READ);
|
|
||||||
if (!fs.isOpened())
|
|
||||||
{
|
|
||||||
cout << "Failed to open file " << intrinsic << endl;
|
|
||||||
return -1;
|
|
||||||
}
|
|
||||||
|
|
||||||
Mat M1, D1, M2, D2;
|
|
||||||
fs["M1"] >> M1;
|
|
||||||
fs["D1"] >> D1;
|
|
||||||
fs["M2"] >> M2;
|
|
||||||
fs["D2"] >> D2;
|
|
||||||
|
|
||||||
// reading extrinsic parameters
|
|
||||||
fs.open(extrinsic, CV_STORAGE_READ);
|
|
||||||
if (!fs.isOpened())
|
|
||||||
{
|
|
||||||
cout << "Failed to open file " << extrinsic << endl;
|
|
||||||
return -1;
|
|
||||||
}
|
|
||||||
|
|
||||||
Mat R, T, R1, P1, R2, P2;
|
|
||||||
fs["R"] >> R;
|
|
||||||
fs["T"] >> T;
|
|
||||||
|
|
||||||
Size img_size = imgLeftColor.size();
|
|
||||||
|
|
||||||
Rect roi1, roi2;
|
|
||||||
stereoRectify(M1, D1, M2, D2, img_size, R, T, R1, R2, P1, P2, Q, CALIB_ZERO_DISPARITY, -1, img_size, &roi1, &roi2);
|
|
||||||
|
|
||||||
Mat map11, map12, map21, map22;
|
|
||||||
initUndistortRectifyMap(M1, D1, R1, P1, img_size, CV_16SC2, map11, map12);
|
|
||||||
initUndistortRectifyMap(M2, D2, R2, P2, img_size, CV_16SC2, map21, map22);
|
|
||||||
|
|
||||||
Mat img1r, img2r;
|
|
||||||
remap(imgLeftColor, img1r, map11, map12, INTER_LINEAR);
|
|
||||||
remap(imgRightColor, img2r, map21, map22, INTER_LINEAR);
|
|
||||||
|
|
||||||
imgLeftColor = img1r(roi1);
|
|
||||||
imgRightColor = img2r(roi2);
|
|
||||||
}
|
|
||||||
|
|
||||||
Mat imgLeftGray, imgRightGray;
|
|
||||||
cvtColor(imgLeftColor, imgLeftGray, COLOR_BGR2GRAY);
|
|
||||||
cvtColor(imgRightColor, imgRightGray, COLOR_BGR2GRAY);
|
|
||||||
|
|
||||||
cvtColor(imgLeftColor, imgLeftColor, COLOR_BGR2RGB);
|
|
||||||
|
|
||||||
Mat disp, points;
|
|
||||||
|
|
||||||
StereoBM bm(0, ndisp);
|
|
||||||
|
|
||||||
bm(imgLeftGray, imgRightGray, disp);
|
|
||||||
disp.convertTo(disp, CV_8U, 1.0 / 16.0);
|
|
||||||
|
|
||||||
disp = disp(Range(21, disp.rows - 21), Range(ndisp, disp.cols - 21)).clone();
|
|
||||||
imgLeftColor = imgLeftColor(Range(21, imgLeftColor.rows - 21), Range(ndisp, imgLeftColor.cols - 21)).clone();
|
|
||||||
|
|
||||||
reprojectImageTo3D(disp, points, Q);
|
|
||||||
|
|
||||||
const string windowName = "OpenGL Sample";
|
|
||||||
|
|
||||||
namedWindow(windowName, WINDOW_OPENGL);
|
|
||||||
resizeWindow(windowName, 400, 400);
|
|
||||||
|
|
||||||
PointCloudRenderer renderer(points, imgLeftColor, scale);
|
|
||||||
|
|
||||||
createTrackbar("Fov", windowName, &renderer.fov_, 100);
|
|
||||||
setMouseCallback(windowName, mouseCallback, &renderer);
|
|
||||||
setOpenGlDrawCallback(windowName, openGlDrawCallback, &renderer);
|
|
||||||
|
|
||||||
for(;;)
|
|
||||||
{
|
|
||||||
int key = waitKey(10);
|
|
||||||
|
|
||||||
if (key >= 0)
|
|
||||||
key = key & 0xff;
|
|
||||||
|
|
||||||
if (key == 27)
|
|
||||||
{
|
|
||||||
stop = true;
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
|
|
||||||
double aspect = getWindowProperty(windowName, WND_PROP_ASPECT_RATIO);
|
|
||||||
|
|
||||||
key = tolower(key);
|
|
||||||
|
|
||||||
renderer.update(key, aspect);
|
|
||||||
|
|
||||||
updateWindow(windowName);
|
|
||||||
}
|
|
||||||
|
|
||||||
return 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
const int PointCloudRenderer::step_ = 20;
|
|
||||||
|
|
||||||
PointCloudRenderer::PointCloudRenderer(const Mat& points, const Mat& img, double scale)
|
|
||||||
{
|
|
||||||
mouse_dx_ = 0;
|
|
||||||
mouse_dy_ = 0;
|
|
||||||
|
|
||||||
fov_ = 0;
|
|
||||||
yaw_ = 0.0;
|
|
||||||
pitch_ = 0.0;
|
|
||||||
|
|
||||||
frame_ = 0;
|
|
||||||
|
|
||||||
camera_.setScale(Point3d(scale, scale, scale));
|
|
||||||
|
|
||||||
pointCloud_.setVertexArray(points);
|
|
||||||
pointCloud_.setColorArray(img, false);
|
|
||||||
|
|
||||||
tm_.start();
|
|
||||||
}
|
|
||||||
|
|
||||||
inline int clamp(int val, int minVal, int maxVal)
|
|
||||||
{
|
|
||||||
return max(min(val, maxVal), minVal);
|
|
||||||
}
|
|
||||||
|
|
||||||
void PointCloudRenderer::onMouseEvent(int event, int x, int y, int /*flags*/)
|
|
||||||
{
|
|
||||||
static int oldx = x;
|
|
||||||
static int oldy = y;
|
|
||||||
static bool moving = false;
|
|
||||||
|
|
||||||
if (event == EVENT_LBUTTONDOWN)
|
|
||||||
{
|
|
||||||
oldx = x;
|
|
||||||
oldy = y;
|
|
||||||
moving = true;
|
|
||||||
}
|
|
||||||
else if (event == EVENT_LBUTTONUP)
|
|
||||||
{
|
|
||||||
moving = false;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (moving)
|
|
||||||
{
|
|
||||||
mouse_dx_ = oldx - x;
|
|
||||||
mouse_dy_ = oldy - y;
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
mouse_dx_ = 0;
|
|
||||||
mouse_dy_ = 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
const int mouseClamp = 300;
|
|
||||||
mouse_dx_ = clamp(mouse_dx_, -mouseClamp, mouseClamp);
|
|
||||||
mouse_dy_ = clamp(mouse_dy_, -mouseClamp, mouseClamp);
|
|
||||||
}
|
|
||||||
|
|
||||||
static Point3d rotate(Point3d v, double yaw, double pitch)
|
|
||||||
{
|
|
||||||
Point3d t1;
|
|
||||||
t1.x = v.x * cos(-yaw / 180.0 * CV_PI) - v.z * sin(-yaw / 180.0 * CV_PI);
|
|
||||||
t1.y = v.y;
|
|
||||||
t1.z = v.x * sin(-yaw / 180.0 * CV_PI) + v.z * cos(-yaw / 180.0 * CV_PI);
|
|
||||||
|
|
||||||
Point3d t2;
|
|
||||||
t2.x = t1.x;
|
|
||||||
t2.y = t1.y * cos(pitch / 180.0 * CV_PI) - t1.z * sin(pitch / 180.0 * CV_PI);
|
|
||||||
t2.z = t1.y * sin(pitch / 180.0 * CV_PI) + t1.z * cos(pitch / 180.0 * CV_PI);
|
|
||||||
|
|
||||||
return t2;
|
|
||||||
}
|
|
||||||
|
|
||||||
void PointCloudRenderer::update(int key, double aspect)
|
|
||||||
{
|
|
||||||
const Point3d dirVec(0.0, 0.0, -1.0);
|
|
||||||
const Point3d upVec(0.0, 1.0, 0.0);
|
|
||||||
const Point3d leftVec(-1.0, 0.0, 0.0);
|
|
||||||
|
|
||||||
const double posStep = 0.1;
|
|
||||||
|
|
||||||
const double mouseStep = 0.001;
|
|
||||||
|
|
||||||
camera_.setPerspectiveProjection(30.0 + fov_ / 100.0 * 40.0, aspect, 0.1, 1000.0);
|
|
||||||
|
|
||||||
yaw_ += mouse_dx_ * mouseStep;
|
|
||||||
pitch_ += mouse_dy_ * mouseStep;
|
|
||||||
|
|
||||||
if (key == 'w')
|
|
||||||
pos_ += posStep * rotate(dirVec, yaw_, pitch_);
|
|
||||||
else if (key == 's')
|
|
||||||
pos_ -= posStep * rotate(dirVec, yaw_, pitch_);
|
|
||||||
else if (key == 'a')
|
|
||||||
pos_ += posStep * rotate(leftVec, yaw_, pitch_);
|
|
||||||
else if (key == 'd')
|
|
||||||
pos_ -= posStep * rotate(leftVec, yaw_, pitch_);
|
|
||||||
else if (key == 'q')
|
|
||||||
pos_ += posStep * rotate(upVec, yaw_, pitch_);
|
|
||||||
else if (key == 'e')
|
|
||||||
pos_ -= posStep * rotate(upVec, yaw_, pitch_);
|
|
||||||
|
|
||||||
camera_.setCameraPos(pos_, yaw_, pitch_, 0.0);
|
|
||||||
|
|
||||||
tm_.stop();
|
|
||||||
|
|
||||||
if (frame_++ >= step_)
|
|
||||||
{
|
|
||||||
ostringstream ostr;
|
|
||||||
ostr << "FPS: " << step_ / tm_.getTimeSec();
|
|
||||||
fps_ = ostr.str();
|
|
||||||
|
|
||||||
frame_ = 0;
|
|
||||||
tm_.reset();
|
|
||||||
}
|
|
||||||
|
|
||||||
tm_.start();
|
|
||||||
}
|
|
||||||
|
|
||||||
void PointCloudRenderer::draw()
|
|
||||||
{
|
|
||||||
camera_.setupProjectionMatrix();
|
|
||||||
camera_.setupModelViewMatrix();
|
|
||||||
|
|
||||||
render(pointCloud_);
|
|
||||||
|
|
||||||
render(fps_, GlFont::get("Courier New", 16), Scalar::all(255), Point2d(3.0, 0.0));
|
|
||||||
}
|
|
@ -4,7 +4,6 @@
|
|||||||
|
|
||||||
#include "cvconfig.h"
|
#include "cvconfig.h"
|
||||||
#include "opencv2/core/core.hpp"
|
#include "opencv2/core/core.hpp"
|
||||||
#include "opencv2/core/opengl_interop.hpp"
|
|
||||||
#include "opencv2/highgui/highgui.hpp"
|
#include "opencv2/highgui/highgui.hpp"
|
||||||
#include "opencv2/gpu/gpu.hpp"
|
#include "opencv2/gpu/gpu.hpp"
|
||||||
|
|
||||||
@ -14,12 +13,6 @@ using namespace cv::gpu;
|
|||||||
|
|
||||||
void getFlowField(const Mat& u, const Mat& v, Mat& flowField);
|
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[])
|
int main(int argc, const char* argv[])
|
||||||
{
|
{
|
||||||
try
|
try
|
||||||
@ -80,12 +73,8 @@ int main(int argc, const char* argv[])
|
|||||||
namedWindow("Forward flow");
|
namedWindow("Forward flow");
|
||||||
namedWindow("Backward flow");
|
namedWindow("Backward flow");
|
||||||
|
|
||||||
namedWindow("Needle Map", WINDOW_OPENGL);
|
|
||||||
|
|
||||||
namedWindow("Interpolated frame");
|
namedWindow("Interpolated frame");
|
||||||
|
|
||||||
setGlDevice();
|
|
||||||
|
|
||||||
cout << "Press:" << endl;
|
cout << "Press:" << endl;
|
||||||
cout << "\tESC to quit" << endl;
|
cout << "\tESC to quit" << endl;
|
||||||
cout << "\t'a' to move to the previous frame" << endl;
|
cout << "\t'a' to move to the previous frame" << endl;
|
||||||
@ -124,14 +113,6 @@ int main(int argc, const char* argv[])
|
|||||||
Mat flowFieldBackward;
|
Mat flowFieldBackward;
|
||||||
getFlowField(Mat(d_bu), Mat(d_bv), 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;
|
cout << "Interpolating..." << endl;
|
||||||
|
|
||||||
// first frame color components
|
// first frame color components
|
||||||
@ -196,14 +177,6 @@ int main(int argc, const char* argv[])
|
|||||||
imshow("Forward flow", flowFieldForward);
|
imshow("Forward flow", flowFieldForward);
|
||||||
imshow("Backward flow", flowFieldBackward);
|
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;
|
int currentFrame = 0;
|
||||||
|
|
||||||
imshow("Interpolated frame", frames[currentFrame]);
|
imshow("Interpolated frame", frames[currentFrame]);
|
||||||
@ -292,22 +265,4 @@ void getFlowField(const Mat& u, const Mat& v, Mat& flowField)
|
|||||||
row[j][3] = 255;
|
row[j][3] = 255;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
#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
|
|
@ -1,135 +0,0 @@
|
|||||||
#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;
|
|
||||||
}
|
|
125
samples/gpu/opengl.cpp
Normal file
125
samples/gpu/opengl.cpp
Normal file
@ -0,0 +1,125 @@
|
|||||||
|
#include <iostream>
|
||||||
|
#include "cvconfig.h"
|
||||||
|
|
||||||
|
#ifndef HAVE_OPENGL
|
||||||
|
int main()
|
||||||
|
{
|
||||||
|
std::cerr << "Library was built without OpenGL support" << std::endl;
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
|
#else
|
||||||
|
|
||||||
|
#ifdef WIN32
|
||||||
|
#define WIN32_LEAN_AND_MEAN 1
|
||||||
|
#define NOMINMAX 1
|
||||||
|
#include <windows.h>
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#if defined(__APPLE__)
|
||||||
|
#include <OpenGL/gl.h>
|
||||||
|
#include <OpenGL/glu.h>
|
||||||
|
#else
|
||||||
|
#include <GL/gl.h>
|
||||||
|
#include <GL/glu.h>
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#include "opencv2/core/core.hpp"
|
||||||
|
#include "opencv2/core/opengl_interop.hpp"
|
||||||
|
#include "opencv2/core/gpumat.hpp"
|
||||||
|
#include "opencv2/highgui/highgui.hpp"
|
||||||
|
|
||||||
|
using namespace std;
|
||||||
|
using namespace cv;
|
||||||
|
using namespace cv::gpu;
|
||||||
|
|
||||||
|
const int win_width = 800;
|
||||||
|
const int win_height = 640;
|
||||||
|
|
||||||
|
struct DrawData
|
||||||
|
{
|
||||||
|
GlArrays arr;
|
||||||
|
GlTexture tex;
|
||||||
|
GlBuffer indices;
|
||||||
|
};
|
||||||
|
|
||||||
|
void CV_CDECL draw(void* userdata);
|
||||||
|
|
||||||
|
void CV_CDECL draw(void* userdata)
|
||||||
|
{
|
||||||
|
static double angle = 0.0;
|
||||||
|
|
||||||
|
DrawData* data = static_cast<DrawData*>(userdata);
|
||||||
|
|
||||||
|
glMatrixMode(GL_PROJECTION);
|
||||||
|
glLoadIdentity();
|
||||||
|
gluPerspective(45.0, (double)win_width / win_height, 0.1, 100.0);
|
||||||
|
|
||||||
|
glMatrixMode(GL_MODELVIEW);
|
||||||
|
glLoadIdentity();
|
||||||
|
gluLookAt(0, 0, 3, 0, 0, 0, 0, 1, 0);
|
||||||
|
glRotated(angle, 0, 1, 0);
|
||||||
|
|
||||||
|
glEnable(GL_TEXTURE_2D);
|
||||||
|
data->tex.bind();
|
||||||
|
|
||||||
|
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
|
||||||
|
glTexEnvi(GL_TEXTURE_2D, GL_TEXTURE_ENV_MODE, GL_REPLACE);
|
||||||
|
|
||||||
|
glDisable(GL_CULL_FACE);
|
||||||
|
|
||||||
|
render(data->arr, data->indices, RenderMode::TRIANGLES);
|
||||||
|
|
||||||
|
angle += 0.3;
|
||||||
|
}
|
||||||
|
|
||||||
|
int main(int argc, char* argv[])
|
||||||
|
{
|
||||||
|
if (argc < 2)
|
||||||
|
{
|
||||||
|
cout << "Usage: " << argv[0] << " image" << endl;
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
|
|
||||||
|
Mat img = imread(argv[1]);
|
||||||
|
if (img.empty())
|
||||||
|
{
|
||||||
|
cerr << "Can't open image " << argv[1] << endl;
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
|
|
||||||
|
namedWindow("OpenGL", WINDOW_OPENGL);
|
||||||
|
resizeWindow("OpenGL", win_width, win_height);
|
||||||
|
|
||||||
|
Mat_<Vec2f> vertex(1, 4);
|
||||||
|
vertex << Vec2f(-1, 1), Vec2f(-1, -1), Vec2f(1, -1), Vec2f(1, 1);
|
||||||
|
|
||||||
|
Mat_<Vec2f> texCoords(1, 4);
|
||||||
|
texCoords << Vec2f(0, 0), Vec2f(0, 1), Vec2f(1, 1), Vec2f(1, 0);
|
||||||
|
|
||||||
|
Mat_<int> indices(1, 6);
|
||||||
|
indices << 0, 1, 2, 2, 3, 0;
|
||||||
|
|
||||||
|
DrawData data;
|
||||||
|
|
||||||
|
data.arr.setVertexArray(vertex);
|
||||||
|
data.arr.setTexCoordArray(texCoords);
|
||||||
|
data.indices.copyFrom(indices);
|
||||||
|
data.tex.copyFrom(img);
|
||||||
|
|
||||||
|
setOpenGlDrawCallback("OpenGL", draw, &data);
|
||||||
|
|
||||||
|
for (;;)
|
||||||
|
{
|
||||||
|
updateWindow("OpenGL");
|
||||||
|
int key = waitKey(10);
|
||||||
|
if ((key & 0xff) == 27)
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
|
setOpenGlDrawCallback("OpenGL", 0, 0);
|
||||||
|
destroyAllWindows();
|
||||||
|
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
#endif
|
@ -3,7 +3,6 @@
|
|||||||
|
|
||||||
#include "cvconfig.h"
|
#include "cvconfig.h"
|
||||||
#include "opencv2/core/core.hpp"
|
#include "opencv2/core/core.hpp"
|
||||||
#include "opencv2/core/opengl_interop.hpp"
|
|
||||||
#include "opencv2/imgproc/imgproc.hpp"
|
#include "opencv2/imgproc/imgproc.hpp"
|
||||||
#include "opencv2/highgui/highgui.hpp"
|
#include "opencv2/highgui/highgui.hpp"
|
||||||
#include "opencv2/video/video.hpp"
|
#include "opencv2/video/video.hpp"
|
||||||
@ -66,40 +65,6 @@ static void drawArrows(Mat& frame, const vector<Point2f>& prevPts, const vector<
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
#ifdef HAVE_OPENGL
|
|
||||||
|
|
||||||
struct DrawData
|
|
||||||
{
|
|
||||||
GlTexture tex;
|
|
||||||
GlArrays arr;
|
|
||||||
};
|
|
||||||
|
|
||||||
static void drawCallback(void* userdata)
|
|
||||||
{
|
|
||||||
DrawData* data = static_cast<DrawData*>(userdata);
|
|
||||||
|
|
||||||
if (data->tex.empty() || data->arr.empty())
|
|
||||||
return;
|
|
||||||
|
|
||||||
static GlCamera camera;
|
|
||||||
static bool init_camera = true;
|
|
||||||
|
|
||||||
if (init_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));
|
|
||||||
init_camera = false;
|
|
||||||
}
|
|
||||||
|
|
||||||
camera.setupProjectionMatrix();
|
|
||||||
camera.setupModelViewMatrix();
|
|
||||||
|
|
||||||
render(data->tex);
|
|
||||||
render(data->arr, RenderMode::TRIANGLES);
|
|
||||||
}
|
|
||||||
|
|
||||||
#endif
|
|
||||||
|
|
||||||
template <typename T> inline T clamp (T x, T a, T b)
|
template <typename T> inline T clamp (T x, T a, T b)
|
||||||
{
|
{
|
||||||
return ((x) > (a) ? ((x) < (b) ? (x) : (b)) : (a));
|
return ((x) > (a) ? ((x) < (b) ? (x) : (b)) : (a));
|
||||||
@ -200,12 +165,6 @@ int main(int argc, const char* argv[])
|
|||||||
namedWindow("PyrLK [Sparse]", WINDOW_NORMAL);
|
namedWindow("PyrLK [Sparse]", WINDOW_NORMAL);
|
||||||
namedWindow("PyrLK [Dense] Flow Field", WINDOW_NORMAL);
|
namedWindow("PyrLK [Dense] Flow Field", WINDOW_NORMAL);
|
||||||
|
|
||||||
#ifdef HAVE_OPENGL
|
|
||||||
namedWindow("PyrLK [Dense]", WINDOW_OPENGL);
|
|
||||||
|
|
||||||
setGlDevice();
|
|
||||||
#endif
|
|
||||||
|
|
||||||
cout << "Image size : " << frame0.cols << " x " << frame0.rows << endl;
|
cout << "Image size : " << frame0.cols << " x " << frame0.rows << endl;
|
||||||
cout << "Points count : " << points << endl;
|
cout << "Points count : " << points << endl;
|
||||||
|
|
||||||
@ -271,21 +230,6 @@ int main(int argc, const char* argv[])
|
|||||||
|
|
||||||
imshow("PyrLK [Dense] Flow Field", flowField);
|
imshow("PyrLK [Dense] Flow Field", flowField);
|
||||||
|
|
||||||
#ifdef HAVE_OPENGL
|
|
||||||
setOpenGlContext("PyrLK [Dense]");
|
|
||||||
|
|
||||||
GpuMat d_vertex, d_colors;
|
|
||||||
createOpticalFlowNeedleMap(d_u, d_v, d_vertex, d_colors);
|
|
||||||
|
|
||||||
DrawData drawData;
|
|
||||||
|
|
||||||
drawData.tex.copyFrom(d_frame0Gray);
|
|
||||||
drawData.arr.setVertexArray(d_vertex);
|
|
||||||
drawData.arr.setColorArray(d_colors, false);
|
|
||||||
|
|
||||||
setOpenGlDrawCallback("PyrLK [Dense]", drawCallback, &drawData);
|
|
||||||
#endif
|
|
||||||
|
|
||||||
waitKey();
|
waitKey();
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
|
Loading…
x
Reference in New Issue
Block a user