2014-04-28 33 views
3

我當前的項目:從設備的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進行面部檢測,並將此流發送到另一個客戶端。這可以通過支持opencv的gstreamer壞插件完成,也可以通過將流轉換爲matts並使用opencv完成。有人知道哪個更容易,你有什麼樣的例子嗎? (我正在使用gstreamer 1.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等

+0

[請僅使用Answers解答問題](// meta.stackoverflow.com/q/92107)。如果您有新問題,請點擊[問問題](// stackoverflow.com/questions/ask)按鈕。如果有助於提供上下文,請包含此問題的鏈接。 (我編輯過你的帖子只是一個答案 - 你可以從編輯歷史中檢索新的問題部分。) – Mogsdad

0

你可以使用opencv VideoCapture功能來接收流,然後您可以對其進行圖像處理。