Skip to content

Commit

Permalink
Include fps + documentatation for Sobel verilated
Browse files Browse the repository at this point in the history
modified:   tut05/src/main.cpp
new file:   tut05/imgs/sobel_horizontal_160x120.jpg
  tut05/imgs/sobel_vertical_160x120.jpg
  • Loading branch information
felipe-m committed Oct 8, 2023
1 parent f334d61 commit a5cbf27
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 0 deletions.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
17 changes: 17 additions & 0 deletions sim_fpga/tutorial/tut05/src/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
#include <SDL_opengl.h>
#include <assert.h>
#include <stdio.h>
#include <chrono> // to measure fps

#include <opencv2/opencv.hpp>
#include <opencv2/core.hpp>
Expand Down Expand Up @@ -342,11 +343,18 @@ int main(int argc, char **argv) {
cv::Mat grayrgb_input_feed; // grayscale resized image, but with 3 channels for the texture
cv::VideoCapture cap(0);

double timed_fps;
unsigned int millis_elapsed = 0;

// get opencv frame per seconds (FPS)
double cam_fps = cap.get(cv::CAP_PROP_FPS);

if (!cap.isOpened()) {
std::cout << "cannot open camera";
}

auto time_capture = std::chrono::high_resolution_clock::now();
auto old_time_capture = std::chrono::high_resolution_clock::now();
cap >> input_feed;
cv::resize(input_feed,resized_input_feed,cv::Size(IMG_COLS,IMG_ROWS),cv::INTER_LINEAR);
cv::cvtColor(resized_input_feed, gray_input_feed, cv::COLOR_BGR2GRAY);
Expand Down Expand Up @@ -438,6 +446,8 @@ int main(int argc, char **argv) {
GRIP_LINES_VERTICAL_ICON " Set Vertical");
}

old_time_capture = time_capture; // save old capture
time_capture = std::chrono::high_resolution_clock::now(); // new time capture
cap >> input_feed;
cv::resize(input_feed,resized_input_feed,cv::Size(IMG_COLS,IMG_ROWS),cv::INTER_LINEAR);
cv::cvtColor(resized_input_feed, gray_input_feed, cv::COLOR_BGR2GRAY);
Expand All @@ -463,8 +473,15 @@ int main(int argc, char **argv) {
//ImGui::SameLine();


// the 1st capture will be wrong, but just only the first
auto elapsed = std::chrono::duration_cast<std::chrono::milliseconds>(
time_capture - old_time_capture);
millis_elapsed = elapsed.count();
timed_fps = 1000.0 / millis_elapsed;
ImGui::Text("Timed %i ms (%.1f FPS)", millis_elapsed, timed_fps);
ImGui::Text("Application average %.3f ms/frame (%.1f FPS)",
1000.0f / ImGui::GetIO().Framerate, ImGui::GetIO().Framerate);
ImGui::Text("Maximum camera fps %.1f", cam_fps);
ImGui::End();
}

Expand Down

0 comments on commit a5cbf27

Please sign in to comment.