From 6c452addfeb88b8a11a9e8a3c429e3b084548358 Mon Sep 17 00:00:00 2001 From: Vladimir Dudnik Date: Mon, 20 Jul 2015 19:05:05 +0300 Subject: [PATCH] changed output from fps to time (in msec). Notes for dx10 and dx11: the first measure is wrong (zero), the followiing are correct; measured time includes output text to surface. --- samples/directx/d3d10_interop.cpp | 16 ++++++++-------- samples/directx/d3d11_interop.cpp | 16 ++++++++-------- samples/directx/d3d9_interop.cpp | 8 ++++---- samples/directx/d3d9ex_interop.cpp | 8 ++++---- samples/directx/d3dsample.hpp | 32 ++++++++++++++++++-------------- 5 files changed, 42 insertions(+), 38 deletions(-) diff --git a/samples/directx/d3d10_interop.cpp b/samples/directx/d3d10_interop.cpp index d66417a..2869e6b 100644 --- a/samples/directx/d3d10_interop.cpp +++ b/samples/directx/d3d10_interop.cpp @@ -199,14 +199,14 @@ public: cv::blur(m, m, cv::Size(15, 15), cv::Point(-7, -7)); } - cv::String strMode = cv::format("%s", m_modeStr[MODE_CPU].c_str()); + cv::String strMode = cv::format("mode: %s", m_modeStr[MODE_CPU].c_str()); cv::String strProcessing = m_demo_processing ? "blur frame" : "copy frame"; - cv::String strFPS = cv::format("%2.1f", m_timer.fps()); - cv::String strDevName = cv::format("%s", m_oclDevName.c_str()); + cv::String strTime = cv::format("time: %4.1f msec", m_timer.time(Timer::UNITS::MSEC)); + cv::String strDevName = cv::format("OpenCL device: %s", m_oclDevName.c_str()); cv::putText(m, strMode, cv::Point(0, 16), 1, 0.8, cv::Scalar(0, 0, 0)); cv::putText(m, strProcessing, cv::Point(0, 32), 1, 0.8, cv::Scalar(0, 0, 0)); - cv::putText(m, strFPS, cv::Point(0, 48), 1, 0.8, cv::Scalar(0, 0, 0)); + cv::putText(m, strTime, cv::Point(0, 48), 1, 0.8, cv::Scalar(0, 0, 0)); cv::putText(m, strDevName, cv::Point(0, 64), 1, 0.8, cv::Scalar(0, 0, 0)); pSurface->Unmap(subResource); @@ -227,14 +227,14 @@ public: cv::blur(u, u, cv::Size(15, 15), cv::Point(-7, -7)); } - cv::String strMode = cv::format("%s", m_modeStr[MODE_GPU].c_str()); + cv::String strMode = cv::format("mode: %s", m_modeStr[MODE_GPU].c_str()); cv::String strProcessing = m_demo_processing ? "blur frame" : "copy frame"; - cv::String strFPS = cv::format("%2.1f", m_timer.fps()); - cv::String strDevName = cv::format("%s", m_oclDevName.c_str()); + cv::String strTime = cv::format("time: %4.1f msec", m_timer.time(Timer::UNITS::MSEC)); + cv::String strDevName = cv::format("OpenCL device: %s", m_oclDevName.c_str()); cv::putText(u, strMode, cv::Point(0, 16), 1, 0.8, cv::Scalar(0, 0, 0)); cv::putText(u, strProcessing, cv::Point(0, 32), 1, 0.8, cv::Scalar(0, 0, 0)); - cv::putText(u, strFPS, cv::Point(0, 48), 1, 0.8, cv::Scalar(0, 0, 0)); + cv::putText(u, strTime, cv::Point(0, 48), 1, 0.8, cv::Scalar(0, 0, 0)); cv::putText(u, strDevName, cv::Point(0, 64), 1, 0.8, cv::Scalar(0, 0, 0)); cv::directx::convertToD3D10Texture2D(u, pSurface); diff --git a/samples/directx/d3d11_interop.cpp b/samples/directx/d3d11_interop.cpp index 0972970..3ac2b06 100644 --- a/samples/directx/d3d11_interop.cpp +++ b/samples/directx/d3d11_interop.cpp @@ -204,14 +204,14 @@ public: cv::blur(m, m, cv::Size(15, 15), cv::Point(-7, -7)); } - cv::String strMode = cv::format("%s", m_modeStr[MODE_CPU].c_str()); + cv::String strMode = cv::format("mode: %s", m_modeStr[MODE_CPU].c_str()); cv::String strProcessing = m_demo_processing ? "blur frame" : "copy frame"; - cv::String strFPS = cv::format("%2.1f", m_timer.fps()); - cv::String strDevName = cv::format("%s", m_oclDevName.c_str()); + cv::String strTime = cv::format("time: %4.1f msec", m_timer.time(Timer::UNITS::MSEC)); + cv::String strDevName = cv::format("OpenCL device: %s", m_oclDevName.c_str()); cv::putText(m, strMode, cv::Point(0, 16), 1, 0.8, cv::Scalar(0, 0, 0)); cv::putText(m, strProcessing, cv::Point(0, 32), 1, 0.8, cv::Scalar(0, 0, 0)); - cv::putText(m, strFPS, cv::Point(0, 48), 1, 0.8, cv::Scalar(0, 0, 0)); + cv::putText(m, strTime, cv::Point(0, 48), 1, 0.8, cv::Scalar(0, 0, 0)); cv::putText(m, strDevName, cv::Point(0, 64), 1, 0.8, cv::Scalar(0, 0, 0)); m_pD3D11Ctx->Unmap(pSurface, subResource); @@ -232,14 +232,14 @@ public: cv::blur(u, u, cv::Size(15, 15), cv::Point(-7, -7)); } - cv::String strMode = cv::format("%s", m_modeStr[MODE_GPU].c_str()); + cv::String strMode = cv::format("mode: %s", m_modeStr[MODE_GPU].c_str()); cv::String strProcessing = m_demo_processing ? "blur frame" : "copy frame"; - cv::String strFPS = cv::format("%2.1f", m_timer.fps()); - cv::String strDevName = cv::format("%s", m_oclDevName.c_str()); + cv::String strTime = cv::format("time: %4.1f msec", m_timer.time(Timer::UNITS::MSEC)); + cv::String strDevName = cv::format("OpenCL device: %s", m_oclDevName.c_str()); cv::putText(u, strMode, cv::Point(0, 16), 1, 0.8, cv::Scalar(0, 0, 0)); cv::putText(u, strProcessing, cv::Point(0, 32), 1, 0.8, cv::Scalar(0, 0, 0)); - cv::putText(u, strFPS, cv::Point(0, 48), 1, 0.8, cv::Scalar(0, 0, 0)); + cv::putText(u, strTime, cv::Point(0, 48), 1, 0.8, cv::Scalar(0, 0, 0)); cv::putText(u, strDevName, cv::Point(0, 64), 1, 0.8, cv::Scalar(0, 0, 0)); cv::directx::convertToD3D11Texture2D(u, pSurface); diff --git a/samples/directx/d3d9_interop.cpp b/samples/directx/d3d9_interop.cpp index aa5c3cc..afe12b3 100644 --- a/samples/directx/d3d9_interop.cpp +++ b/samples/directx/d3d9_interop.cpp @@ -207,7 +207,7 @@ public: m_timer.stop(); - print_info(pSurface, m_mode, m_timer.fps(), m_oclDevName); + print_info(pSurface, m_mode, m_timer.time(Timer::UNITS::MSEC), m_oclDevName); // traditional DX render pipeline: // BitBlt surface to backBuffer and flip backBuffer to frontBuffer @@ -235,7 +235,7 @@ public: } // render() - void print_info(LPDIRECT3DSURFACE9 pSurface, int mode, float fps, cv::String oclDevName) + void print_info(LPDIRECT3DSURFACE9 pSurface, int mode, float time, cv::String oclDevName) { HDC hDC; @@ -258,7 +258,7 @@ public: int y = 0; buf[0] = 0; - sprintf(buf, "Mode: %s", m_modeStr[mode].c_str()); + sprintf(buf, "mode: %s", m_modeStr[mode].c_str()); ::TextOut(hDC, 0, y, buf, (int)strlen(buf)); y += tm.tmHeight; @@ -268,7 +268,7 @@ public: y += tm.tmHeight; buf[0] = 0; - sprintf(buf, "FPS: %2.1f", fps); + sprintf(buf, "time: %4.1f msec", time); ::TextOut(hDC, 0, y, buf, (int)strlen(buf)); y += tm.tmHeight; diff --git a/samples/directx/d3d9ex_interop.cpp b/samples/directx/d3d9ex_interop.cpp index 5b5565e..1871770 100644 --- a/samples/directx/d3d9ex_interop.cpp +++ b/samples/directx/d3d9ex_interop.cpp @@ -207,7 +207,7 @@ public: m_timer.stop(); - print_info(pSurface, m_mode, m_timer.fps(), m_oclDevName); + print_info(pSurface, m_mode, m_timer.time(Timer::UNITS::MSEC), m_oclDevName); // traditional DX render pipeline: // BitBlt surface to backBuffer and flip backBuffer to frontBuffer @@ -236,7 +236,7 @@ public: } // render() - void print_info(LPDIRECT3DSURFACE9 pSurface, int mode, float fps, cv::String oclDevName) + void print_info(LPDIRECT3DSURFACE9 pSurface, int mode, float time, cv::String oclDevName) { HDC hDC; @@ -259,7 +259,7 @@ public: int y = 0; buf[0] = 0; - sprintf(buf, "Mode: %s", m_modeStr[mode].c_str()); + sprintf(buf, "mode: %s", m_modeStr[mode].c_str()); ::TextOut(hDC, 0, y, buf, (int)strlen(buf)); y += tm.tmHeight; @@ -269,7 +269,7 @@ public: y += tm.tmHeight; buf[0] = 0; - sprintf(buf, "FPS: %2.1f", fps); + sprintf(buf, "time: %4.1f msec", time); ::TextOut(hDC, 0, y, buf, (int)strlen(buf)); y += tm.tmHeight; diff --git a/samples/directx/d3dsample.hpp b/samples/directx/d3dsample.hpp index ddfed2e..4b7545f 100644 --- a/samples/directx/d3dsample.hpp +++ b/samples/directx/d3dsample.hpp @@ -20,40 +20,44 @@ class Timer { public: - Timer() : m_t0(0), m_t1(0) + 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 start() { m_t0 = cv::getTickCount(); - time_queue.push(m_t0); } void stop() { - if (time_queue.size() > 1) - m_t1 = time_queue.front(); - - if (time_queue.size() >= 25) - time_queue.pop(); + m_diff = cv::getTickCount() - m_t0; } - float fps() + float time(UNITS u = UNITS::MSEC) { - size_t sz = time_queue.size(); - - float fps = sz * m_tick_frequency / (m_t0 - m_t1); + float sec = m_diff / m_tick_frequency; - return fps; + return sec * m_unit_mul[u]; } public: float m_tick_frequency; int64 m_t0; - int64 m_t1; - std::queue time_queue; + int64 m_diff; + int m_unit_mul[3]; }; -- 2.7.4