opencv: fix caps issues and extend supported caps for some elements

Some elements had vague caps, such as "video/x-raw-rgb", which caused problems
at least with textwrite. For other elements, the underlying OpenCV functions
support more than just one image type, so I increased the number of supported
caps.

I created a utility function "gst_opencv_caps_from_cv_image_type", so each
element creates caps directly from OpenCV image types, such as CV_8UC1 for
8-bit grayscale. This function uses gstvideo to create uniform caps.

https://bugzilla.gnome.org/show_bug.cgi?id=635304
This commit is contained in:
Josh Doe 2010-11-19 15:23:41 -05:00 committed by Thiago Santos
parent 7622328aab
commit 6e43f75df3
12 changed files with 111 additions and 58 deletions

View file

@ -52,6 +52,7 @@
#include <gst/gst.h>
#include "gstopencvutils.h"
#include "gstcvdilateerode.h"
/*
@ -59,19 +60,6 @@ GST_DEBUG_CATEGORY_STATIC (gst_cv_dilate_erode_debug);
#define GST_CAT_DEFAULT gst_cv_dilate_erode_debug
*/
static GstStaticPadTemplate sink_factory = GST_STATIC_PAD_TEMPLATE ("sink",
GST_PAD_SINK,
GST_PAD_ALWAYS,
GST_STATIC_CAPS ("video/x-raw-rgb, depth=(int)24, bpp=(int)24;"
"video/x-raw-gray")
);
static GstStaticPadTemplate src_factory = GST_STATIC_PAD_TEMPLATE ("src",
GST_PAD_SRC,
GST_PAD_ALWAYS,
GST_STATIC_CAPS ("video/x-raw-rgb, depth=(int)24, bpp=(int)24;"
"video/x-raw-gray")
);
/* Filter signals and args */
enum
@ -143,11 +131,21 @@ static void
gst_cv_dilate_erode_base_init (gpointer gclass)
{
GstElementClass *element_class = GST_ELEMENT_CLASS (gclass);
GstCaps *caps;
GstPadTemplate *templ;
gst_element_class_add_pad_template (element_class,
gst_static_pad_template_get (&src_factory));
gst_element_class_add_pad_template (element_class,
gst_static_pad_template_get (&sink_factory));
/* add sink and source pad templates */
caps = gst_opencv_caps_from_cv_image_type (CV_16UC1);
gst_caps_append (caps, gst_opencv_caps_from_cv_image_type (CV_8UC4));
gst_caps_append (caps, gst_opencv_caps_from_cv_image_type (CV_8UC3));
gst_caps_append (caps, gst_opencv_caps_from_cv_image_type (CV_8UC1));
templ = gst_pad_template_new ("sink", GST_PAD_SINK, GST_PAD_ALWAYS,
gst_caps_ref (caps));
gst_element_class_add_pad_template (element_class, templ);
gst_object_unref (templ);
templ = gst_pad_template_new ("src", GST_PAD_SRC, GST_PAD_ALWAYS, caps);
gst_element_class_add_pad_template (element_class, templ);
gst_object_unref (templ);
}
/* initialize the cvdilate_erode's class */

View file

@ -47,6 +47,7 @@
#include <gst/gst.h>
#include "gstopencvutils.h"
#include "gstcvequalizehist.h"
GST_DEBUG_CATEGORY_STATIC (gst_cv_equalize_hist_debug);
@ -55,12 +56,12 @@ GST_DEBUG_CATEGORY_STATIC (gst_cv_equalize_hist_debug);
static GstStaticPadTemplate sink_factory = GST_STATIC_PAD_TEMPLATE ("sink",
GST_PAD_SINK,
GST_PAD_ALWAYS,
GST_STATIC_CAPS ("video/x-raw-gray, depth=(int)8, bpp=(int)8"));
GST_STATIC_CAPS (GST_VIDEO_CAPS_GRAY8));
static GstStaticPadTemplate src_factory = GST_STATIC_PAD_TEMPLATE ("src",
GST_PAD_SRC,
GST_PAD_ALWAYS,
GST_STATIC_CAPS ("video/x-raw-gray, depth=(int)8, bpp=(int)8"));
GST_STATIC_CAPS (GST_VIDEO_CAPS_GRAY8));
GST_BOILERPLATE (GstCvEqualizeHist, gst_cv_equalize_hist,
GstOpencvVideoFilter, GST_TYPE_OPENCV_VIDEO_FILTER);

View file

@ -47,6 +47,7 @@
#include <gst/gst.h>
#include "gstopencvutils.h"
#include "gstcvlaplace.h"
GST_DEBUG_CATEGORY_STATIC (gst_cv_laplace_debug);
@ -55,14 +56,19 @@ GST_DEBUG_CATEGORY_STATIC (gst_cv_laplace_debug);
static GstStaticPadTemplate sink_factory = GST_STATIC_PAD_TEMPLATE ("sink",
GST_PAD_SINK,
GST_PAD_ALWAYS,
GST_STATIC_CAPS ("video/x-raw-gray, depth=(int)8, bpp=(int)8")
GST_STATIC_CAPS (GST_VIDEO_CAPS_GRAY8)
);
#if G_BYTE_ORDER == G_BIG_ENDIAN
#define BYTE_ORDER_STRING "BIG_ENDIAN"
#else
#define BYTE_ORDER_STRING "LITTLE_ENDIAN"
#endif
static GstStaticPadTemplate src_factory = GST_STATIC_PAD_TEMPLATE ("src",
GST_PAD_SRC,
GST_PAD_ALWAYS,
GST_STATIC_CAPS
("video/x-raw-gray, depth=(int)16, bpp=(int)16, endianness=(int)4321")
GST_STATIC_CAPS (GST_VIDEO_CAPS_GRAY16 (BYTE_ORDER_STRING))
);
/* Filter signals and args */
@ -213,14 +219,18 @@ gst_cv_laplace_transform_caps (GstBaseTransform * trans, GstPadDirection dir,
structure = gst_caps_get_structure (output, i);
gst_structure_set (structure,
"depth", G_TYPE_INT, 16,
"bpp", G_TYPE_INT, 16, "endianness", G_TYPE_INT, 4321, NULL);
"bpp", G_TYPE_INT, 16,
"endianness", G_TYPE_INT, G_BYTE_ORDER,
NULL);
}
break;
case GST_PAD_SRC:
for (i = 0; i < gst_caps_get_size (output); i++) {
structure = gst_caps_get_structure (output, i);
gst_structure_set (structure,
"depth", G_TYPE_INT, 8, "bpp", G_TYPE_INT, 8, NULL);
"depth", G_TYPE_INT, 8,
"bpp", G_TYPE_INT, 8,
NULL);
gst_structure_remove_field (structure, "endianness");
}
break;

View file

@ -47,25 +47,12 @@
#include <gst/gst.h>
#include "gstopencvutils.h"
#include "gstcvsmooth.h"
GST_DEBUG_CATEGORY_STATIC (gst_cv_smooth_debug);
#define GST_CAT_DEFAULT gst_cv_smooth_debug
static GstStaticPadTemplate sink_factory = GST_STATIC_PAD_TEMPLATE ("sink",
GST_PAD_SINK,
GST_PAD_ALWAYS,
GST_STATIC_CAPS ("video/x-raw-rgb, depth=(int)24, bpp=(int)24;"
"video/x-raw-gray, depth=(int)8, bpp=(int)8")
);
static GstStaticPadTemplate src_factory = GST_STATIC_PAD_TEMPLATE ("src",
GST_PAD_SRC,
GST_PAD_ALWAYS,
GST_STATIC_CAPS ("video/x-raw-rgb, depth=(int)24, bpp=(int)24;"
"video/x-raw-gray, depth=(int)8, bpp=(int)8")
);
/* Filter signals and args */
enum
{
@ -146,17 +133,25 @@ static void
gst_cv_smooth_base_init (gpointer gclass)
{
GstElementClass *element_class = GST_ELEMENT_CLASS (gclass);
gst_element_class_add_pad_template (element_class,
gst_static_pad_template_get (&src_factory));
gst_element_class_add_pad_template (element_class,
gst_static_pad_template_get (&sink_factory));
GstCaps *caps;
GstPadTemplate *templ;
gst_element_class_set_details_simple (element_class,
"cvsmooth",
"Transform/Effect/Video",
"Applies cvSmooth OpenCV function to the image",
"Thiago Santos<thiago.sousa.santos@collabora.co.uk>");
/* add sink and source pad templates */
caps = gst_opencv_caps_from_cv_image_type (CV_8UC3);
gst_caps_append (caps, gst_opencv_caps_from_cv_image_type (CV_8UC1));
templ = gst_pad_template_new ("sink", GST_PAD_SINK, GST_PAD_ALWAYS,
gst_caps_ref (caps));
gst_element_class_add_pad_template (element_class, templ);
gst_object_unref (templ);
templ = gst_pad_template_new ("src", GST_PAD_SRC, GST_PAD_ALWAYS, caps);
gst_element_class_add_pad_template (element_class, templ);
gst_object_unref (templ);
}
/* initialize the cvsmooth's class */

View file

@ -47,6 +47,7 @@
#include <gst/gst.h>
#include "gstopencvutils.h"
#include "gstcvsobel.h"
GST_DEBUG_CATEGORY_STATIC (gst_cv_sobel_debug);
@ -55,14 +56,19 @@ GST_DEBUG_CATEGORY_STATIC (gst_cv_sobel_debug);
static GstStaticPadTemplate sink_factory = GST_STATIC_PAD_TEMPLATE ("sink",
GST_PAD_SINK,
GST_PAD_ALWAYS,
GST_STATIC_CAPS ("video/x-raw-gray, depth=(int)8, bpp=(int)8")
GST_STATIC_CAPS (GST_VIDEO_CAPS_GRAY8)
);
#if G_BYTE_ORDER == G_BIG_ENDIAN
#define BYTE_ORDER_STRING "BIG_ENDIAN"
#else
#define BYTE_ORDER_STRING "LITTLE_ENDIAN"
#endif
static GstStaticPadTemplate src_factory = GST_STATIC_PAD_TEMPLATE ("src",
GST_PAD_SRC,
GST_PAD_ALWAYS,
GST_STATIC_CAPS
("video/x-raw-gray, depth=(int)16, bpp=(int)16, endianness=(int)4321")
GST_STATIC_CAPS (GST_VIDEO_CAPS_GRAY16 (BYTE_ORDER_STRING))
);
/* Filter signals and args */
@ -188,14 +194,18 @@ gst_cv_sobel_transform_caps (GstBaseTransform * trans, GstPadDirection dir,
structure = gst_caps_get_structure (output, i);
gst_structure_set (structure,
"depth", G_TYPE_INT, 16,
"bpp", G_TYPE_INT, 16, "endianness", G_TYPE_INT, 4321, NULL);
"bpp", G_TYPE_INT, 16,
"endianness", G_TYPE_INT, G_BYTE_ORDER,
NULL);
}
break;
case GST_PAD_SRC:
for (i = 0; i < gst_caps_get_size (output); i++) {
structure = gst_caps_get_structure (output, i);
gst_structure_set (structure,
"depth", G_TYPE_INT, 8, "bpp", G_TYPE_INT, 8, NULL);
"depth", G_TYPE_INT, 8,
"bpp", G_TYPE_INT, 8,
NULL);
gst_structure_remove_field (structure, "endianness");
}
break;

View file

@ -62,6 +62,7 @@
#include <gst/gst.h>
#include "gstopencvutils.h"
#include "gstedgedetect.h"
GST_DEBUG_CATEGORY_STATIC (gst_edgedetect_debug);
@ -90,13 +91,13 @@ enum
static GstStaticPadTemplate sink_factory = GST_STATIC_PAD_TEMPLATE ("sink",
GST_PAD_SINK,
GST_PAD_ALWAYS,
GST_STATIC_CAPS ("video/x-raw-rgb")
GST_STATIC_CAPS (GST_VIDEO_CAPS_RGB)
);
static GstStaticPadTemplate src_factory = GST_STATIC_PAD_TEMPLATE ("src",
GST_PAD_SRC,
GST_PAD_ALWAYS,
GST_STATIC_CAPS ("video/x-raw-rgb")
GST_STATIC_CAPS (GST_VIDEO_CAPS_RGB)
);
GST_BOILERPLATE (Gstedgedetect, gst_edgedetect, GstElement, GST_TYPE_ELEMENT);

View file

@ -62,6 +62,7 @@
#include <gst/gst.h>
#include "gstopencvutils.h"
#include "gstfaceblur.h"
GST_DEBUG_CATEGORY_STATIC (gst_faceblur_debug);
@ -87,13 +88,13 @@ enum
static GstStaticPadTemplate sink_factory = GST_STATIC_PAD_TEMPLATE ("sink",
GST_PAD_SINK,
GST_PAD_ALWAYS,
GST_STATIC_CAPS ("video/x-raw-rgb")
GST_STATIC_CAPS (GST_VIDEO_CAPS_RGB)
);
static GstStaticPadTemplate src_factory = GST_STATIC_PAD_TEMPLATE ("src",
GST_PAD_SRC,
GST_PAD_ALWAYS,
GST_STATIC_CAPS ("video/x-raw-rgb")
GST_STATIC_CAPS (GST_VIDEO_CAPS_RGB)
);
GST_BOILERPLATE (Gstfaceblur, gst_faceblur, GstElement, GST_TYPE_ELEMENT);

View file

@ -92,3 +92,33 @@ gst_opencv_parse_iplimage_params_from_caps (GstCaps * caps, gint * width,
gst_opencv_parse_iplimage_params_from_structure (gst_caps_get_structure
(caps, 0), width, height, ipldepth, channels, err);
}
GstCaps *
gst_opencv_caps_from_cv_image_type (int cv_type)
{
GstCaps * caps = gst_caps_new_empty ();
switch (cv_type) {
case CV_8UC1:
gst_caps_append (caps, gst_caps_from_string (GST_VIDEO_CAPS_GRAY8));
break;
case CV_8UC3:
gst_caps_append (caps, gst_caps_from_string (GST_VIDEO_CAPS_RGB));
gst_caps_append (caps, gst_caps_from_string (GST_VIDEO_CAPS_BGR));
break;
case CV_8UC4:
gst_caps_append (caps, gst_caps_from_string (GST_VIDEO_CAPS_RGBx));
gst_caps_append (caps, gst_caps_from_string (GST_VIDEO_CAPS_xRGB));
gst_caps_append (caps, gst_caps_from_string (GST_VIDEO_CAPS_BGRx));
gst_caps_append (caps, gst_caps_from_string (GST_VIDEO_CAPS_xBGR));
gst_caps_append (caps, gst_caps_from_string (GST_VIDEO_CAPS_RGBA));
gst_caps_append (caps, gst_caps_from_string (GST_VIDEO_CAPS_ARGB));
gst_caps_append (caps, gst_caps_from_string (GST_VIDEO_CAPS_BGRA));
gst_caps_append (caps, gst_caps_from_string (GST_VIDEO_CAPS_ABGR));
break;
case CV_16UC1:
gst_caps_append (caps, gst_caps_from_string (GST_VIDEO_CAPS_GRAY16("1234")));
gst_caps_append (caps, gst_caps_from_string (GST_VIDEO_CAPS_GRAY16("4321")));
break;
}
return caps;
}

View file

@ -27,6 +27,8 @@
#endif
#include <gst/gst.h>
#include <gst/video/video.h>
#include <cv.h>
gboolean
@ -39,4 +41,6 @@ gboolean gst_opencv_parse_iplimage_params_from_structure
(GstStructure * structure, gint * width, gint * height, gint * depth,
gint * channels, GError ** err);
GstCaps * gst_opencv_caps_from_cv_image_type (int cv_type);
#endif /* __GST_OPENCV_UTILS__ */

View file

@ -62,6 +62,7 @@
#include <gst/gst.h>
#include "gstopencvutils.h"
#include "gstpyramidsegment.h"
#define BLOCK_SIZE 1000
@ -92,13 +93,13 @@ enum
static GstStaticPadTemplate sink_factory = GST_STATIC_PAD_TEMPLATE ("sink",
GST_PAD_SINK,
GST_PAD_ALWAYS,
GST_STATIC_CAPS ("video/x-raw-rgb")
GST_STATIC_CAPS (GST_VIDEO_CAPS_RGB)
);
static GstStaticPadTemplate src_factory = GST_STATIC_PAD_TEMPLATE ("src",
GST_PAD_SRC,
GST_PAD_ALWAYS,
GST_STATIC_CAPS ("video/x-raw-rgb")
GST_STATIC_CAPS (GST_VIDEO_CAPS_RGB)
);
GST_BOILERPLATE (Gstpyramidsegment, gst_pyramidsegment, GstElement,

View file

@ -63,6 +63,7 @@
#include <gst/gst.h>
#include "gstopencvutils.h"
#include "gsttemplatematch.h"
GST_DEBUG_CATEGORY_STATIC (gst_templatematch_debug);
@ -90,13 +91,13 @@ enum
static GstStaticPadTemplate sink_factory = GST_STATIC_PAD_TEMPLATE ("sink",
GST_PAD_SINK,
GST_PAD_ALWAYS,
GST_STATIC_CAPS ("video/x-raw-rgb")
GST_STATIC_CAPS (GST_VIDEO_CAPS_RGB)
);
static GstStaticPadTemplate src_factory = GST_STATIC_PAD_TEMPLATE ("src",
GST_PAD_SRC,
GST_PAD_ALWAYS,
GST_STATIC_CAPS ("video/x-raw-rgb")
GST_STATIC_CAPS (GST_VIDEO_CAPS_RGB)
);
GST_BOILERPLATE (GstTemplateMatch, gst_templatematch, GstElement,

View file

@ -62,6 +62,7 @@
#include <gst/gst.h>
#include "gstopencvutils.h"
#include "gsttextwrite.h"
GST_DEBUG_CATEGORY_STATIC (gst_textwrite_debug);
@ -104,13 +105,13 @@ enum
static GstStaticPadTemplate sink_factory = GST_STATIC_PAD_TEMPLATE ("sink",
GST_PAD_SINK,
GST_PAD_ALWAYS,
GST_STATIC_CAPS ("video/x-raw-rgb")
GST_STATIC_CAPS (GST_VIDEO_CAPS_RGB)
);
static GstStaticPadTemplate src_factory = GST_STATIC_PAD_TEMPLATE ("src",
GST_PAD_SRC,
GST_PAD_ALWAYS,
GST_STATIC_CAPS ("ANY")
GST_STATIC_CAPS (GST_VIDEO_CAPS_RGB)
);
GST_BOILERPLATE (Gsttextwrite, gst_textwrite, GstElement, GST_TYPE_ELEMENT);