opencv: extracting video channels and depth from caps

classic Classic list List threaded Threaded
3 messages Options
Reply | Threaded
Open this post in threaded view
|

opencv: extracting video channels and depth from caps

filnet
Hi,

The opencv plugins has a utility method to extract the number of video channels and depth from caps (see code below).

Problem is that it fails for sparse formats (BGRx, ...) where it reports 3 channels of depth 8.
For opencv to work correctly downstream, it should report 4 channels.

I can't find a simple way to detect that the caps/video info is sparse and has one additional "channel".

Philippe.

gboolean
gst_opencv_parse_iplimage_params_from_caps (GstCaps * caps, gint * width,
    gint * height, gint * ipldepth, gint * channels, GError ** err)
{
  GstVideoInfo info;
  gint depth = 0;
  guint i;

  if (!gst_video_info_from_caps (&info, caps)) {
    GST_ERROR ("Failed to get the videoinfo from caps");
    g_set_error (err, GST_CORE_ERROR, GST_CORE_ERROR_NEGOTIATION,
        "No width/height/depth/channels in caps");
    return FALSE;
  }

  *width = GST_VIDEO_INFO_WIDTH (&info);
  *height = GST_VIDEO_INFO_HEIGHT (&info);
  if (GST_VIDEO_INFO_IS_RGB (&info))
    *channels = 3;
  else if (GST_VIDEO_INFO_IS_GRAY (&info))
    *channels = 1;
  else {
    g_set_error (err, GST_CORE_ERROR, GST_CORE_ERROR_NEGOTIATION,
        "Unsupported caps %s", gst_caps_to_string (caps));
    return FALSE;
  }

  for (i = 0; i < GST_VIDEO_INFO_N_COMPONENTS (&info); i++) {
    depth += GST_VIDEO_INFO_COMP_DEPTH (&info, i);
  }

  if (depth / *channels == 8) {
    /* TODO signdness? */
    *ipldepth = IPL_DEPTH_8U;
  } else if (depth / *channels == 16) {
    *ipldepth = IPL_DEPTH_16U;
  } else {
    g_set_error (err, GST_CORE_ERROR, GST_CORE_ERROR_NEGOTIATION,
        "Unsupported depth/channels %d/%d", depth, *channels);
    return FALSE;
  }

  return TRUE;
}


_______________________________________________
gstreamer-devel mailing list
[hidden email]
https://lists.freedesktop.org/mailman/listinfo/gstreamer-devel
Reply | Threaded
Open this post in threaded view
|

Re: opencv: extracting video channels and depth from caps

Sebastian Dröge-3
On Sun, 2016-10-23 at 09:44 +0000, philippe renon wrote:

> Hi,
>
> The opencv plugins has a utility method to extract the number of
> video channels and depth from caps (see code below).
>
> Problem is that it fails for sparse formats (BGRx, ...) where it
> reports 3 channels of depth 8.
> For opencv to work correctly downstream, it should report 4 channels.
>
> I can't find a simple way to detect that the caps/video info is
> sparse and has one additional "channel".
Should it actually use that additional "channel", it's containing
arbitrary and useless data.

In any case, you can get this info with e.g.
GST_VIDEO_INFO_COMP_PSTRIDE(), which will tell you 4 here (4 bytes to
get from one pixel to the next). It might even be better to directly
have a switch around the GstVideoFormat here instead.

--
Sebastian Dröge, Centricular Ltd · http://www.centricular.com
_______________________________________________
gstreamer-devel mailing list
[hidden email]
https://lists.freedesktop.org/mailman/listinfo/gstreamer-devel

signature.asc (949 bytes) Download Attachment
Reply | Threaded
Open this post in threaded view
|

Re: opencv: extracting video channels and depth from caps

filnet
opencv misbehaves if that additional channel is not accounted for as it then assumes the image is RGB (i.e. stride 3). I thought about using the stride but it is a bit cumbersome as it is a per channel information.
What about adding a IS_SPARSE flag (like HAS_ALPHA or IS_RGB) ?


Le Lundi 24 octobre 2016 8h45, Sebastian Dröge <[hidden email]> a écrit :


On Sun, 2016-10-23 at 09:44 +0000, philippe renon wrote:

> Hi,
>
> The opencv plugins has a utility method to extract the number of
> video channels and depth from caps (see code below).
>
> Problem is that it fails for sparse formats (BGRx, ...) where it
> reports 3 channels of depth 8.
> For opencv to work correctly downstream, it should report 4 channels.
>
> I can't find a simple way to detect that the caps/video info is
> sparse and has one additional "channel".

Should it actually use that additional "channel", it's containing
arbitrary and useless data.

In any case, you can get this info with e.g.
GST_VIDEO_INFO_COMP_PSTRIDE(), which will tell you 4 here (4 bytes to
get from one pixel to the next). It might even be better to directly
have a switch around the GstVideoFormat here instead.

--
Sebastian Dröge, Centricular Ltd · http://www.centricular.com
_______________________________________________
gstreamer-devel mailing list
[hidden email]
https://lists.freedesktop.org/mailman/listinfo/gstreamer-devel




_______________________________________________
gstreamer-devel mailing list
[hidden email]
https://lists.freedesktop.org/mailman/listinfo/gstreamer-devel