gstreamer opencv接收和编辑流

时间:2014-04-28 11:55:50

标签: c opencv gstreamer

我目前的项目:

从带有USB摄像头的设备发送视频到服务器,在服务器上进行视频处理,然后将其发送到显示它的另一个客户端。

我已经让gstreamer在终端工作了:

在接收服务器上:

gst-launch-1.0 udpsrc port=5000 ! \
application/x-rtp,media=video,clock-rate=90000,encoding-name=H264 ! \
rtph264depay ! h264parse ! avdec_h264 ! videoconvert ! \
timeoverlay shaded-background=true text="host" deltay=20 ! \
ximagesink async=true sync=false

在捕获客户端上:

gst-launch-1.0 -v v4l2src ! \
timeoverlay shaded-background=true text="pi" ! \
video/x-raw,height=480,width=640,framerate=30/1 ! \
videoconvert ! omxh264enc ! rtph264pay ! \
udpsink host=136.225.61.68 port=5000

效果非常好,视频正在转移。现在我需要(在接收端)捕获c代码中的流,以便我可以使用opencv进行面部检测,并将此流发送到另一个客户端。这可以通过具有opencv支持的gstreamer坏插件来完成,也可以通过将流转换为垫并使用opencv来完成。有谁知道哪个更容易,你有什么例子吗? (我正在使用gstreamer 1.0)。

提前致谢

2 个答案:

答案 0 :(得分:0)

我终于找到了第一步的解决方案。我现在可以使用gst_parse_launch以C代码接收流。

服务器端的代码现在如下:

#include <gst/gst.h>

int main(int argc, char *argv[]) {
  GstElement *pipeline;
  GstBus *bus;
  GstMessage *msg;

  /* Initialize GStreamer */
  gst_init (&argc, &argv);

  /* Build the pipeline */
  pipeline = gst_parse_launch ("udpsrc port=5000 ! \
  application/x-rtp,media=video,clock-rate=90000,encoding-name=H264 ! \
  rtph264depay ! h264parse ! avdec_h264 ! videoconvert ! \
  timeoverlay shaded-background=true deltay=20 ! \
  ximagesink async=true sync=false", NULL);

  /* Start playing */
  gst_element_set_state (pipeline, GST_STATE_PLAYING);

  /* Wait until error or EOS */
  bus = gst_element_get_bus (pipeline);
  msg = gst_bus_timed_pop_filtered (bus, GST_CLOCK_TIME_NONE, GST_MESSAGE_ERROR | GST_MESSAGE_EOS);

  /* Free resources */
  if (msg != NULL)
    gst_message_unref (msg);
  gst_object_unref (bus);
  gst_element_set_state (pipeline, GST_STATE_NULL);
  gst_object_unref (pipeline);
  return 0;
}

现在下一步是将其与OpenCV或OpenCV插件连接,以便我可以进行facedetect等。

答案 1 :(得分:0)

您可以使用opencv VideoCapture函数接收流,然后就可以对其进行图像处理。