opencv: extracting video channels and depth from caps
philippe renon
philippe_renon at yahoo.fr
Sun Oct 23 09:44:18 UTC 2016
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;
}
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://lists.freedesktop.org/archives/gstreamer-devel/attachments/20161023/03ff57e0/attachment-0001.html>
More information about the gstreamer-devel
mailing list