Merge pull request #502 from jet47:opengl-updates
commit
afa993316f
23 changed files with 6574 additions and 2920 deletions
@ -0,0 +1,330 @@ |
|||||||
|
/*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.
|
||||||
|
//
|
||||||
|
//
|
||||||
|
// License Agreement
|
||||||
|
// For Open Source Computer Vision Library
|
||||||
|
//
|
||||||
|
// Copyright (C) 2000-2008, Intel Corporation, all rights reserved.
|
||||||
|
// Copyright (C) 2009, Willow Garage Inc., 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 GpuMaterials provided with the distribution.
|
||||||
|
//
|
||||||
|
// * The name of the copyright holders 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*/
|
||||||
|
|
||||||
|
#ifndef __OPENCV_OPENGL_INTEROP_DEPRECATED_HPP__ |
||||||
|
#define __OPENCV_OPENGL_INTEROP_DEPRECATED_HPP__ |
||||||
|
|
||||||
|
#ifdef __cplusplus |
||||||
|
|
||||||
|
#include "opencv2/core/core.hpp" |
||||||
|
|
||||||
|
namespace cv |
||||||
|
{ |
||||||
|
//! Smart pointer for OpenGL buffer memory with reference counting.
|
||||||
|
class CV_EXPORTS GlBuffer |
||||||
|
{ |
||||||
|
public: |
||||||
|
enum Usage |
||||||
|
{ |
||||||
|
ARRAY_BUFFER = 0x8892, // buffer will use for OpenGL arrays (vertices, colors, normals, etc)
|
||||||
|
TEXTURE_BUFFER = 0x88EC // buffer will ise for OpenGL textures
|
||||||
|
}; |
||||||
|
|
||||||
|
//! create empty buffer
|
||||||
|
explicit GlBuffer(Usage usage); |
||||||
|
|
||||||
|
//! create buffer
|
||||||
|
GlBuffer(int rows, int cols, int type, Usage usage); |
||||||
|
GlBuffer(Size size, int type, Usage usage); |
||||||
|
|
||||||
|
//! copy from host/device memory
|
||||||
|
GlBuffer(InputArray mat, Usage usage); |
||||||
|
|
||||||
|
void create(int rows, int cols, int type, Usage usage); |
||||||
|
void create(Size size, int type, Usage usage); |
||||||
|
void create(int rows, int cols, int type); |
||||||
|
void create(Size size, int type); |
||||||
|
|
||||||
|
void release(); |
||||||
|
|
||||||
|
//! copy from host/device memory
|
||||||
|
void copyFrom(InputArray mat); |
||||||
|
|
||||||
|
void bind() const; |
||||||
|
void unbind() const; |
||||||
|
|
||||||
|
//! map to host memory
|
||||||
|
Mat mapHost(); |
||||||
|
void unmapHost(); |
||||||
|
|
||||||
|
//! map to device memory
|
||||||
|
gpu::GpuMat mapDevice(); |
||||||
|
void unmapDevice(); |
||||||
|
|
||||||
|
inline int rows() const { return rows_; } |
||||||
|
inline int cols() const { return cols_; } |
||||||
|
inline Size size() const { return Size(cols_, rows_); } |
||||||
|
inline bool empty() const { return rows_ == 0 || cols_ == 0; } |
||||||
|
|
||||||
|
inline int type() const { return type_; } |
||||||
|
inline int depth() const { return CV_MAT_DEPTH(type_); } |
||||||
|
inline int channels() const { return CV_MAT_CN(type_); } |
||||||
|
inline int elemSize() const { return CV_ELEM_SIZE(type_); } |
||||||
|
inline int elemSize1() const { return CV_ELEM_SIZE1(type_); } |
||||||
|
|
||||||
|
inline Usage usage() const { return usage_; } |
||||||
|
|
||||||
|
class Impl; |
||||||
|
private: |
||||||
|
int rows_; |
||||||
|
int cols_; |
||||||
|
int type_; |
||||||
|
Usage usage_; |
||||||
|
|
||||||
|
Ptr<Impl> impl_; |
||||||
|
}; |
||||||
|
|
||||||
|
template <> CV_EXPORTS void Ptr<GlBuffer::Impl>::delete_obj(); |
||||||
|
|
||||||
|
//! Smart pointer for OpenGL 2d texture memory with reference counting.
|
||||||
|
class CV_EXPORTS GlTexture |
||||||
|
{ |
||||||
|
public: |
||||||
|
//! create empty texture
|
||||||
|
GlTexture(); |
||||||
|
|
||||||
|
//! create texture
|
||||||
|
GlTexture(int rows, int cols, int type); |
||||||
|
GlTexture(Size size, int type); |
||||||
|
|
||||||
|
//! copy from host/device memory
|
||||||
|
explicit GlTexture(InputArray mat, bool bgra = true); |
||||||
|
|
||||||
|
void create(int rows, int cols, int type); |
||||||
|
void create(Size size, int type); |
||||||
|
void release(); |
||||||
|
|
||||||
|
//! copy from host/device memory
|
||||||
|
void copyFrom(InputArray mat, bool bgra = true); |
||||||
|
|
||||||
|
void bind() const; |
||||||
|
void unbind() const; |
||||||
|
|
||||||
|
inline int rows() const { return rows_; } |
||||||
|
inline int cols() const { return cols_; } |
||||||
|
inline Size size() const { return Size(cols_, rows_); } |
||||||
|
inline bool empty() const { return rows_ == 0 || cols_ == 0; } |
||||||
|
|
||||||
|
inline int type() const { return type_; } |
||||||
|
inline int depth() const { return CV_MAT_DEPTH(type_); } |
||||||
|
inline int channels() const { return CV_MAT_CN(type_); } |
||||||
|
inline int elemSize() const { return CV_ELEM_SIZE(type_); } |
||||||
|
inline int elemSize1() const { return CV_ELEM_SIZE1(type_); } |
||||||
|
|
||||||
|
class Impl; |
||||||
|
private: |
||||||
|
int rows_; |
||||||
|
int cols_; |
||||||
|
int type_; |
||||||
|
|
||||||
|
Ptr<Impl> impl_; |
||||||
|
GlBuffer buf_; |
||||||
|
}; |
||||||
|
|
||||||
|
template <> CV_EXPORTS void Ptr<GlTexture::Impl>::delete_obj(); |
||||||
|
|
||||||
|
//! OpenGL Arrays
|
||||||
|
class CV_EXPORTS GlArrays |
||||||
|
{ |
||||||
|
public: |
||||||
|
inline GlArrays() |
||||||
|
: vertex_(GlBuffer::ARRAY_BUFFER), color_(GlBuffer::ARRAY_BUFFER), bgra_(true), normal_(GlBuffer::ARRAY_BUFFER), texCoord_(GlBuffer::ARRAY_BUFFER) |
||||||
|
{ |
||||||
|
} |
||||||
|
|
||||||
|
void setVertexArray(InputArray vertex); |
||||||
|
inline void resetVertexArray() { vertex_.release(); } |
||||||
|
|
||||||
|
void setColorArray(InputArray color, bool bgra = true); |
||||||
|
inline void resetColorArray() { color_.release(); } |
||||||
|
|
||||||
|
void setNormalArray(InputArray normal); |
||||||
|
inline void resetNormalArray() { normal_.release(); } |
||||||
|
|
||||||
|
void setTexCoordArray(InputArray texCoord); |
||||||
|
inline void resetTexCoordArray() { texCoord_.release(); } |
||||||
|
|
||||||
|
void bind() const; |
||||||
|
void unbind() const; |
||||||
|
|
||||||
|
inline int rows() const { return vertex_.rows(); } |
||||||
|
inline int cols() const { return vertex_.cols(); } |
||||||
|
inline Size size() const { return vertex_.size(); } |
||||||
|
inline bool empty() const { return vertex_.empty(); } |
||||||
|
|
||||||
|
private: |
||||||
|
GlBuffer vertex_; |
||||||
|
GlBuffer color_; |
||||||
|
bool bgra_; |
||||||
|
GlBuffer normal_; |
||||||
|
GlBuffer texCoord_; |
||||||
|
}; |
||||||
|
|
||||||
|
//! OpenGL Font
|
||||||
|
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
|
||||||
|
CV_EXPORTS void render(const GlTexture& tex, |
||||||
|
Rect_<double> wndRect = Rect_<double>(0.0, 0.0, 1.0, 1.0), |
||||||
|
Rect_<double> texRect = Rect_<double>(0.0, 0.0, 1.0, 1.0)); |
||||||
|
|
||||||
|
//! render mode
|
||||||
|
namespace RenderMode { |
||||||
|
enum { |
||||||
|
POINTS = 0x0000, |
||||||
|
LINES = 0x0001, |
||||||
|
LINE_LOOP = 0x0002, |
||||||
|
LINE_STRIP = 0x0003, |
||||||
|
TRIANGLES = 0x0004, |
||||||
|
TRIANGLE_STRIP = 0x0005, |
||||||
|
TRIANGLE_FAN = 0x0006, |
||||||
|
QUADS = 0x0007, |
||||||
|
QUAD_STRIP = 0x0008, |
||||||
|
POLYGON = 0x0009 |
||||||
|
}; |
||||||
|
} |
||||||
|
|
||||||
|
//! render OpenGL arrays
|
||||||
|
CV_EXPORTS void render(const GlArrays& arr, int mode = RenderMode::POINTS, Scalar color = Scalar::all(255)); |
||||||
|
|
||||||
|
CV_EXPORTS void render(const std::string& str, const Ptr<GlFont>& font, Scalar color, Point2d pos); |
||||||
|
|
||||||
|
//! 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 cv
|
||||||
|
|
||||||
|
#endif // __cplusplus
|
||||||
|
|
||||||
|
#endif // __OPENCV_OPENGL_INTEROP_DEPRECATED_HPP__
|
File diff suppressed because it is too large
Load Diff
File diff suppressed because it is too large
Load Diff
File diff suppressed because it is too large
Load Diff
@ -0,0 +1,331 @@ |
|||||||
|
/*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.
|
||||||
|
//
|
||||||
|
//
|
||||||
|
// License Agreement
|
||||||
|
// For Open Source Computer Vision Library
|
||||||
|
//
|
||||||
|
// Copyright (C) 2000-2008, Intel Corporation, all rights reserved.
|
||||||
|
// Copyright (C) 2009, Willow Garage Inc., 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 the copyright holders 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 "precomp.hpp" |
||||||
|
#include "opencv2/core/opengl_interop_deprecated.hpp" |
||||||
|
#include "opencv2/core/gpumat.hpp" |
||||||
|
|
||||||
|
using namespace std; |
||||||
|
using namespace cv; |
||||||
|
using namespace cv::gpu; |
||||||
|
|
||||||
|
CvOpenGlFuncTab::~CvOpenGlFuncTab() |
||||||
|
{ |
||||||
|
} |
||||||
|
|
||||||
|
void icvSetOpenGlFuncTab(const CvOpenGlFuncTab*) |
||||||
|
{ |
||||||
|
CV_Error(CV_StsNotImplemented, "This function in deprecated, do not use it"); |
||||||
|
} |
||||||
|
|
||||||
|
////////////////////////////////////////////////////////////////////////
|
||||||
|
// GlBuffer
|
||||||
|
|
||||||
|
class cv::GlBuffer::Impl |
||||||
|
{ |
||||||
|
}; |
||||||
|
|
||||||
|
cv::GlBuffer::GlBuffer(Usage _usage) : rows_(0), cols_(0), type_(0), usage_(_usage) |
||||||
|
{ |
||||||
|
CV_Error(CV_StsNotImplemented, "This function in deprecated, do not use it"); |
||||||
|
} |
||||||
|
|
||||||
|
cv::GlBuffer::GlBuffer(int, int, int, Usage _usage) : rows_(0), cols_(0), type_(0), usage_(_usage) |
||||||
|
{ |
||||||
|
CV_Error(CV_StsNotImplemented, "This function in deprecated, do not use it"); |
||||||
|
} |
||||||
|
|
||||||
|
cv::GlBuffer::GlBuffer(Size, int, Usage _usage) : rows_(0), cols_(0), type_(0), usage_(_usage) |
||||||
|
{ |
||||||
|
CV_Error(CV_StsNotImplemented, "This function in deprecated, do not use it"); |
||||||
|
} |
||||||
|
|
||||||
|
cv::GlBuffer::GlBuffer(InputArray, Usage _usage) : rows_(0), cols_(0), type_(0), usage_(_usage) |
||||||
|
{ |
||||||
|
CV_Error(CV_StsNotImplemented, "This function in deprecated, do not use it"); |
||||||
|
} |
||||||
|
|
||||||
|
void cv::GlBuffer::create(int, int, int, Usage) |
||||||
|
{ |
||||||
|
CV_Error(CV_StsNotImplemented, "This function in deprecated, do not use it"); |
||||||
|
} |
||||||
|
|
||||||
|
void cv::GlBuffer::release() |
||||||
|
{ |
||||||
|
} |
||||||
|
|
||||||
|
void cv::GlBuffer::copyFrom(InputArray) |
||||||
|
{ |
||||||
|
CV_Error(CV_StsNotImplemented, "This function in deprecated, do not use it"); |
||||||
|
} |
||||||
|
|
||||||
|
void cv::GlBuffer::bind() const |
||||||
|
{ |
||||||
|
CV_Error(CV_StsNotImplemented, "This function in deprecated, do not use it"); |
||||||
|
} |
||||||
|
|
||||||
|
void cv::GlBuffer::unbind() const |
||||||
|
{ |
||||||
|
CV_Error(CV_StsNotImplemented, "This function in deprecated, do not use it"); |
||||||
|
} |
||||||
|
|
||||||
|
Mat cv::GlBuffer::mapHost() |
||||||
|
{ |
||||||
|
CV_Error(CV_StsNotImplemented, "This function in deprecated, do not use it"); |
||||||
|
return Mat(); |
||||||
|
} |
||||||
|
|
||||||
|
void cv::GlBuffer::unmapHost() |
||||||
|
{ |
||||||
|
CV_Error(CV_StsNotImplemented, "This function in deprecated, do not use it"); |
||||||
|
} |
||||||
|
|
||||||
|
GpuMat cv::GlBuffer::mapDevice() |
||||||
|
{ |
||||||
|
CV_Error(CV_StsNotImplemented, "This function in deprecated, do not use it"); |
||||||
|
return GpuMat(); |
||||||
|
} |
||||||
|
|
||||||
|
void cv::GlBuffer::unmapDevice() |
||||||
|
{ |
||||||
|
CV_Error(CV_StsNotImplemented, "This function in deprecated, do not use it"); |
||||||
|
} |
||||||
|
|
||||||
|
template <> void cv::Ptr<cv::GlBuffer::Impl>::delete_obj() |
||||||
|
{ |
||||||
|
if (obj) delete obj; |
||||||
|
} |
||||||
|
|
||||||
|
//////////////////////////////////////////////////////////////////////////////////////////
|
||||||
|
// GlTexture
|
||||||
|
|
||||||
|
class cv::GlTexture::Impl |
||||||
|
{ |
||||||
|
}; |
||||||
|
|
||||||
|
cv::GlTexture::GlTexture() : rows_(0), cols_(0), type_(0), buf_(GlBuffer::TEXTURE_BUFFER) |
||||||
|
{ |
||||||
|
CV_Error(CV_StsNotImplemented, "This function in deprecated, do not use it"); |
||||||
|
} |
||||||
|
|
||||||
|
cv::GlTexture::GlTexture(int, int, int) : rows_(0), cols_(0), type_(0), buf_(GlBuffer::TEXTURE_BUFFER) |
||||||
|
{ |
||||||
|
CV_Error(CV_StsNotImplemented, "This function in deprecated, do not use it"); |
||||||
|
} |
||||||
|
|
||||||
|
cv::GlTexture::GlTexture(Size, int) : rows_(0), cols_(0), type_(0), buf_(GlBuffer::TEXTURE_BUFFER) |
||||||
|
{ |
||||||
|
CV_Error(CV_StsNotImplemented, "This function in deprecated, do not use it"); |
||||||
|
} |
||||||
|
|
||||||
|
cv::GlTexture::GlTexture(InputArray, bool) : rows_(0), cols_(0), type_(0), buf_(GlBuffer::TEXTURE_BUFFER) |
||||||
|
{ |
||||||
|
CV_Error(CV_StsNotImplemented, "This function in deprecated, do not use it"); |
||||||
|
} |
||||||
|
|
||||||
|
void cv::GlTexture::create(int, int, int) |
||||||
|
{ |
||||||
|
CV_Error(CV_StsNotImplemented, "This function in deprecated, do not use it"); |
||||||
|
} |
||||||
|
|
||||||
|
void cv::GlTexture::release() |
||||||
|
{ |
||||||
|
} |
||||||
|
|
||||||
|
void cv::GlTexture::copyFrom(InputArray, bool) |
||||||
|
{ |
||||||
|
CV_Error(CV_StsNotImplemented, "This function in deprecated, do not use it"); |
||||||
|
} |
||||||
|
|
||||||
|
void cv::GlTexture::bind() const |
||||||
|
{ |
||||||
|
CV_Error(CV_StsNotImplemented, "This function in deprecated, do not use it"); |
||||||
|
} |
||||||
|
|
||||||
|
void cv::GlTexture::unbind() const |
||||||
|
{ |
||||||
|
CV_Error(CV_StsNotImplemented, "This function in deprecated, do not use it"); |
||||||
|
} |
||||||
|
|
||||||
|
template <> void cv::Ptr<cv::GlTexture::Impl>::delete_obj() |
||||||
|
{ |
||||||
|
if (obj) delete obj; |
||||||
|
} |
||||||
|
|
||||||
|
////////////////////////////////////////////////////////////////////////
|
||||||
|
// GlArrays
|
||||||
|
|
||||||
|
void cv::GlArrays::setVertexArray(InputArray) |
||||||
|
{ |
||||||
|
CV_Error(CV_StsNotImplemented, "This function in deprecated, do not use it"); |
||||||
|
} |
||||||
|
|
||||||
|
void cv::GlArrays::setColorArray(InputArray, bool) |
||||||
|
{ |
||||||
|
CV_Error(CV_StsNotImplemented, "This function in deprecated, do not use it"); |
||||||
|
} |
||||||
|
|
||||||
|
void cv::GlArrays::setNormalArray(InputArray) |
||||||
|
{ |
||||||
|
CV_Error(CV_StsNotImplemented, "This function in deprecated, do not use it"); |
||||||
|
} |
||||||
|
|
||||||
|
void cv::GlArrays::setTexCoordArray(InputArray) |
||||||
|
{ |
||||||
|
CV_Error(CV_StsNotImplemented, "This function in deprecated, do not use it"); |
||||||
|
} |
||||||
|
|
||||||
|
void cv::GlArrays::bind() const |
||||||
|
{ |
||||||
|
CV_Error(CV_StsNotImplemented, "This function in deprecated, do not use it"); |
||||||
|
} |
||||||
|
|
||||||
|
void cv::GlArrays::unbind() const |
||||||
|
{ |
||||||
|
CV_Error(CV_StsNotImplemented, "This function in deprecated, do not use it"); |
||||||
|
} |
||||||
|
|
||||||
|
////////////////////////////////////////////////////////////////////////
|
||||||
|
// GlFont
|
||||||
|
|
||||||
|
cv::GlFont::GlFont(const string& _family, int _height, Weight _weight, Style _style) |
||||||
|
: family_(_family), height_(_height), weight_(_weight), style_(_style), base_(0) |
||||||
|
{ |
||||||
|
CV_Error(CV_StsNotImplemented, "This function in deprecated, do not use it"); |
||||||
|
} |
||||||
|
|
||||||
|
void cv::GlFont::draw(const char*, int) const |
||||||
|
{ |
||||||
|
CV_Error(CV_StsNotImplemented, "This function in deprecated, do not use it"); |
||||||
|
} |
||||||
|
|
||||||
|
Ptr<GlFont> cv::GlFont::get(const std::string&, int, Weight, Style) |
||||||
|
{ |
||||||
|
CV_Error(CV_StsNotImplemented, "This function in deprecated, do not use it"); |
||||||
|
return Ptr<GlFont>(); |
||||||
|
} |
||||||
|
|
||||||
|
////////////////////////////////////////////////////////////////////////
|
||||||
|
// Rendering
|
||||||
|
|
||||||
|
void cv::render(const GlTexture&, Rect_<double>, Rect_<double>) |
||||||
|
{ |
||||||
|
CV_Error(CV_StsNotImplemented, "This function in deprecated, do not use it"); |
||||||
|
} |
||||||
|
|
||||||
|
void cv::render(const GlArrays&, int, Scalar) |
||||||
|
{ |
||||||
|
CV_Error(CV_StsNotImplemented, "This function in deprecated, do not use it"); |
||||||
|
} |
||||||
|
|
||||||
|
void cv::render(const string&, const Ptr<GlFont>&, Scalar, Point2d) |
||||||
|
{ |
||||||
|
CV_Error(CV_StsNotImplemented, "This function in deprecated, do not use it"); |
||||||
|
} |
||||||
|
|
||||||
|
////////////////////////////////////////////////////////////////////////
|
||||||
|
// GlCamera
|
||||||
|
|
||||||
|
cv::GlCamera::GlCamera() : |
||||||
|
eye_(0.0, 0.0, -5.0), center_(0.0, 0.0, 0.0), up_(0.0, 1.0, 0.0), |
||||||
|
pos_(0.0, 0.0, -5.0), yaw_(0.0), pitch_(0.0), roll_(0.0), |
||||||
|
useLookAtParams_(false), |
||||||
|
|
||||||
|
scale_(1.0, 1.0, 1.0), |
||||||
|
|
||||||
|
projectionMatrix_(), |
||||||
|
fov_(45.0), aspect_(0.0), |
||||||
|
left_(0.0), right_(1.0), bottom_(1.0), top_(0.0), |
||||||
|
zNear_(-1.0), zFar_(1.0), |
||||||
|
perspectiveProjection_(false) |
||||||
|
{ |
||||||
|
CV_Error(CV_StsNotImplemented, "This function in deprecated, do not use it"); |
||||||
|
} |
||||||
|
|
||||||
|
void cv::GlCamera::lookAt(Point3d, Point3d, Point3d) |
||||||
|
{ |
||||||
|
CV_Error(CV_StsNotImplemented, "This function in deprecated, do not use it"); |
||||||
|
} |
||||||
|
|
||||||
|
void cv::GlCamera::setCameraPos(Point3d, double, double, double) |
||||||
|
{ |
||||||
|
CV_Error(CV_StsNotImplemented, "This function in deprecated, do not use it"); |
||||||
|
} |
||||||
|
|
||||||
|
void cv::GlCamera::setScale(Point3d) |
||||||
|
{ |
||||||
|
CV_Error(CV_StsNotImplemented, "This function in deprecated, do not use it"); |
||||||
|
} |
||||||
|
|
||||||
|
void cv::GlCamera::setProjectionMatrix(const Mat&, bool) |
||||||
|
{ |
||||||
|
CV_Error(CV_StsNotImplemented, "This function in deprecated, do not use it"); |
||||||
|
} |
||||||
|
|
||||||
|
void cv::GlCamera::setPerspectiveProjection(double, double, double, double) |
||||||
|
{ |
||||||
|
CV_Error(CV_StsNotImplemented, "This function in deprecated, do not use it"); |
||||||
|
} |
||||||
|
|
||||||
|
void cv::GlCamera::setOrthoProjection(double, double, double, double, double, double) |
||||||
|
{ |
||||||
|
CV_Error(CV_StsNotImplemented, "This function in deprecated, do not use it"); |
||||||
|
} |
||||||
|
|
||||||
|
void cv::GlCamera::setupProjectionMatrix() const |
||||||
|
{ |
||||||
|
CV_Error(CV_StsNotImplemented, "This function in deprecated, do not use it"); |
||||||
|
} |
||||||
|
|
||||||
|
void cv::GlCamera::setupModelViewMatrix() const |
||||||
|
{ |
||||||
|
CV_Error(CV_StsNotImplemented, "This function in deprecated, do not use it"); |
||||||
|
} |
||||||
|
|
||||||
|
////////////////////////////////////////////////////////////////////////
|
||||||
|
// Error handling
|
||||||
|
|
||||||
|
bool icvCheckGlError(const char*, const int, const char*) |
||||||
|
{ |
||||||
|
CV_Error(CV_StsNotImplemented, "This function in deprecated, do not use it"); |
||||||
|
return false; |
||||||
|
} |
@ -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) |
||||||
|
|
||||||
|
/////////////////////////////////////////////
|
||||||
|
// Buffer
|
||||||
|
|
||||||
|
PARAM_TEST_CASE(Buffer, 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(Buffer, Constructor1) |
||||||
|
{ |
||||||
|
cv::ogl::Buffer buf(size.height, size.width, type, cv::ogl::Buffer::ARRAY_BUFFER, true); |
||||||
|
|
||||||
|
EXPECT_EQ(size.height, buf.rows()); |
||||||
|
EXPECT_EQ(size.width, buf.cols()); |
||||||
|
EXPECT_EQ(type, buf.type()); |
||||||
|
} |
||||||
|
|
||||||
|
GPU_TEST_P(Buffer, Constructor2) |
||||||
|
{ |
||||||
|
cv::ogl::Buffer buf(size, type, cv::ogl::Buffer::ARRAY_BUFFER, true); |
||||||
|
|
||||||
|
EXPECT_EQ(size.height, buf.rows()); |
||||||
|
EXPECT_EQ(size.width, buf.cols()); |
||||||
|
EXPECT_EQ(type, buf.type()); |
||||||
|
} |
||||||
|
|
||||||
|
GPU_TEST_P(Buffer, ConstructorFromMat) |
||||||
|
{ |
||||||
|
cv::Mat gold = randomMat(size, type); |
||||||
|
|
||||||
|
cv::ogl::Buffer buf(gold, cv::ogl::Buffer::ARRAY_BUFFER, true); |
||||||
|
|
||||||
|
cv::Mat bufData; |
||||||
|
buf.copyTo(bufData); |
||||||
|
|
||||||
|
EXPECT_MAT_NEAR(gold, bufData, 0); |
||||||
|
} |
||||||
|
|
||||||
|
GPU_TEST_P(Buffer, ConstructorFromGpuMat) |
||||||
|
{ |
||||||
|
cv::Mat gold = randomMat(size, type); |
||||||
|
cv::gpu::GpuMat d_gold(gold); |
||||||
|
|
||||||
|
cv::ogl::Buffer buf(d_gold, cv::ogl::Buffer::ARRAY_BUFFER); |
||||||
|
|
||||||
|
cv::Mat bufData; |
||||||
|
buf.copyTo(bufData); |
||||||
|
|
||||||
|
EXPECT_MAT_NEAR(gold, bufData, 0); |
||||||
|
} |
||||||
|
|
||||||
|
GPU_TEST_P(Buffer, ConstructorFromBuffer) |
||||||
|
{ |
||||||
|
cv::ogl::Buffer buf_gold(size, type, cv::ogl::Buffer::ARRAY_BUFFER, true); |
||||||
|
|
||||||
|
cv::ogl::Buffer 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(Buffer, ConstructorFromTexture2D) |
||||||
|
{ |
||||||
|
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::ogl::Texture2D tex_gold(gold, true); |
||||||
|
|
||||||
|
cv::ogl::Buffer buf(tex_gold, cv::ogl::Buffer::PIXEL_PACK_BUFFER, true); |
||||||
|
|
||||||
|
cv::Mat bufData; |
||||||
|
buf.copyTo(bufData); |
||||||
|
|
||||||
|
EXPECT_MAT_NEAR(gold, bufData, 1e-2); |
||||||
|
} |
||||||
|
|
||||||
|
GPU_TEST_P(Buffer, Create) |
||||||
|
{ |
||||||
|
cv::ogl::Buffer buf; |
||||||
|
buf.create(size.height, size.width, type, cv::ogl::Buffer::ARRAY_BUFFER, true); |
||||||
|
|
||||||
|
EXPECT_EQ(size.height, buf.rows()); |
||||||
|
EXPECT_EQ(size.width, buf.cols()); |
||||||
|
EXPECT_EQ(type, buf.type()); |
||||||
|
} |
||||||
|
|
||||||
|
GPU_TEST_P(Buffer, CopyFromMat) |
||||||
|
{ |
||||||
|
cv::Mat gold = randomMat(size, type); |
||||||
|
|
||||||
|
cv::ogl::Buffer buf; |
||||||
|
buf.copyFrom(gold, cv::ogl::Buffer::ARRAY_BUFFER, true); |
||||||
|
|
||||||
|
cv::Mat bufData; |
||||||
|
buf.copyTo(bufData); |
||||||
|
|
||||||
|
EXPECT_MAT_NEAR(gold, bufData, 0); |
||||||
|
} |
||||||
|
|
||||||
|
GPU_TEST_P(Buffer, CopyFromGpuMat) |
||||||
|
{ |
||||||
|
cv::Mat gold = randomMat(size, type); |
||||||
|
cv::gpu::GpuMat d_gold(gold); |
||||||
|
|
||||||
|
cv::ogl::Buffer buf; |
||||||
|
buf.copyFrom(d_gold, cv::ogl::Buffer::ARRAY_BUFFER, true); |
||||||
|
|
||||||
|
cv::Mat bufData; |
||||||
|
buf.copyTo(bufData); |
||||||
|
|
||||||
|
EXPECT_MAT_NEAR(gold, bufData, 0); |
||||||
|
} |
||||||
|
|
||||||
|
GPU_TEST_P(Buffer, CopyFromBuffer) |
||||||
|
{ |
||||||
|
cv::Mat gold = randomMat(size, type); |
||||||
|
cv::ogl::Buffer buf_gold(gold, cv::ogl::Buffer::ARRAY_BUFFER, true); |
||||||
|
|
||||||
|
cv::ogl::Buffer buf; |
||||||
|
buf.copyFrom(buf_gold, cv::ogl::Buffer::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(Buffer, CopyFromTexture2D) |
||||||
|
{ |
||||||
|
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::ogl::Texture2D tex_gold(gold, true); |
||||||
|
|
||||||
|
cv::ogl::Buffer buf; |
||||||
|
buf.copyFrom(tex_gold, cv::ogl::Buffer::ARRAY_BUFFER, true); |
||||||
|
|
||||||
|
cv::Mat bufData; |
||||||
|
buf.copyTo(bufData); |
||||||
|
|
||||||
|
EXPECT_MAT_NEAR(gold, bufData, 1e-2); |
||||||
|
} |
||||||
|
|
||||||
|
GPU_TEST_P(Buffer, CopyToGpuMat) |
||||||
|
{ |
||||||
|
cv::Mat gold = randomMat(size, type); |
||||||
|
|
||||||
|
cv::ogl::Buffer buf(gold, cv::ogl::Buffer::ARRAY_BUFFER, true); |
||||||
|
|
||||||
|
cv::gpu::GpuMat dst; |
||||||
|
buf.copyTo(dst); |
||||||
|
|
||||||
|
EXPECT_MAT_NEAR(gold, dst, 0); |
||||||
|
} |
||||||
|
|
||||||
|
GPU_TEST_P(Buffer, CopyToBuffer) |
||||||
|
{ |
||||||
|
cv::Mat gold = randomMat(size, type); |
||||||
|
|
||||||
|
cv::ogl::Buffer buf(gold, cv::ogl::Buffer::ARRAY_BUFFER, true); |
||||||
|
|
||||||
|
cv::ogl::Buffer dst; |
||||||
|
buf.copyTo(dst, cv::ogl::Buffer::ARRAY_BUFFER, true); |
||||||
|
|
||||||
|
EXPECT_NE(buf.bufId(), dst.bufId()); |
||||||
|
|
||||||
|
cv::Mat bufData; |
||||||
|
dst.copyTo(bufData); |
||||||
|
|
||||||
|
EXPECT_MAT_NEAR(gold, bufData, 0); |
||||||
|
} |
||||||
|
|
||||||
|
GPU_TEST_P(Buffer, CopyToTexture2D) |
||||||
|
{ |
||||||
|
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::ogl::Buffer buf(gold, cv::ogl::Buffer::PIXEL_PACK_BUFFER, true); |
||||||
|
|
||||||
|
cv::ogl::Texture2D tex; |
||||||
|
buf.copyTo(tex, cv::ogl::Buffer::PIXEL_PACK_BUFFER, true); |
||||||
|
|
||||||
|
cv::Mat texData; |
||||||
|
tex.copyTo(texData); |
||||||
|
|
||||||
|
EXPECT_MAT_NEAR(gold, texData, 1e-2); |
||||||
|
} |
||||||
|
|
||||||
|
GPU_TEST_P(Buffer, Clone) |
||||||
|
{ |
||||||
|
cv::Mat gold = randomMat(size, type); |
||||||
|
|
||||||
|
cv::ogl::Buffer buf(gold, cv::ogl::Buffer::ARRAY_BUFFER, true); |
||||||
|
|
||||||
|
cv::ogl::Buffer dst = buf.clone(cv::ogl::Buffer::ARRAY_BUFFER, true); |
||||||
|
|
||||||
|
EXPECT_NE(buf.bufId(), dst.bufId()); |
||||||
|
|
||||||
|
cv::Mat bufData; |
||||||
|
dst.copyTo(bufData); |
||||||
|
|
||||||
|
EXPECT_MAT_NEAR(gold, bufData, 0); |
||||||
|
} |
||||||
|
|
||||||
|
GPU_TEST_P(Buffer, MapHostRead) |
||||||
|
{ |
||||||
|
cv::Mat gold = randomMat(size, type); |
||||||
|
|
||||||
|
cv::ogl::Buffer buf(gold, cv::ogl::Buffer::ARRAY_BUFFER, true); |
||||||
|
|
||||||
|
cv::Mat dst = buf.mapHost(cv::ogl::Buffer::READ_ONLY); |
||||||
|
|
||||||
|
EXPECT_MAT_NEAR(gold, dst, 0); |
||||||
|
|
||||||
|
buf.unmapHost(); |
||||||
|
} |
||||||
|
|
||||||
|
GPU_TEST_P(Buffer, MapHostWrite) |
||||||
|
{ |
||||||
|
cv::Mat gold = randomMat(size, type); |
||||||
|
|
||||||
|
cv::ogl::Buffer buf(size, type, cv::ogl::Buffer::ARRAY_BUFFER, true); |
||||||
|
|
||||||
|
cv::Mat dst = buf.mapHost(cv::ogl::Buffer::WRITE_ONLY); |
||||||
|
gold.copyTo(dst); |
||||||
|
buf.unmapHost(); |
||||||
|
dst.release(); |
||||||
|
|
||||||
|
cv::Mat bufData; |
||||||
|
buf.copyTo(bufData); |
||||||
|
|
||||||
|
EXPECT_MAT_NEAR(gold, bufData, 0); |
||||||
|
} |
||||||
|
|
||||||
|
GPU_TEST_P(Buffer, MapDevice) |
||||||
|
{ |
||||||
|
cv::Mat gold = randomMat(size, type); |
||||||
|
|
||||||
|
cv::ogl::Buffer buf(gold, cv::ogl::Buffer::ARRAY_BUFFER, true); |
||||||
|
|
||||||
|
cv::gpu::GpuMat dst = buf.mapDevice(); |
||||||
|
|
||||||
|
EXPECT_MAT_NEAR(gold, dst, 0); |
||||||
|
|
||||||
|
buf.unmapDevice(); |
||||||
|
} |
||||||
|
|
||||||
|
INSTANTIATE_TEST_CASE_P(OpenGL, Buffer, testing::Combine(DIFFERENT_SIZES, ALL_TYPES)); |
||||||
|
|
||||||
|
/////////////////////////////////////////////
|
||||||
|
// Texture2D
|
||||||
|
|
||||||
|
PARAM_TEST_CASE(Texture2D, 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::ogl::Texture2D::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::ogl::Texture2D::DEPTH_COMPONENT : cn == 3 ? cv::ogl::Texture2D::RGB : cn == 4 ? cv::ogl::Texture2D::RGBA : cv::ogl::Texture2D::NONE; |
||||||
|
} |
||||||
|
}; |
||||||
|
|
||||||
|
GPU_TEST_P(Texture2D, Constructor1) |
||||||
|
{ |
||||||
|
cv::ogl::Texture2D 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(Texture2D, Constructor2) |
||||||
|
{ |
||||||
|
cv::ogl::Texture2D tex(size, format, true); |
||||||
|
|
||||||
|
EXPECT_EQ(size.height, tex.rows()); |
||||||
|
EXPECT_EQ(size.width, tex.cols()); |
||||||
|
EXPECT_EQ(format, tex.format()); |
||||||
|
} |
||||||
|
|
||||||
|
GPU_TEST_P(Texture2D, ConstructorFromMat) |
||||||
|
{ |
||||||
|
cv::Mat gold = randomMat(size, type, 0, depth == CV_8U ? 255 : 1); |
||||||
|
|
||||||
|
cv::ogl::Texture2D tex(gold, true); |
||||||
|
|
||||||
|
cv::Mat texData; |
||||||
|
tex.copyTo(texData, depth); |
||||||
|
|
||||||
|
EXPECT_MAT_NEAR(gold, texData, 1e-2); |
||||||
|
} |
||||||
|
|
||||||
|
GPU_TEST_P(Texture2D, ConstructorFromGpuMat) |
||||||
|
{ |
||||||
|
cv::Mat gold = randomMat(size, type, 0, depth == CV_8U ? 255 : 1); |
||||||
|
cv::gpu::GpuMat d_gold(gold); |
||||||
|
|
||||||
|
cv::ogl::Texture2D tex(d_gold, true); |
||||||
|
|
||||||
|
cv::Mat texData; |
||||||
|
tex.copyTo(texData, depth); |
||||||
|
|
||||||
|
EXPECT_MAT_NEAR(gold, texData, 1e-2); |
||||||
|
} |
||||||
|
|
||||||
|
GPU_TEST_P(Texture2D, ConstructorFromBuffer) |
||||||
|
{ |
||||||
|
cv::Mat gold = randomMat(size, type, 0, depth == CV_8U ? 255 : 1); |
||||||
|
cv::ogl::Buffer buf_gold(gold, cv::ogl::Buffer::PIXEL_UNPACK_BUFFER, true); |
||||||
|
|
||||||
|
cv::ogl::Texture2D tex(buf_gold, true); |
||||||
|
|
||||||
|
cv::Mat texData; |
||||||
|
tex.copyTo(texData, depth); |
||||||
|
|
||||||
|
EXPECT_MAT_NEAR(gold, texData, 1e-2); |
||||||
|
} |
||||||
|
|
||||||
|
GPU_TEST_P(Texture2D, ConstructorFromTexture2D) |
||||||
|
{ |
||||||
|
cv::ogl::Texture2D tex_gold(size, format, true); |
||||||
|
cv::ogl::Texture2D 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(Texture2D, Create) |
||||||
|
{ |
||||||
|
cv::ogl::Texture2D 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(Texture2D, CopyFromMat) |
||||||
|
{ |
||||||
|
cv::Mat gold = randomMat(size, type, 0, depth == CV_8U ? 255 : 1); |
||||||
|
|
||||||
|
cv::ogl::Texture2D tex; |
||||||
|
tex.copyFrom(gold, true); |
||||||
|
|
||||||
|
cv::Mat texData; |
||||||
|
tex.copyTo(texData, depth); |
||||||
|
|
||||||
|
EXPECT_MAT_NEAR(gold, texData, 1e-2); |
||||||
|
} |
||||||
|
|
||||||
|
GPU_TEST_P(Texture2D, CopyFromGpuMat) |
||||||
|
{ |
||||||
|
cv::Mat gold = randomMat(size, type, 0, depth == CV_8U ? 255 : 1); |
||||||
|
cv::gpu::GpuMat d_gold(gold); |
||||||
|
|
||||||
|
cv::ogl::Texture2D tex; |
||||||
|
tex.copyFrom(d_gold, true); |
||||||
|
|
||||||
|
cv::Mat texData; |
||||||
|
tex.copyTo(texData, depth); |
||||||
|
|
||||||
|
EXPECT_MAT_NEAR(gold, texData, 1e-2); |
||||||
|
} |
||||||
|
|
||||||
|
GPU_TEST_P(Texture2D, CopyFromBuffer) |
||||||
|
{ |
||||||
|
cv::Mat gold = randomMat(size, type, 0, depth == CV_8U ? 255 : 1); |
||||||
|
cv::ogl::Buffer buf_gold(gold, cv::ogl::Buffer::PIXEL_UNPACK_BUFFER, true); |
||||||
|
|
||||||
|
cv::ogl::Texture2D tex; |
||||||
|
tex.copyFrom(buf_gold, true); |
||||||
|
|
||||||
|
cv::Mat texData; |
||||||
|
tex.copyTo(texData, depth); |
||||||
|
|
||||||
|
EXPECT_MAT_NEAR(gold, texData, 1e-2); |
||||||
|
} |
||||||
|
|
||||||
|
GPU_TEST_P(Texture2D, CopyToGpuMat) |
||||||
|
{ |
||||||
|
cv::Mat gold = randomMat(size, type, 0, depth == CV_8U ? 255 : 1); |
||||||
|
|
||||||
|
cv::ogl::Texture2D tex(gold, true); |
||||||
|
|
||||||
|
cv::gpu::GpuMat dst; |
||||||
|
tex.copyTo(dst, depth); |
||||||
|
|
||||||
|
EXPECT_MAT_NEAR(gold, dst, 1e-2); |
||||||
|
} |
||||||
|
|
||||||
|
GPU_TEST_P(Texture2D, CopyToBuffer) |
||||||
|
{ |
||||||
|
cv::Mat gold = randomMat(size, type, 0, depth == CV_8U ? 255 : 1); |
||||||
|
|
||||||
|
cv::ogl::Texture2D tex(gold, true); |
||||||
|
|
||||||
|
cv::ogl::Buffer dst; |
||||||
|
tex.copyTo(dst, depth, true); |
||||||
|
|
||||||
|
cv::Mat bufData; |
||||||
|
dst.copyTo(bufData); |
||||||
|
|
||||||
|
EXPECT_MAT_NEAR(gold, bufData, 1e-2); |
||||||
|
} |
||||||
|
|
||||||
|
INSTANTIATE_TEST_CASE_P(OpenGL, Texture2D, testing::Combine(DIFFERENT_SIZES, testing::Values(CV_8UC1, CV_8UC3, CV_8UC4, CV_32FC1, CV_32FC3, CV_32FC4))); |
||||||
|
|
||||||
|
#endif |
@ -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)); |
|
||||||
} |
|
@ -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; |
|
||||||
} |
|
@ -0,0 +1,122 @@ |
|||||||
|
#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 |
||||||
|
{ |
||||||
|
ogl::Arrays arr; |
||||||
|
ogl::Texture2D tex; |
||||||
|
ogl::Buffer indices; |
||||||
|
}; |
||||||
|
|
||||||
|
void draw(void* userdata); |
||||||
|
|
||||||
|
void draw(void* userdata) |
||||||
|
{ |
||||||
|
DrawData* data = static_cast<DrawData*>(userdata); |
||||||
|
|
||||||
|
glRotated(0.6, 0, 1, 0); |
||||||
|
|
||||||
|
ogl::render(data->arr, data->indices, ogl::TRIANGLES); |
||||||
|
} |
||||||
|
|
||||||
|
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); |
||||||
|
|
||||||
|
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); |
||||||
|
|
||||||
|
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); |
||||||
|
|
||||||
|
setOpenGlDrawCallback("OpenGL", draw, &data); |
||||||
|
|
||||||
|
for (;;) |
||||||
|
{ |
||||||
|
updateWindow("OpenGL"); |
||||||
|
int key = waitKey(40); |
||||||
|
if ((key & 0xff) == 27) |
||||||
|
break; |
||||||
|
} |
||||||
|
|
||||||
|
setOpenGlDrawCallback("OpenGL", 0, 0); |
||||||
|
destroyAllWindows(); |
||||||
|
|
||||||
|
return 0; |
||||||
|
} |
||||||
|
|
||||||
|
#endif |
Loading…
Reference in new issue