1
0
mirror of https://bitbucket.org/librepilot/librepilot.git synced 2025-02-20 10:54:14 +01:00

LP-109 video: cleanup camera calibration plugin

This commit is contained in:
Philippe Renon 2017-07-15 12:33:01 +02:00
parent ba29f527fa
commit d78472b59c
14 changed files with 12 additions and 707 deletions

View File

@ -9,7 +9,7 @@ include(../utils/utils.pri)
include(gstreamer_dependencies.pri)
gstreamer_plugins:include(plugins/plugins.pro)
include(plugins/plugins.pro)
HEADERS += \
gst_global.h \

View File

@ -1,7 +1,5 @@
/* GStreamer
* Copyright (C) <1999> Erik Walthinsen <omega@cse.ogi.edu>
* Library <2002> Ronald Bultje <rbultje@ronald.bitfreak.net>
* Copyright (C) 2007 David A. Schleef <ds@schleef.org>
* Copyright (C) <2017> Philippe Renon <philippe_renon@yahoo.fr>
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Library General Public

View File

@ -1,5 +1,5 @@
/* GStreamer
* Copyright (C) <2011> Wim Taymans <wim.taymans@gmail.com>
* Copyright (C) <2017> Philippe Renon <philippe_renon@yahoo.fr>
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Library General Public

View File

@ -1,7 +1,5 @@
/* GStreamer
* Copyright (C) <1999> Erik Walthinsen <omega@cse.ogi.edu>
* Library <2002> Ronald Bultje <rbultje@ronald.bitfreak.net>
* Copyright (C) 2007 David A. Schleef <ds@schleef.org>
* Copyright (C) <2017> Philippe Renon <philippe_renon@yahoo.fr>
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Library General Public

View File

@ -1,5 +1,5 @@
/* GStreamer
* Copyright (C) <2011> Wim Taymans <wim.taymans@gmail.com>
* Copyright (C) <2017> Philippe Renon <philippe_renon@yahoo.fr>
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Library General Public

View File

@ -1,10 +1,6 @@
/*
* GStreamer
* Copyright (C) 2005 Thomas Vander Stichele <thomas@apestaart.org>
* Copyright (C) 2005 Ronald S. Bultje <rbultje@ronald.bitfreak.net>
* Copyright (C) 2008 Michael Sheldon <mike@mikeasoft.com>
* Copyright (C) 2011 Stefan Sauer <ensonic@users.sf.net>
* Copyright (C) 2014 Robert Jobbagy <jobbagy.robert@gmail.com>
* Copyright (C) <2017> Philippe Renon <philippe_renon@yahoo.fr>
*
* Permission is hereby granted, free of charge, to any person obtaining a
* copy of this software and associated documentation files (the "Software"),
@ -48,28 +44,7 @@
/**
* SECTION:element-cameracalibration
*
* Performs face detection on videos and images.
* If you have high cpu load you need to use videoscale with capsfilter and reduce the video resolution.
*
* The image is scaled down multiple times using the GstCameraCalibration::scale-factor
* until the size is &lt;= GstCameraCalibration::min-size-width or
* GstCameraCalibration::min-size-height.
*
* <refsect2>
* <title>Example launch line</title>
* |[
* gst-launch-1.0 autovideosrc ! decodebin ! colorspace ! cameracalibration ! videoconvert ! xvimagesink
* ]| Detect and show faces
* |[
* gst-launch-1.0 autovideosrc ! video/x-raw,width=320,height=240 ! videoconvert ! cameracalibration min-size-width=60 min-size-height=60 ! colorspace ! xvimagesink
* ]| Detect large faces on a smaller image
*
* </refsect2>
*/
/* FIXME: development version of OpenCV has CV_HAAR_FIND_BIGGEST_OBJECT which
* we might want to use if available
* see https://code.ros.org/svn/opencv/trunk/opencv/modules/objdetect/src/haar.cpp
* Performs fcamera calibration.
*/
#ifdef HAVE_CONFIG_H

View File

@ -1,10 +1,6 @@
/*
* GStreamer
* Copyright (C) 2005 Thomas Vander Stichele <thomas@apestaart.org>
* Copyright (C) 2005 Ronald S. Bultje <rbultje@ronald.bitfreak.net>
* Copyright (C) 2008 Michael Sheldon <mike@mikeasoft.com>
* Copyright (C) 2011 Stefan Sauer <ensonic@users.sf.net>
* Copyright (C) 2011 Robert Jobbagy <jobbagy.robert@gmail.com>
* Copyright (C) <2017> Philippe Renon <philippe_renon@yahoo.fr>
*
* Permission is hereby granted, free of charge, to any person obtaining a
* copy of this software and associated documentation files (the "Software"),

View File

@ -1,10 +1,6 @@
/*
* GStreamer
* Copyright (C) 2005 Thomas Vander Stichele <thomas@apestaart.org>
* Copyright (C) 2005 Ronald S. Bultje <rbultje@ronald.bitfreak.net>
* Copyright (C) 2008 Michael Sheldon <mike@mikeasoft.com>
* Copyright (C) 2011 Stefan Sauer <ensonic@users.sf.net>
* Copyright (C) 2014 Robert Jobbagy <jobbagy.robert@gmail.com>
* Copyright (C) <2017> Philippe Renon <philippe_renon@yahoo.fr>
*
* Permission is hereby granted, free of charge, to any person obtaining a
* copy of this software and associated documentation files (the "Software"),
@ -48,28 +44,8 @@
/**
* SECTION:element-cameraundistort
*
* Performs face detection on videos and images.
* If you have high cpu load you need to use videoscale with capsfilter and reduce the video resolution.
* Performs camera distortion correction.
*
* The image is scaled down multiple times using the GstCameraCalibration::scale-factor
* until the size is &lt;= GstCameraCalibration::min-size-width or
* GstCameraCalibration::min-size-height.
*
* <refsect2>
* <title>Example launch line</title>
* |[
* gst-launch-1.0 autovideosrc ! decodebin ! colorspace ! cameraundistort ! videoconvert ! xvimagesink
* ]| Detect and show faces
* |[
* gst-launch-1.0 autovideosrc ! video/x-raw,width=320,height=240 ! videoconvert ! cameraundistort min-size-width=60 min-size-height=60 ! colorspace ! xvimagesink
* ]| Detect large faces on a smaller image
*
* </refsect2>
*/
/* FIXME: development version of OpenCV has CV_HAAR_FIND_BIGGEST_OBJECT which
* we might want to use if available
* see https://code.ros.org/svn/opencv/trunk/opencv/modules/objdetect/src/haar.cpp
*/
#ifdef HAVE_CONFIG_H
@ -174,7 +150,7 @@ gst_camera_undistort_class_init (GstCameraUndistortClass * klass)
g_object_class_install_property (gobject_class, PROP_ALPHA,
g_param_spec_float ("alpha", "Pixels",
"Pixels bla bla...",
"Show all pixels (1), only valid ones (0) or something in between",
0.0, 1.0, DEFAULT_ALPHA,
(GParamFlags) (G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS)));

View File

@ -1,10 +1,6 @@
/*
* GStreamer
* Copyright (C) 2005 Thomas Vander Stichele <thomas@apestaart.org>
* Copyright (C) 2005 Ronald S. Bultje <rbultje@ronald.bitfreak.net>
* Copyright (C) 2008 Michael Sheldon <mike@mikeasoft.com>
* Copyright (C) 2011 Stefan Sauer <ensonic@users.sf.net>
* Copyright (C) 2011 Robert Jobbagy <jobbagy.robert@gmail.com>
* Copyright (C) <2017> Philippe Renon <philippe_renon@yahoo.fr>
*
* Permission is hereby granted, free of charge, to any person obtaining a
* copy of this software and associated documentation files (the "Software"),
@ -51,7 +47,6 @@
#include <gst/gst.h>
#include <gst/opencv/gstopencvvideofilter.h>
//#include "gstopencvvideofilter.h"
#include <opencv2/core.hpp>

View File

@ -1,178 +0,0 @@
/* GStreamer
* Copyright (C) <2010> Thiago Santos <thiago.sousa.santos@collabora.co.uk>
*
* gstopencvutils.c: miscellaneous utility functions
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Library General Public
* License as published by the Free Software Foundation; either
* version 2 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
* Library General Public License for more details.
*
* You should have received a copy of the GNU Library General Public
* License along with this library; if not, write to the
* Free Software Foundation, Inc., 51 Franklin St, Fifth Floor,
* Boston, MA 02110-1301, USA.
*/
#ifdef HAVE_CONFIG_H
#include "config.h"
#endif
#include "gstopencvutils.h"
#include <opencv2/core/core_c.h>
/*
The various opencv image containers or headers store the following information:
- number of channels (usually 1, 3 or 4)
- depth (8, 16, 32, 64...); all channels have the same depth.
The channel layout (BGR vs RGB) is not stored...
This gives us the following list of supported image formats:
CV_8UC1, CV_8UC2, CV_8UC3, CV_8UC4
CV_8SC1, CV_8SC2, CV_8SC3, CV_8SC4
CV_16UC1, CV_16UC2, CV_16UC3, CV_16UC4
CV_16SC1, CV_16SC2, CV_16SC3, CV_16SC4
CV_32SC1, CV_32SC2, CV_32SC3, CV_32SC4
CV_32FC1, CV_32FC2, CV_32FC3, CV_32FC4
CV_64FC1, CV_64FC2, CV_64FC3, CV_64FC4
Where the first part of the format name is the depth followed by a digit
representing the number of channels.
Note that opencv supports more that 4 channels.
The opencv algorithms don't all support all the image types.
For example findChessboardCorners() supports only 8 bits formats
(gray scale and color).
And, typically, this algorithm will convert the image to gray scale before
proceeding. It will do so with something like this:
cvtColor(srcImg, destImg, CV_BGR2GRAY);
The conversion will work on any BGR format (BGR, BGRA, BGRx).
The extra channel(s) will be ignored.
It will also produce a result for any RGB format.
The result will be "wrong" to the human eye and might affect some algorithms
(not findChessboardCorners() afaik...).
This is due to how RGB gets converted to gray where each color has a
different weight.
Another example is the 2D rendering API.
It work with RGB but the colors will be wrong.
Likewise other layouts like xBGR and ABGR formats will probably misbehave
with most algorithms.
The bad thing is that it is not possible to change the "default" BGR format.
Safest is to not assume that RGB will work and always convert to BGR.
That said, the current opencv gstreamer elements all accept BGR and RGB caps !
Some have restrictions but if a format is supported then both BGR and RGB
layouts will be supported.
*/
gboolean
gst_opencv_parse_iplimage_params_from_caps (GstCaps * caps, gint * width,
gint * height, gint * ipldepth, gint * channels, GError ** err)
{
GstVideoInfo info;
GstVideoFormat format;
int cv_type;
gchar *caps_str;
if (!gst_video_info_from_caps (&info, caps)) {
caps_str = gst_caps_to_string (caps);
GST_ERROR ("Failed to get video info from caps %s", caps_str);
g_set_error (err, GST_CORE_ERROR, GST_CORE_ERROR_NEGOTIATION,
"Failed to get video info from caps %s", caps_str);
g_free (caps_str);
return FALSE;
}
format = GST_VIDEO_INFO_FORMAT (&info);
if (!gst_opencv_cv_image_type_from_video_format (format, &cv_type, err)) {
return FALSE;
}
*width = GST_VIDEO_INFO_WIDTH (&info);
*height = GST_VIDEO_INFO_HEIGHT (&info);
*ipldepth = cvIplDepth (cv_type);
*channels = CV_MAT_CN (cv_type);
return TRUE;
}
gboolean
gst_opencv_cv_image_type_from_video_format (GstVideoFormat format,
int * cv_type, GError ** err)
{
const gchar *format_str;
switch (format) {
case GST_VIDEO_FORMAT_GRAY8:
*cv_type = CV_8UC1;
break;
case GST_VIDEO_FORMAT_RGB:
case GST_VIDEO_FORMAT_BGR:
*cv_type = CV_8UC3;
break;
case GST_VIDEO_FORMAT_RGBx:
case GST_VIDEO_FORMAT_xRGB:
case GST_VIDEO_FORMAT_BGRx:
case GST_VIDEO_FORMAT_xBGR:
case GST_VIDEO_FORMAT_RGBA:
case GST_VIDEO_FORMAT_ARGB:
case GST_VIDEO_FORMAT_BGRA:
case GST_VIDEO_FORMAT_ABGR:
*cv_type = CV_8UC4;
break;
case GST_VIDEO_FORMAT_GRAY16_LE:
case GST_VIDEO_FORMAT_GRAY16_BE:
*cv_type = CV_16UC1;
break;
default:
format_str = gst_video_format_to_string (format);
g_set_error (err, GST_CORE_ERROR, GST_CORE_ERROR_NEGOTIATION,
"Unsupported video format %s", format_str);
return FALSE;
}
return TRUE;
}
GstCaps *
gst_opencv_caps_from_cv_image_type (int cv_type)
{
GstCaps *c = gst_caps_new_empty ();
switch (cv_type) {
case CV_8UC1:
gst_caps_append (c, gst_caps_from_string (GST_VIDEO_CAPS_MAKE ("GRAY8")));
break;
case CV_8UC3:
gst_caps_append (c, gst_caps_from_string (GST_VIDEO_CAPS_MAKE ("RGB")));
gst_caps_append (c, gst_caps_from_string (GST_VIDEO_CAPS_MAKE ("BGR")));
break;
case CV_8UC4:
gst_caps_append (c, gst_caps_from_string (GST_VIDEO_CAPS_MAKE ("RGBx")));
gst_caps_append (c, gst_caps_from_string (GST_VIDEO_CAPS_MAKE ("xRGB")));
gst_caps_append (c, gst_caps_from_string (GST_VIDEO_CAPS_MAKE ("BGRx")));
gst_caps_append (c, gst_caps_from_string (GST_VIDEO_CAPS_MAKE ("xBGR")));
gst_caps_append (c, gst_caps_from_string (GST_VIDEO_CAPS_MAKE ("RGBA")));
gst_caps_append (c, gst_caps_from_string (GST_VIDEO_CAPS_MAKE ("ARGB")));
gst_caps_append (c, gst_caps_from_string (GST_VIDEO_CAPS_MAKE ("BGRA")));
gst_caps_append (c, gst_caps_from_string (GST_VIDEO_CAPS_MAKE ("ABGR")));
break;
case CV_16UC1:
gst_caps_append (c,
gst_caps_from_string (GST_VIDEO_CAPS_MAKE ("GRAY16_LE")));
gst_caps_append (c,
gst_caps_from_string (GST_VIDEO_CAPS_MAKE ("GRAY16_BE")));
break;
}
return c;
}

View File

@ -1,46 +0,0 @@
/* GStreamer
* Copyright (C) <2010> Thiago Santos <thiago.sousa.santos@collabora.co.uk>
*
* gstopencvutils.h: miscellaneous utility functions
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Library General Public
* License as published by the Free Software Foundation; either
* version 2 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
* Library General Public License for more details.
*
* You should have received a copy of the GNU Library General Public
* License along with this library; if not, write to the
* Free Software Foundation, Inc., 51 Franklin St, Fifth Floor,
* Boston, MA 02110-1301, USA.
*/
#ifndef __GST_OPENCV_UTILS__
#define __GST_OPENCV_UTILS__
#ifdef HAVE_CONFIG_H
#include "config.h"
#endif
#include <gst/gst.h>
#include <gst/video/video.h>
G_BEGIN_DECLS
gboolean gst_opencv_parse_iplimage_params_from_caps
(GstCaps * caps, gint * width, gint * height, gint * depth,
gint * channels, GError ** err);
gboolean
gst_opencv_cv_image_type_from_video_format (GstVideoFormat format,
int * cv_type, GError ** err);
GstCaps * gst_opencv_caps_from_cv_image_type (int cv_type);
G_END_DECLS
#endif /* __GST_OPENCV_UTILS__ */

View File

@ -1,289 +0,0 @@
/*
* GStreamer
* Copyright (C) 2010 Thiago Santos <thiago.sousa.santos@collabora.co.uk>
*
* Permission is hereby granted, free of charge, to any person obtaining a
* copy of this software and associated documentation files (the "Software"),
* to deal in the Software without restriction, including without limitation
* the rights to use, copy, modify, merge, publish, distribute, sublicense,
* and/or sell copies of the Software, and to permit persons to whom the
* Software is furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in
* all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
* FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
* DEALINGS IN THE SOFTWARE.
*
* Alternatively, the contents of this file may be used under the
* GNU Lesser General Public License Version 2.1 (the "LGPL"), in
* which case the following provisions apply instead of the ones
* mentioned above:
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Library General Public
* License as published by the Free Software Foundation; either
* version 2 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
* Library General Public License for more details.
*
* You should have received a copy of the GNU Library General Public
* License along with this library; if not, write to the
* Free Software Foundation, Inc., 51 Franklin St, Fifth Floor,
* Boston, MA 02110-1301, USA.
*/
/* TODO opencv can do scaling for some cases */
#ifdef HAVE_CONFIG_H
# include <config.h>
#endif
#include "gstopencvvideofilter.h"
#include "gstopencvutils.h"
#include <opencv2/core/core_c.h>
GST_DEBUG_CATEGORY_STATIC (gst_opencv_video_filter_debug);
#define GST_CAT_DEFAULT gst_opencv_video_filter_debug
/* Filter signals and args */
enum
{
/* FILL ME */
LAST_SIGNAL
};
enum
{
PROP_0
};
static GstElementClass *parent_class = NULL;
static void gst_opencv_video_filter_class_init (GstOpencvVideoFilterClass *
klass);
static void gst_opencv_video_filter_init (GstOpencvVideoFilter * cv_filter,
GstOpencvVideoFilterClass * klass);
static gboolean gst_opencv_video_filter_set_info (GstVideoFilter * vfilter,
GstCaps * incaps, GstVideoInfo * in_info,
GstCaps * outcaps, GstVideoInfo * out_info);
static GstFlowReturn gst_opencv_video_filter_transform_frame_ip (
GstVideoFilter * vfilter, GstVideoFrame * frame);
static GstFlowReturn gst_opencv_video_filter_transform_frame (
GstVideoFilter * vfilter,
GstVideoFrame * inframe, GstVideoFrame * outframe);
static void gst_opencv_video_filter_set_property (GObject * object,
guint prop_id, const GValue * value, GParamSpec * pspec);
static void gst_opencv_video_filter_get_property (GObject * object,
guint prop_id, GValue * value, GParamSpec * pspec);
GType
gst_opencv_video_filter_get_type (void)
{
static volatile gsize opencv_video_filter_type = 0;
if (g_once_init_enter (&opencv_video_filter_type)) {
GType _type;
static const GTypeInfo opencv_video_filter_info = {
sizeof (GstOpencvVideoFilterClass),
NULL,
NULL,
(GClassInitFunc) gst_opencv_video_filter_class_init,
NULL,
NULL,
sizeof (GstOpencvVideoFilter),
0,
(GInstanceInitFunc) gst_opencv_video_filter_init,
};
_type = g_type_register_static (GST_TYPE_VIDEO_FILTER,
"GstOpencvVideoFilter", &opencv_video_filter_info,
G_TYPE_FLAG_ABSTRACT);
g_once_init_leave (&opencv_video_filter_type, _type);
}
return opencv_video_filter_type;
}
/* Clean up */
static void
gst_opencv_video_filter_finalize (GObject * obj)
{
GstOpencvVideoFilter *cv_filter = GST_OPENCV_VIDEO_FILTER (obj);
if (cv_filter->cvImage)
cvReleaseImage (&cv_filter->cvImage);
if (cv_filter->out_cvImage)
cvReleaseImage (&cv_filter->out_cvImage);
G_OBJECT_CLASS (parent_class)->finalize (obj);
}
static void
gst_opencv_video_filter_class_init (GstOpencvVideoFilterClass * klass)
{
GObjectClass *gobject_class;
GstVideoFilterClass *filter_class;
gobject_class = (GObjectClass *) klass;
filter_class = (GstVideoFilterClass *) klass;
parent_class = (GstElementClass *) g_type_class_peek_parent (klass);
GST_DEBUG_CATEGORY_INIT (gst_opencv_video_filter_debug,
"opencvvideofilter", 0, "opencvvideofilter element");
gobject_class->finalize =
GST_DEBUG_FUNCPTR (gst_opencv_video_filter_finalize);
gobject_class->set_property = gst_opencv_video_filter_set_property;
gobject_class->get_property = gst_opencv_video_filter_get_property;
filter_class->transform_frame = gst_opencv_video_filter_transform_frame;
filter_class->transform_frame_ip =
gst_opencv_video_filter_transform_frame_ip;
filter_class->set_info = gst_opencv_video_filter_set_info;
}
static void
gst_opencv_video_filter_init (GstOpencvVideoFilter * cv_filter,
GstOpencvVideoFilterClass * klass)
{
}
static GstFlowReturn
gst_opencv_video_filter_transform_frame (GstVideoFilter * vfilter,
GstVideoFrame * inframe, GstVideoFrame * outframe)
{
GstOpencvVideoFilter *cv_filter;
GstOpencvVideoFilterClass *fclass;
GstFlowReturn ret;
cv_filter = GST_OPENCV_VIDEO_FILTER (vfilter);
fclass = GST_OPENCV_VIDEO_FILTER_GET_CLASS (vfilter);
g_return_val_if_fail (fclass->cv_transform_frame != NULL, GST_FLOW_ERROR);
g_return_val_if_fail (cv_filter->cvImage != NULL, GST_FLOW_ERROR);
g_return_val_if_fail (cv_filter->out_cvImage != NULL, GST_FLOW_ERROR);
cv_filter->cvImage->imageData = (char *) inframe->data;
cv_filter->out_cvImage->imageData = (char *) outframe->data;
ret = fclass->cv_transform_frame (cv_filter, inframe, cv_filter->cvImage,
outframe, cv_filter->out_cvImage);
return ret;
}
static GstFlowReturn
gst_opencv_video_filter_transform_frame_ip (GstVideoFilter * vfilter,
GstVideoFrame * frame)
{
GstOpencvVideoFilter *cv_filter;
GstOpencvVideoFilterClass *fclass;
GstFlowReturn ret;
cv_filter = GST_OPENCV_VIDEO_FILTER (vfilter);
fclass = GST_OPENCV_VIDEO_FILTER_GET_CLASS (vfilter);
g_return_val_if_fail (fclass->cv_transform_frame_ip != NULL, GST_FLOW_ERROR);
g_return_val_if_fail (cv_filter->cvImage != NULL, GST_FLOW_ERROR);
cv_filter->cvImage->imageData = (char *) frame->data;
ret = fclass->cv_transform_frame_ip (cv_filter, frame, cv_filter->cvImage);
return ret;
}
static gboolean
gst_opencv_video_filter_set_info (GstVideoFilter * vfilter, GstCaps * incaps,
GstVideoInfo * in_info, GstCaps * outcaps, GstVideoInfo * out_info)
{
GstOpencvVideoFilter *cv_filter = GST_OPENCV_VIDEO_FILTER (vfilter);
GstOpencvVideoFilterClass *klass =
GST_OPENCV_VIDEO_FILTER_GET_CLASS (cv_filter);
gint in_width, in_height;
gint in_depth, in_channels;
gint out_width, out_height;
gint out_depth, out_channels;
GError *in_err = NULL;
GError *out_err = NULL;
if (!gst_opencv_parse_iplimage_params_from_caps (incaps, &in_width,
&in_height, &in_depth, &in_channels, &in_err)) {
GST_WARNING_OBJECT (cv_filter, "Failed to parse input caps: %s",
in_err->message);
g_error_free (in_err);
return FALSE;
}
if (!gst_opencv_parse_iplimage_params_from_caps (outcaps, &out_width,
&out_height, &out_depth, &out_channels, &out_err)) {
GST_WARNING_OBJECT (cv_filter, "Failed to parse output caps: %s",
out_err->message);
g_error_free (out_err);
return FALSE;
}
if (klass->cv_set_info) {
if (!klass->cv_set_info (cv_filter, in_width, in_height, in_depth,
in_channels, out_width, out_height, out_depth, out_channels))
return FALSE;
}
if (cv_filter->cvImage) {
cvReleaseImage (&cv_filter->cvImage);
}
if (cv_filter->out_cvImage) {
cvReleaseImage (&cv_filter->out_cvImage);
}
cv_filter->cvImage =
cvCreateImageHeader (cvSize (in_width, in_height), in_depth, in_channels);
cv_filter->out_cvImage =
cvCreateImageHeader (cvSize (out_width, out_height), out_depth,
out_channels);
gst_base_transform_set_in_place (GST_BASE_TRANSFORM (cv_filter),
cv_filter->in_place);
return TRUE;
}
static void
gst_opencv_video_filter_set_property (GObject * object, guint prop_id,
const GValue * value, GParamSpec * pspec)
{
switch (prop_id) {
default:
G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
break;
}
}
static void
gst_opencv_video_filter_get_property (GObject * object, guint prop_id,
GValue * value, GParamSpec * pspec)
{
switch (prop_id) {
default:
G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
break;
}
}
void
gst_opencv_video_filter_set_in_place (GstOpencvVideoFilter * cv_filter,
gboolean ip)
{
cv_filter->in_place = ip;
gst_base_transform_set_in_place (GST_BASE_TRANSFORM (cv_filter), ip);
}

View File

@ -1,110 +0,0 @@
/*
* GStreamer
* Copyright (C) 2010 Thiago Santos <thiago.sousa.santos@collabora.co.uk>
*
* Permission is hereby granted, free of charge, to any person obtaining a
* copy of this software and associated documentation files (the "Software"),
* to deal in the Software without restriction, including without limitation
* the rights to use, copy, modify, merge, publish, distribute, sublicense,
* and/or sell copies of the Software, and to permit persons to whom the
* Software is furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in
* all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
* FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
* DEALINGS IN THE SOFTWARE.
*
* Alternatively, the contents of this file may be used under the
* GNU Lesser General Public License Version 2.1 (the "LGPL"), in
* which case the following provisions apply instead of the ones
* mentioned above:
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Library General Public
* License as published by the Free Software Foundation; either
* version 2 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
* Library General Public License for more details.
*
* You should have received a copy of the GNU Library General Public
* License along with this library; if not, write to the
* Free Software Foundation, Inc., 51 Franklin St, Fifth Floor,
* Boston, MA 02110-1301, USA.
*/
#ifndef __GST_OPENCV_VIDEO_FILTER_H__
#define __GST_OPENCV_VIDEO_FILTER_H__
#include <gst/gst.h>
#include <gst/video/gstvideofilter.h>
G_BEGIN_DECLS
/* forward declare opencv type to avoid exposing them in this API */
typedef struct _IplImage IplImage;
/* #defines don't like whitespacey bits */
#define GST_TYPE_OPENCV_VIDEO_FILTER \
(gst_opencv_video_filter_get_type())
#define GST_OPENCV_VIDEO_FILTER(obj) \
(G_TYPE_CHECK_INSTANCE_CAST((obj),GST_TYPE_OPENCV_VIDEO_FILTER,GstOpencvVideoFilter))
#define GST_OPENCV_VIDEO_FILTER_CLASS(klass) \
(G_TYPE_CHECK_CLASS_CAST((klass),GST_TYPE_OPENCV_VIDEO_FILTER,GstOpencvVideoFilterClass))
#define GST_IS_OPENCV_VIDEO_FILTER(obj) \
(G_TYPE_CHECK_INSTANCE_TYPE((obj),GST_TYPE_OPENCV_VIDEO_FILTER))
#define GST_IS_OPENCV_VIDEO_FILTER_CLASS(klass) \
(G_TYPE_CHECK_CLASS_TYPE((klass),GST_TYPE_OPENCV_VIDEO_FILTER))
#define GST_OPENCV_VIDEO_FILTER_GET_CLASS(obj) \
(G_TYPE_INSTANCE_GET_CLASS((obj),GST_TYPE_OPENCV_VIDEO_FILTER,GstOpencvVideoFilterClass))
#define GST_OPENCV_VIDEO_FILTER_CAST(obj) ((GstOpencvVideoFilter *) (obj))
typedef struct _GstOpencvVideoFilter GstOpencvVideoFilter;
typedef struct _GstOpencvVideoFilterClass GstOpencvVideoFilterClass;
typedef GstFlowReturn (*GstOpencvVideoFilterTransformIPFunc)
(GstOpencvVideoFilter * cvfilter, GstVideoFrame * frame, IplImage * img);
typedef GstFlowReturn (*GstOpencvVideoFilterTransformFunc)
(GstOpencvVideoFilter * cvfilter, GstVideoFrame * frame, IplImage * img,
GstVideoFrame * outframe, IplImage * outimg);
typedef gboolean (*GstOpencvVideoFilterSetInfo)
(GstOpencvVideoFilter * cv_filter, gint in_width, gint in_height,
gint in_depth, gint in_channels, gint out_width, gint out_height,
gint out_depth, gint out_channels);
struct _GstOpencvVideoFilter
{
GstVideoFilter videofilter;
gboolean in_place;
IplImage *cvImage;
IplImage *out_cvImage;
};
struct _GstOpencvVideoFilterClass
{
GstVideoFilterClass parent_class;
GstOpencvVideoFilterTransformFunc cv_transform_frame;
GstOpencvVideoFilterTransformIPFunc cv_transform_frame_ip;
GstOpencvVideoFilterSetInfo cv_set_info;
};
GType gst_opencv_video_filter_get_type (void);
void gst_opencv_video_filter_set_in_place (GstOpencvVideoFilter * cv_filter,
gboolean ip);
G_END_DECLS
#endif /* __GST_OPENCV_VIDEO_FILTER_H__ */

View File

@ -3,16 +3,6 @@ DEFINES += GST_PLUGIN_BUILD_STATIC
#CONFIG += link_pkgconfig
PKGCONFIG += gstreamer-base-1.0
do_not_compile {
HEADERS += \
plugins/cameracalibration/gstopencvutils.h \
plugins/cameracalibration/gstopencvvideofilter.hpp
SOURCES += \
plugins/cameracalibration/gstopencvutils.cpp \
plugins/cameracalibration/gstopencvvideofilter.cpp \
}
opencv {
# there is no package for gst opencv yet...
GSTREAMER_SDK_DIR = $$system(pkg-config --variable=exec_prefix gstreamer-1.0)