2015-05-25 11:41:04 +00:00
|
|
|
/* GStreamer
|
|
|
|
*
|
|
|
|
* Copyright (C) 2014 Mathieu Duponchelle <mathieu.duponchelle@opencreed.com>
|
|
|
|
* Copyright (C) 2015 Raspberry Pi Foundation
|
|
|
|
* Author: Thibault Saunier <thibault.saunier@collabora.com>
|
|
|
|
*
|
|
|
|
* This library is free software; you can redistribute it and/or
|
|
|
|
* modify it under the terms of the GNU Lesser General Public
|
|
|
|
* License as published by the Free Software Foundation; either
|
|
|
|
* version 2.1 of the License, or (at your option) any later version.
|
|
|
|
*
|
|
|
|
* This library is distributed in the hope that it will be useful,
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
|
|
|
* Lesser General Public License for more details.
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU Lesser General Public
|
|
|
|
* License along with this library; if not, write to the
|
|
|
|
* Free Software Foundation, Inc., 59 Temple Place - Suite 330,
|
|
|
|
* Boston, MA 02111-1307, USA.
|
|
|
|
*/
|
|
|
|
|
2015-06-08 16:20:33 +00:00
|
|
|
#include "../gst-libs/gst/video/gstvalidatessim.h"
|
2015-05-25 11:41:04 +00:00
|
|
|
|
|
|
|
#include <gst/gst.h>
|
|
|
|
#include <gst/validate/validate.h>
|
|
|
|
#include <gst/video/video.h>
|
2015-08-11 01:05:41 +00:00
|
|
|
#include <locale.h> /* for LC_ALL */
|
2015-05-25 11:41:04 +00:00
|
|
|
|
2024-06-18 13:53:27 +00:00
|
|
|
static int
|
|
|
|
real_main (int argc, char **argv)
|
2015-05-25 11:41:04 +00:00
|
|
|
{
|
|
|
|
GstValidateSsim *ssim;
|
|
|
|
gint rep_err, ret = 0;
|
|
|
|
GError *err = NULL;
|
|
|
|
GstValidateRunner *runner = NULL;
|
|
|
|
GOptionContext *ctx;
|
2017-05-01 20:51:48 +00:00
|
|
|
gchar *outfolder = NULL;
|
2015-05-25 11:41:04 +00:00
|
|
|
gfloat mssim = 0, lowest = 1, highest = -1;
|
|
|
|
gdouble min_avg_similarity = 0.95, min_lowest_similarity = -1.0;
|
|
|
|
|
|
|
|
GOptionEntry options[] = {
|
|
|
|
{"min-avg-similarity", 'a', 0, G_OPTION_ARG_DOUBLE,
|
|
|
|
&min_avg_similarity,
|
|
|
|
"The minimum average similarity under which we consider"
|
2017-03-20 21:36:36 +00:00
|
|
|
" the test as failing",
|
2015-05-25 11:41:04 +00:00
|
|
|
NULL},
|
|
|
|
{"min-lowest-similarity", 'l', 0, G_OPTION_ARG_DOUBLE,
|
|
|
|
&min_lowest_similarity,
|
|
|
|
"The minimum 'lowest' similarity under which we consider"
|
2017-03-20 21:36:36 +00:00
|
|
|
" the test as failing",
|
2015-05-25 11:41:04 +00:00
|
|
|
NULL},
|
2015-08-11 01:05:41 +00:00
|
|
|
{"result-output-folder", 'r', 0, G_OPTION_ARG_FILENAME,
|
2015-05-25 11:41:04 +00:00
|
|
|
&outfolder,
|
|
|
|
"The folder in which to store resulting grey scale images"
|
|
|
|
" when the test failed. In that folder you will find"
|
|
|
|
" images with the structural difference between"
|
|
|
|
" the reference frame and the failed one",
|
|
|
|
NULL},
|
|
|
|
{NULL}
|
|
|
|
};
|
|
|
|
|
2015-08-11 01:05:41 +00:00
|
|
|
setlocale (LC_ALL, "");
|
|
|
|
|
2017-12-29 02:25:05 +00:00
|
|
|
g_set_prgname ("gst-validate-images-check-" GST_API_VERSION);
|
2015-05-25 11:41:04 +00:00
|
|
|
ctx = g_option_context_new ("/reference/file/path /compared/file/path");
|
|
|
|
|
|
|
|
g_option_context_set_summary (ctx,
|
2017-05-04 21:45:32 +00:00
|
|
|
"The gst-validate-images-check calculates SSIM (Structural SIMilarity)"
|
2015-05-25 11:41:04 +00:00
|
|
|
" index for the images. And according to min-lowest-similarity and"
|
2016-03-08 06:54:32 +00:00
|
|
|
" min-avg-similarity, it will consider the images similar enough"
|
2015-05-25 11:41:04 +00:00
|
|
|
" or report critical issues in the GstValidate reporting system");
|
|
|
|
g_option_context_add_main_entries (ctx, options, NULL);
|
|
|
|
|
|
|
|
if (!g_option_context_parse (ctx, &argc, &argv, &err)) {
|
|
|
|
g_printerr ("Error initializing: %s\n", err->message);
|
|
|
|
g_option_context_free (ctx);
|
2015-08-20 07:51:03 +00:00
|
|
|
g_clear_error (&err);
|
2015-05-25 11:41:04 +00:00
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (argc != 3) {
|
|
|
|
gchar *help = g_option_context_get_help (ctx, FALSE, NULL);
|
|
|
|
g_printerr ("%s", help);
|
|
|
|
g_free (help);
|
|
|
|
g_option_context_free (ctx);
|
|
|
|
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
|
|
|
gst_init (&argc, &argv);
|
|
|
|
gst_validate_init ();
|
|
|
|
|
|
|
|
runner = gst_validate_runner_new ();
|
|
|
|
ssim =
|
2020-03-04 14:07:32 +00:00
|
|
|
gst_validate_ssim_new (runner, min_avg_similarity, min_lowest_similarity,
|
|
|
|
0, 1);
|
2015-05-25 11:41:04 +00:00
|
|
|
|
|
|
|
gst_validate_ssim_compare_image_files (ssim, argv[1], argv[2], &mssim,
|
|
|
|
&lowest, &highest, outfolder);
|
|
|
|
|
2015-06-18 09:09:26 +00:00
|
|
|
if (!g_file_test (argv[1], G_FILE_TEST_IS_DIR)) {
|
|
|
|
gst_validate_printf (ssim, "Compared %s with %s, average: %f, Min %f\n",
|
|
|
|
argv[1], argv[2], mssim, lowest);
|
|
|
|
}
|
|
|
|
|
2015-05-25 11:41:04 +00:00
|
|
|
rep_err = gst_validate_runner_exit (runner, TRUE);
|
|
|
|
if (ret == 0) {
|
|
|
|
ret = rep_err;
|
|
|
|
if (rep_err != 0)
|
2020-05-03 04:54:56 +00:00
|
|
|
gst_validate_printf (NULL, "Returning %d as error where found", rep_err);
|
2015-05-25 11:41:04 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
g_object_unref (ssim);
|
|
|
|
g_object_unref (runner);
|
|
|
|
gst_validate_deinit ();
|
|
|
|
|
2020-05-03 04:54:56 +00:00
|
|
|
gst_validate_printf (NULL, "\n=======> Test %s (Return value: %i)\n\n",
|
2015-08-24 07:39:15 +00:00
|
|
|
ret == 0 ? "PASSED" : "FAILED", ret);
|
|
|
|
|
2015-05-25 11:41:04 +00:00
|
|
|
return ret;
|
|
|
|
}
|
2024-06-18 13:53:27 +00:00
|
|
|
|
|
|
|
int
|
|
|
|
main (int argc, char *argv[])
|
|
|
|
{
|
|
|
|
int ret;
|
|
|
|
|
|
|
|
#ifdef G_OS_WIN32
|
|
|
|
argv = g_win32_get_command_line ();
|
|
|
|
#endif
|
|
|
|
|
|
|
|
#if defined(__APPLE__) && TARGET_OS_MAC && !TARGET_OS_IPHONE
|
|
|
|
ret = gst_macos_main ((GstMainFunc) real_main, argc, argv, NULL);
|
|
|
|
#else
|
|
|
|
ret = real_main (argc, argv);
|
|
|
|
#endif
|
|
|
|
|
|
|
|
#ifdef G_OS_WIN32
|
|
|
|
g_strfreev (argv);
|
|
|
|
#endif
|
|
|
|
|
|
|
|
return ret;
|
|
|
|
}
|