comments and improvement to fps printing

pull/3471/head
kallaballa 3 years ago
parent 832e5f4ff5
commit 4f5a199d17
  1. 18
      src/camera/camera-demo.cpp

@ -149,16 +149,17 @@ int main(int argc, char **argv) {
uint64_t cnt = 1;
int64 start = cv::getTickCount();
double tickFreq = cv::getTickFrequency();
double lastFps = 0;
while (true) {
//Activate the OpenCL context for OpenGL
GL_CONTEXT.bind();
//Initially get the framebuffer so we can write the video frame to it
//Initially aquire the framebuffer so we can write the video frame to it
gl::acquire_frame_buffer(frameBuffer);
//Activate the OpenCL context for VAAPI
VA_CONTEXT.bind();
//Decode a frame using HW acceleration into a cv::UMat
//Decode a frame on the GPU using VAAPI
cap >> videoFrame;
if (videoFrame.empty()) {
cerr << "End of stream. Exiting" << endl;
@ -173,10 +174,11 @@ int main(int argc, char **argv) {
cv::resize(videoFrameRGBA, frameBuffer, cv::Size(WIDTH, HEIGHT));
GL_CONTEXT.bind();
//Transfer buffer ownership to OpenGL
//Release the frame buffer for use by OpenGL
gl::release_frame_buffer(frameBuffer);
//Render using OpenGL
render();
//Transfer buffer ownership to OpenCL
//Aquire the frame buffer for use by OpenCL
gl::acquire_frame_buffer(frameBuffer);
//Glow effect (OpenCL)
@ -194,7 +196,7 @@ int main(int argc, char **argv) {
if(x11::is_initialized()) {
//Yet again activate the OpenCL context for OpenGL
GL_CONTEXT.bind();
//Transfer buffer ownership back to OpenGL
//Release the frame buffer for use by OpenGL
gl::release_frame_buffer(frameBuffer);
//Blit the framebuffer we have been working on to the screen
gl::blit_frame_buffer_to_screen();
@ -203,13 +205,15 @@ int main(int argc, char **argv) {
if(x11::window_closed())
break;
//Transfer the back buffer (which we have been using as frame buffer) to the native window
gl::swapBuffers();
}
//Measure FPS
if (cnt % uint64(INPUT_FPS) == 0) {
if (cnt % uint64(ceil(lastFps == 0 ? INPUT_FPS : lastFps)) == 0) {
int64 tick = cv::getTickCount();
cerr << "FPS : " << tickFreq / ((tick - start + 1) / cnt) << '\r';
lastFps = tickFreq / ((tick - start + 1) / cnt);
cerr << "FPS : " << lastFps << '\r';
start = tick;
cnt = 1;
}

Loading…
Cancel
Save