diff options
author | Matthias Vogelgesang <matthias.vogelgesang@kit.edu> | 2017-10-18 11:15:06 +0200 |
---|---|---|
committer | Matthias Vogelgesang <matthias.vogelgesang@kit.edu> | 2017-10-18 11:17:13 +0200 |
commit | c5c552c894a47326472baa9484c98fcda5a1ba34 (patch) | |
tree | acf220f4a8af73f4e4306ea9c8cf314b47b17b82 | |
parent | af5d76334b5998ef69bbfc41e0b3390612820648 (diff) | |
download | ufo-filters-c5c552c894a47326472baa9484c98fcda5a1ba34.tar.gz ufo-filters-c5c552c894a47326472baa9484c98fcda5a1ba34.tar.bz2 ufo-filters-c5c552c894a47326472baa9484c98fcda5a1ba34.tar.xz ufo-filters-c5c552c894a47326472baa9484c98fcda5a1ba34.zip |
Add cv-show processor
This task uses the OpenCV imshow function to display results from a stream.
-rw-r--r-- | CMakeLists.txt | 6 | ||||
-rw-r--r-- | docs/filters.rst | 17 | ||||
-rw-r--r-- | src/CMakeLists.txt | 7 | ||||
-rw-r--r-- | src/meson.build | 14 | ||||
-rw-r--r-- | src/ufo-cv-show-task.cpp | 224 | ||||
-rw-r--r-- | src/ufo-cv-show-task.h | 53 |
6 files changed, 320 insertions, 1 deletions
diff --git a/CMakeLists.txt b/CMakeLists.txt index e508da4..89c2890 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -1,5 +1,9 @@ cmake_minimum_required(VERSION 2.8) +if (POLICY CMP0018) +cmake_policy(SET CMP0018 OLD) +endif () + if (POLICY CMP0046) cmake_policy(SET CMP0046 OLD) endif () @@ -12,7 +16,7 @@ if (POLICY CMP0054) cmake_policy(SET CMP0054 OLD) endif () -project(ufo C) +project(ufo C CXX) set(TARNAME "ufo-filters") diff --git a/docs/filters.rst b/docs/filters.rst index b8023f2..9c8d7c0 100644 --- a/docs/filters.rst +++ b/docs/filters.rst @@ -1084,3 +1084,20 @@ Sleep Time to sleep in seconds. + +Display +------- + +.. gobj:class:: cv-show + + Shows the input using an OpenCV window. + + .. gobj:prop:: min:float + + Minimum for display value scaling. If not set, will be determined at + run-time. + + .. gobj:prop:: max:float + + Maximum for display value scaling. If not set, will be determined at + run-time. diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt index 69707a5..54b59ed 100644 --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -131,6 +131,7 @@ pkg_check_modules(GSL gsl) pkg_check_modules(CLFFT clFFT) pkg_check_modules(CLBLAST clblast) pkg_check_modules(PANGOCAIRO pangocairo) +pkg_check_modules(OPENCV opencv) if (OPENMP_FOUND) @@ -241,6 +242,12 @@ if (PANGOCAIRO_FOUND) list(APPEND stamp_aux_LIBS ${PANGOCAIRO_LIBRARIES}) endif () +if (OPENCV_FOUND) + include_directories(${OPENCV_INCLUDE_DIRS}) + list(APPEND ufofilter_SRCS ufo-cv-show-task.cpp) + list(APPEND cv_show_aux_LIBS ${OPENCV_LIBRARIES}) + list(APPEND cv_show_aux_SRCS writers/ufo-writer.c) +endif () #}}} #{{{ Plugin targets include_directories(${CMAKE_CURRENT_BINARY_DIR} diff --git a/src/meson.build b/src/meson.build index 44f589b..ec0f440 100644 --- a/src/meson.build +++ b/src/meson.build @@ -96,6 +96,7 @@ hdf5_dep = dependency('hdf5', required: false) jpeg_dep = dependency('libjpeg', required: false) gsl_dep = dependency('gsl', required: false) pangocairo_dep = dependency('pangocairo', required: false) +opencv_dep = dependency('opencv', required: false) conf = configuration_data() conf.set('HAVE_TIFF', tiff_dep.found()) @@ -201,6 +202,19 @@ shared_module('write', install_dir: plugin_install_dir, ) +# cvshow + +if opencv_dep.found() + shared_module('cvshow', + sources: ['writers/ufo-writer.c', 'ufo-cv-show-task.cpp'], + #c_args: ['-x', 'c++'], + dependencies: deps + [opencv_dep], + name_prefix: 'libufofilter', + install: true, + install_dir: plugin_install_dir, + ) +endif + # measure if gsl_dep.found() diff --git a/src/ufo-cv-show-task.cpp b/src/ufo-cv-show-task.cpp new file mode 100644 index 0000000..34f142b --- /dev/null +++ b/src/ufo-cv-show-task.cpp @@ -0,0 +1,224 @@ +/* + * Copyright (C) 2011-2015 Karlsruhe Institute of Technology + * + * This file is part of Ufo. + * + * 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 3 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, see <http://www.gnu.org/licenses/>. + */ + +#ifdef __APPLE__ +#include <OpenCL/cl.h> +#else +#include <CL/cl.h> +#endif + +#include <highgui.h> +#include "ufo-cv-show-task.h" +#include "writers/ufo-writer.h" + + +struct _UfoCvShowTaskPrivate { + gfloat min; + gfloat max; +}; + +static void ufo_task_interface_init (UfoTaskIface *iface); + +G_DEFINE_TYPE_WITH_CODE (UfoCvShowTask, ufo_cv_show_task, UFO_TYPE_TASK_NODE, + G_IMPLEMENT_INTERFACE (UFO_TYPE_TASK, + ufo_task_interface_init)) + +#define UFO_CV_SHOW_TASK_GET_PRIVATE(obj) (G_TYPE_INSTANCE_GET_PRIVATE((obj), UFO_TYPE_CV_SHOW_TASK, UfoCvShowTaskPrivate)) + +enum { + PROP_0, + PROP_MINIMUM, + PROP_MAXIMUM, + N_PROPERTIES +}; + +static GParamSpec *properties[N_PROPERTIES] = { NULL, }; + +UfoNode * +ufo_cv_show_task_new (void) +{ + return UFO_NODE (g_object_new (UFO_TYPE_CV_SHOW_TASK, NULL)); +} + +static void +ufo_cv_show_task_setup (UfoTask *task, + UfoResources *resources, + GError **error) +{ + cv::namedWindow("cvshow", 1); +} + +static void +ufo_cv_show_task_get_requisition (UfoTask *task, + UfoBuffer **inputs, + UfoRequisition *requisition) +{ + ufo_buffer_get_requisition (inputs[0], requisition); +} + +static guint +ufo_cv_show_task_get_num_inputs (UfoTask *task) +{ + return 1; +} + +static guint +ufo_cv_show_task_get_num_dimensions (UfoTask *task, + guint input) +{ + return 2; +} + +static UfoTaskMode +ufo_cv_show_task_get_mode (UfoTask *task) +{ + return UFO_TASK_MODE_PROCESSOR; +} + +static gboolean +ufo_cv_show_task_process (UfoTask *task, + UfoBuffer **inputs, + UfoBuffer *output, + UfoRequisition *requisition) +{ + UfoCvShowTaskPrivate *priv; + UfoWriterImage image; + + priv = UFO_CV_SHOW_TASK_GET_PRIVATE (task); + ufo_buffer_copy (inputs[0], output); + + /* + * We do the conversion ourselves because OpenCV would just map [0.0, 1.0] + * to [0, 255]. + */ + image.depth = UFO_BUFFER_DEPTH_8U; + image.requisition = requisition; + image.min = priv->min; + image.max = priv->max; + image.data = (guint8 *) ufo_buffer_get_host_array (inputs[0], NULL); + + ufo_writer_convert_inplace (&image); + + cv::Mat frame (requisition->dims[1], requisition->dims[0], CV_8UC1, image.data); + cv::imshow ("cvshow", frame); + cv::waitKey (1); + + return TRUE; +} + +static void +ufo_cv_show_task_set_property (GObject *object, + guint property_id, + const GValue *value, + GParamSpec *pspec) +{ + UfoCvShowTaskPrivate *priv = UFO_CV_SHOW_TASK_GET_PRIVATE (object); + + switch (property_id) { + case PROP_MAXIMUM: + priv->max = g_value_get_float (value); + break; + case PROP_MINIMUM: + priv->min = g_value_get_float (value); + break; + default: + G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec); + break; + } +} + +static void +ufo_cv_show_task_get_property (GObject *object, + guint property_id, + GValue *value, + GParamSpec *pspec) +{ + UfoCvShowTaskPrivate *priv = UFO_CV_SHOW_TASK_GET_PRIVATE (object); + + switch (property_id) { + case PROP_MAXIMUM: + g_value_set_float (value, priv->max); + break; + case PROP_MINIMUM: + g_value_set_float (value, priv->min); + break; + default: + G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec); + break; + } +} + +static void +ufo_cv_show_task_finalize (GObject *object) +{ + G_OBJECT_CLASS (ufo_cv_show_task_parent_class)->finalize (object); +} + +static void +ufo_task_interface_init (UfoTaskIface *iface) +{ + iface->setup = ufo_cv_show_task_setup; + iface->get_num_inputs = ufo_cv_show_task_get_num_inputs; + iface->get_num_dimensions = ufo_cv_show_task_get_num_dimensions; + iface->get_mode = ufo_cv_show_task_get_mode; + iface->get_requisition = ufo_cv_show_task_get_requisition; + iface->process = ufo_cv_show_task_process; +} + +static void +ufo_cv_show_task_class_init (UfoCvShowTaskClass *klass) +{ + GObjectClass *oclass = G_OBJECT_CLASS (klass); + + oclass->set_property = ufo_cv_show_task_set_property; + oclass->get_property = ufo_cv_show_task_get_property; + oclass->finalize = ufo_cv_show_task_finalize; + + properties[PROP_MINIMUM] = + g_param_spec_float ("min", + "Minimum value for data conversion", + "Minimum value for data conversion", + -G_MAXFLOAT, +G_MAXFLOAT, +G_MAXFLOAT, + G_PARAM_READWRITE); + + properties[PROP_MAXIMUM] = + g_param_spec_float ("max", + "Minimum value for data conversion", + "Minimum value for data conversion", + -G_MAXFLOAT, +G_MAXFLOAT, -G_MAXFLOAT, + G_PARAM_READWRITE); + + for (guint i = PROP_0 + 1; i < N_PROPERTIES; i++) + g_object_class_install_property (oclass, i, properties[i]); + + g_type_class_add_private (oclass, sizeof(UfoCvShowTaskPrivate)); +} + +static void +ufo_cv_show_task_init(UfoCvShowTask *self) +{ + self->priv = UFO_CV_SHOW_TASK_GET_PRIVATE(self); + + /* + * Set to extreme ends, so that we look for the extrema if not set by the + * user. + */ + self->priv->min = +G_MAXFLOAT; + self->priv->max = -G_MAXFLOAT; +} diff --git a/src/ufo-cv-show-task.h b/src/ufo-cv-show-task.h new file mode 100644 index 0000000..6b9a7ed --- /dev/null +++ b/src/ufo-cv-show-task.h @@ -0,0 +1,53 @@ +/* + * Copyright (C) 2011-2013 Karlsruhe Institute of Technology + * + * This file is part of Ufo. + * + * 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 3 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, see <http://www.gnu.org/licenses/>. + */ + +#ifndef __UFO_CV_SHOW_TASK_H +#define __UFO_CV_SHOW_TASK_H + +#include <ufo/ufo.h> + +G_BEGIN_DECLS + +#define UFO_TYPE_CV_SHOW_TASK (ufo_cv_show_task_get_type()) +#define UFO_CV_SHOW_TASK(obj) (G_TYPE_CHECK_INSTANCE_CAST((obj), UFO_TYPE_CV_SHOW_TASK, UfoCvShowTask)) +#define UFO_IS_CV_SHOW_TASK(obj) (G_TYPE_CHECK_INSTANCE_TYPE((obj), UFO_TYPE_CV_SHOW_TASK)) +#define UFO_CV_SHOW_TASK_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST((klass), UFO_TYPE_CV_SHOW_TASK, UfoCvShowTaskClass)) +#define UFO_IS_CV_SHOW_TASK_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE((klass), UFO_TYPE_CV_SHOW_TASK)) +#define UFO_CV_SHOW_TASK_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS((obj), UFO_TYPE_CV_SHOW_TASK, UfoCvShowTaskClass)) + +typedef struct _UfoCvShowTask UfoCvShowTask; +typedef struct _UfoCvShowTaskClass UfoCvShowTaskClass; +typedef struct _UfoCvShowTaskPrivate UfoCvShowTaskPrivate; + +struct _UfoCvShowTask { + UfoTaskNode parent_instance; + + UfoCvShowTaskPrivate *priv; +}; + +struct _UfoCvShowTaskClass { + UfoTaskNodeClass parent_class; +}; + +UfoNode *ufo_cv_show_task_new (void); +GType ufo_cv_show_task_get_type (void); + +G_END_DECLS + +#endif |