我是gtk的新手。我有一个嘈杂的图像并减少它,我使用opencv的功能。它有一个运行时间,例如5秒。我想通过使用进度条显示运行时间的进展。这是我的代码:
#include <opencv2/opencv.hpp>
#include <gtk/gtk.h>
#include <time.h>
using namespace cv;
using namespace std;
gboolean Func (gpointer data) {
gdouble value;
GString *text;
//part of code that generate run time
clock_t start, end;
start = clock();
Mat image, src1, DENO;
image = imread("C:/Users/Alireza/Desktop/1.png");
cvtColor(image, src1, CV_RGB2GRAY);
fastNlMeansDenoising(src1, DENO, 19, 29, 38);
imwrite("DENO.png", DENO);
end = clock();
int runtime = ((int)(end - start)) / CLOCKS_PER_SEC;
cout << "Time1 = " << runtime << "s" << endl;
//part of code that I want to show run time progress by progress bar
value = gtk_progress_bar_get_fraction(GTK_PROGRESS_BAR(data));
value += 0.01;
if (value > 1.0) {
value = 0.0;
}
text = g_string_new(gtk_progress_bar_get_text(GTK_PROGRESS_BAR(data)));
g_string_sprintf(text, "%d%%", (int)(value * 100));
gtk_progress_bar_set_fraction(GTK_PROGRESS_BAR(data), value);
gtk_progress_bar_set_show_text(GTK_PROGRESS_BAR(data), TRUE);
gtk_progress_bar_set_text(GTK_PROGRESS_BAR(data), text->str);
while (gtk_events_pending())
gtk_main_iteration();
return TRUE;
}
int main(int argc, char *argv[])
{
GtkWidget *window;
GtkWidget *progressBar;
gint timer;
gtk_init(&argc, &argv);
window = gtk_window_new(GTK_WINDOW_TOPLEVEL);
gtk_window_set_title(GTK_WINDOW(window), "GtkProgressBar");
gtk_window_set_default_size(GTK_WINDOW(window), 300, 30);
progressBar = gtk_progress_bar_new();
timer = g_timeout_add(100, Func, progressBar);
gtk_container_add(GTK_CONTAINER(window), progressBar);
gtk_widget_show_all(window);
gtk_main();
return 0;
}
这是我的形象:
但我无法将这些代码组合在一起以显示项目的进度运行时间。我是gtk3的新手。有没有人对此有任何想法或建议?