c-gstreamer opencv接收和编辑流



我当前的项目:

将视频从带有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进行人脸检测ect,并将此流发送到另一个客户端。这可以通过支持opencv的gstreamer坏插件来完成,也可以通过将流转换为mats并使用opencv来完成。有人知道哪一个更容易吗?你有什么例子吗?(我使用gstreamer 1.0)。

提前感谢

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

我终于找到了第一步的解决方案。我现在可以使用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插件连接,这样我就可以进行人脸检测等操作。

最新更新