OpenCV中文网站

 找回密码
 立即注册
搜索
热搜: 安装 配置
查看: 2666|回复: 2

ubuntu下用gstreamer 获取摄像头数据如何得到并按每帧图像给o...

[复制链接]
发表于 2017-6-8 13:37:57 | 显示全部楼层 |阅读模式
这是我写的调用并显示一个摄像头的代码,如何得到每帧图像数据?(得到数据用作Oencv进行处理),希望能得到具体方法或者代码参照,我是刚接触gstreamer,感激不尽。
  1. #include <gst/gst.h>

  2. #define Device_path_1 "/dev/video0"
  3. //#define Device_path_2 "/dev/video1"
  4. #define Camera_caps "video/x-raw-yuv,width=(int)1920,height=(int)1080,framerate=(fraction)30/1"

  5. int main(int argc, char *argv[])
  6. {
  7.     GstElement *camera_source_1,*convert_1,*sink_1,*pipeline;
  8.     GMainLoop *loop;

  9.     //初始化GST
  10.     gst_init(&argc,&argv);

  11.     //创建需要的elements
  12.     camera_source_1 = gst_element_factory_make("v4l2src","camera_source_1");
  13.     convert_1 = gst_element_factory_make("ffmpegcolorspace","1_csp");
  14.     sink_1 = gst_element_factory_make("ximagesink","sink_1");


  15.     //创建pipeline
  16.     pipeline = gst_pipeline_new("camera_pipeline");

  17.     //出错处理
  18.     if(!pipeline || !camera_source_1 || !sink_1 || !convert_1){
  19.         g_printerr("Not all elements could be created !\n");
  20.         return -1;
  21.     }

  22.     //配置 elements
  23.     g_object_set(G_OBJECT(camera_source_1),"device",Device_path_1,NULL);

  24.     //link all elements
  25.     gst_bin_add_many(GST_BIN(pipeline),camera_source_1,convert_1,sink_1,NULL);


  26.     gst_element_link_many(camera_source_1,convert_1,sink_1,NULL);

  27.     gst_element_set_state(pipeline,GST_STATE_PLAYING);
  28.     loop = g_main_loop_new(NULL,FALSE);
  29.     g_main_loop_run(loop);
  30.     g_print("stopping sender pipeline\n");
  31.     gst_element_set_state(pipeline,GST_STATE_NULL);
  32.     return 0;
  33. }
复制代码


回复

使用道具 举报

 楼主| 发表于 2017-6-8 15:13:10 | 显示全部楼层
有人会吗,感激不尽。
回复 支持 反对

使用道具 举报

 楼主| 发表于 2017-6-9 17:24:22 | 显示全部楼层
回复 支持 反对

使用道具 举报

您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

手机版|OpenCV中文网站

GMT+8, 2024-3-28 16:33 , Processed in 0.022176 second(s), 15 queries .

Powered by Discuz! X3.4

Copyright © 2001-2021, Tencent Cloud.

快速回复 返回顶部 返回列表