I am new to programming as a whole, but have been able to pick things up fast thanks to you guys.
I have a couple of pictures and I would like to display each picture for as short a period of time as possible. I've been using Opencv so far and it works great. I've been able to figure out how to get the pictures i need and display them using cv::imshow and cv::waitKey(), but the waitKey as we all know it inaccurate in its timing and also doesn't allow me show the pictures for to as high a time resolution as I would like to go.
So far, I've tried using alternatives such as an event loop and limiting the run time of the imshow thread, but nothing has worked to my satisfaction.
First off, I would like to figure out how long it takes for imshow to display an image on the screen (I am guessing it has a lot to do with the CPU speed).
Lastly (which is my actual question), is there a way to do this (even if hypothetical and impractical) and if so how do I go about it (your answers are greatly valued).
What I have tried:
#include <chrono>
#include <condition_variable>
#include <iostream>
#include <mutex>
#include <cstdint>
#include <thread>
#include <opencv2 core="" core.hpp="">
#include <opencv2 highgui="" highgui.hpp="">
static std::condition_variable condvar;
static std::mutex mut;
static bool stop = false;
cv::String folder = "picture location...";
std::vector<cv::string> filenames;
void
loopFunction()
{
using delta = std::chrono::duration<std::int64_t, std::ratio<1,="" 10000000="">>;
auto next = std::chrono::steady_clock::now() + delta{ 1 };
std::unique_lock<std::mutex> lk(mut);
while (!stop)
{
mut.unlock();
for (size_t i = 0; i < 5; ++i)
{
if (i > 1) {
i = 0;
}
cv::Mat myImage = cv::imread(filenames[i]);
cv::imshow("Boiii", myImage);
mut.lock();
condvar.wait_until(lk, next, [] {return false; });
next += delta{ 1 };
}
}
}
int main()
{
cv::glob(folder, filenames);
using namespace std::chrono_literals;
std::thread t{ loopFunction };
std::this_thread::sleep_for(5s);
{
std::lock_guard<std::mutex> lk(mut);
stop = true;
}
t.join();
}