change displaying of fps to time (ms)
This commit is contained in:
parent
0a4830b3d5
commit
ea10290153
@ -113,23 +113,6 @@ public:
|
|||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
static float getFps()
|
|
||||||
{
|
|
||||||
static std::queue<int64> time_queue;
|
|
||||||
|
|
||||||
int64 now = cv::getTickCount();
|
|
||||||
int64 then = 0;
|
|
||||||
time_queue.push(now);
|
|
||||||
|
|
||||||
if (time_queue.size() >= 2)
|
|
||||||
then = time_queue.front();
|
|
||||||
|
|
||||||
if (time_queue.size() >= 25)
|
|
||||||
time_queue.pop();
|
|
||||||
|
|
||||||
return time_queue.size() * (float)cv::getTickFrequency() / (now - then);
|
|
||||||
}
|
|
||||||
|
|
||||||
#if defined(__linux__)
|
#if defined(__linux__)
|
||||||
int handle_event(XEvent& e)
|
int handle_event(XEvent& e)
|
||||||
{
|
{
|
||||||
@ -230,7 +213,7 @@ public:
|
|||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
void print_info(int mode, float fps, cv::String oclDevName)
|
void print_info(int mode, float time, cv::String oclDevName)
|
||||||
{
|
{
|
||||||
#if defined(WIN32) || defined(_WIN32)
|
#if defined(WIN32) || defined(_WIN32)
|
||||||
HDC hDC = m_hDC;
|
HDC hDC = m_hDC;
|
||||||
@ -253,7 +236,7 @@ public:
|
|||||||
|
|
||||||
y += tm.tmHeight;
|
y += tm.tmHeight;
|
||||||
buf[0] = 0;
|
buf[0] = 0;
|
||||||
sprintf_s(buf, sizeof(buf)-1, "FPS: %2.1f", fps);
|
sprintf_s(buf, sizeof(buf)-1, "Time: %2.1f", time);
|
||||||
::TextOut(hDC, 0, y, buf, (int)strlen(buf));
|
::TextOut(hDC, 0, y, buf, (int)strlen(buf));
|
||||||
|
|
||||||
y += tm.tmHeight;
|
y += tm.tmHeight;
|
||||||
@ -266,7 +249,7 @@ public:
|
|||||||
#elif defined(__linux__)
|
#elif defined(__linux__)
|
||||||
|
|
||||||
char buf[256+1];
|
char buf[256+1];
|
||||||
snprintf(buf, sizeof(buf)-1, "FPS: %2.1f Mode: %s Device: %s", fps, m_modeStr[mode].c_str(), oclDevName.c_str());
|
snprintf(buf, sizeof(buf)-1, "Time: %2.1f Mode: %s Device: %s", time, m_modeStr[mode].c_str(), oclDevName.c_str());
|
||||||
XStoreName(m_display, m_window, buf);
|
XStoreName(m_display, m_window, buf);
|
||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
@ -297,60 +280,20 @@ public:
|
|||||||
}
|
}
|
||||||
|
|
||||||
bool do_buffer = use_buffer();
|
bool do_buffer = use_buffer();
|
||||||
|
|
||||||
switch (get_mode())
|
switch (get_mode())
|
||||||
{
|
{
|
||||||
case 0:
|
case 0: // no processing
|
||||||
// no processing
|
m_timer.clear();
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case 1:
|
case 1: // process frame on CPU
|
||||||
{
|
processFrameCPU(texture, buffer);
|
||||||
// process video frame on CPU
|
|
||||||
cv::Mat m(m_height, m_width, CV_8UC4);
|
|
||||||
|
|
||||||
if (do_buffer)
|
|
||||||
buffer.copyTo(m);
|
|
||||||
else
|
|
||||||
texture.copyTo(m);
|
|
||||||
|
|
||||||
if (!m_disableProcessing)
|
|
||||||
{
|
|
||||||
// blur texture image with OpenCV on CPU
|
|
||||||
cv::blur(m, m, cv::Size(15, 15), cv::Point(-7, -7));
|
|
||||||
}
|
|
||||||
|
|
||||||
if (do_buffer)
|
|
||||||
buffer.copyFrom(m, cv::ogl::Buffer::PIXEL_UNPACK_BUFFER, true);
|
|
||||||
else
|
|
||||||
texture.copyFrom(m, true);
|
|
||||||
|
|
||||||
break;
|
break;
|
||||||
}
|
|
||||||
|
|
||||||
case 2:
|
|
||||||
{
|
|
||||||
// process video frame on GPU
|
|
||||||
cv::UMat u;
|
|
||||||
|
|
||||||
if (do_buffer)
|
|
||||||
u = cv::ogl::mapGLBuffer(buffer);
|
|
||||||
else
|
|
||||||
cv::ogl::convertFromGLTexture2D(texture, u);
|
|
||||||
|
|
||||||
if (!m_disableProcessing)
|
|
||||||
{
|
|
||||||
// blur texture image with OpenCV on GPU with OpenCL
|
|
||||||
cv::blur(u, u, cv::Size(15, 15), cv::Point(-7, -7));
|
|
||||||
}
|
|
||||||
|
|
||||||
if (do_buffer)
|
|
||||||
cv::ogl::unmapGLBuffer(u);
|
|
||||||
else
|
|
||||||
cv::ogl::convertToGLTexture2D(u, texture);
|
|
||||||
|
|
||||||
|
case 2: // process frame on GPU
|
||||||
|
processFrameGPU(texture, buffer);
|
||||||
break;
|
break;
|
||||||
}
|
|
||||||
|
|
||||||
} // switch
|
} // switch
|
||||||
|
|
||||||
if (do_buffer) // buffer -> texture
|
if (do_buffer) // buffer -> texture
|
||||||
@ -385,7 +328,7 @@ public:
|
|||||||
glXSwapBuffers(m_display, m_window);
|
glXSwapBuffers(m_display, m_window);
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
print_info(m_mode, getFps(), m_oclDevName);
|
print_info(m_mode, m_timer.time(Timer::UNITS::MSEC), m_oclDevName);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@ -400,6 +343,60 @@ public:
|
|||||||
|
|
||||||
protected:
|
protected:
|
||||||
|
|
||||||
|
void processFrameCPU(cv::ogl::Texture2D& texture, cv::ogl::Buffer& buffer)
|
||||||
|
{
|
||||||
|
cv::Mat m(m_height, m_width, CV_8UC4);
|
||||||
|
|
||||||
|
bool do_buffer = use_buffer();
|
||||||
|
|
||||||
|
m_timer.start();
|
||||||
|
|
||||||
|
if (do_buffer)
|
||||||
|
buffer.copyTo(m);
|
||||||
|
else
|
||||||
|
texture.copyTo(m);
|
||||||
|
|
||||||
|
if (!m_disableProcessing)
|
||||||
|
{
|
||||||
|
// blur texture image with OpenCV on CPU
|
||||||
|
cv::blur(m, m, cv::Size(15, 15), cv::Point(-7, -7));
|
||||||
|
}
|
||||||
|
|
||||||
|
if (do_buffer)
|
||||||
|
buffer.copyFrom(m, cv::ogl::Buffer::PIXEL_UNPACK_BUFFER, true);
|
||||||
|
else
|
||||||
|
texture.copyFrom(m, true);
|
||||||
|
|
||||||
|
m_timer.stop();
|
||||||
|
}
|
||||||
|
|
||||||
|
void processFrameGPU(cv::ogl::Texture2D& texture, cv::ogl::Buffer& buffer)
|
||||||
|
{
|
||||||
|
cv::UMat u;
|
||||||
|
|
||||||
|
bool do_buffer = use_buffer();
|
||||||
|
|
||||||
|
m_timer.start();
|
||||||
|
|
||||||
|
if (do_buffer)
|
||||||
|
u = cv::ogl::mapGLBuffer(buffer);
|
||||||
|
else
|
||||||
|
cv::ogl::convertFromGLTexture2D(texture, u);
|
||||||
|
|
||||||
|
if (!m_disableProcessing)
|
||||||
|
{
|
||||||
|
// blur texture image with OpenCV on GPU with OpenCL
|
||||||
|
cv::blur(u, u, cv::Size(15, 15), cv::Point(-7, -7));
|
||||||
|
}
|
||||||
|
|
||||||
|
if (do_buffer)
|
||||||
|
cv::ogl::unmapGLBuffer(u);
|
||||||
|
else
|
||||||
|
cv::ogl::convertToGLTexture2D(u, texture);
|
||||||
|
|
||||||
|
m_timer.stop();
|
||||||
|
}
|
||||||
|
|
||||||
#if defined(WIN32) || defined(_WIN32)
|
#if defined(WIN32) || defined(_WIN32)
|
||||||
int setup_pixel_format()
|
int setup_pixel_format()
|
||||||
{
|
{
|
||||||
|
@ -22,6 +22,54 @@
|
|||||||
|
|
||||||
#define SAFE_RELEASE(p) if (p) { p->Release(); p = NULL; }
|
#define SAFE_RELEASE(p) if (p) { p->Release(); p = NULL; }
|
||||||
|
|
||||||
|
class Timer
|
||||||
|
{
|
||||||
|
public:
|
||||||
|
enum UNITS
|
||||||
|
{
|
||||||
|
USEC = 0,
|
||||||
|
MSEC,
|
||||||
|
SEC
|
||||||
|
};
|
||||||
|
|
||||||
|
Timer() : m_t0(0), m_diff(0)
|
||||||
|
{
|
||||||
|
m_tick_frequency = (float)cv::getTickFrequency();
|
||||||
|
|
||||||
|
m_unit_mul[USEC] = 1000000;
|
||||||
|
m_unit_mul[MSEC] = 1000;
|
||||||
|
m_unit_mul[SEC] = 1;
|
||||||
|
}
|
||||||
|
|
||||||
|
void clear()
|
||||||
|
{
|
||||||
|
m_t0 = m_diff = 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
void start()
|
||||||
|
{
|
||||||
|
m_t0 = cv::getTickCount();
|
||||||
|
}
|
||||||
|
|
||||||
|
void stop()
|
||||||
|
{
|
||||||
|
m_diff = cv::getTickCount() - m_t0;
|
||||||
|
}
|
||||||
|
|
||||||
|
float time(UNITS u = UNITS::MSEC)
|
||||||
|
{
|
||||||
|
float sec = m_diff / m_tick_frequency;
|
||||||
|
|
||||||
|
return sec * m_unit_mul[u];
|
||||||
|
}
|
||||||
|
|
||||||
|
public:
|
||||||
|
float m_tick_frequency;
|
||||||
|
int64 m_t0;
|
||||||
|
int64 m_diff;
|
||||||
|
int m_unit_mul[3];
|
||||||
|
};
|
||||||
|
|
||||||
class WinApp
|
class WinApp
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
@ -218,4 +266,5 @@ protected:
|
|||||||
int m_width;
|
int m_width;
|
||||||
int m_height;
|
int m_height;
|
||||||
std::string m_window_name;
|
std::string m_window_name;
|
||||||
|
Timer m_timer;
|
||||||
};
|
};
|
||||||
|
Loading…
x
Reference in New Issue
Block a user