使用OpenCV从AXIS ip camera读取图像

时间:2016-06-13 07:29:39

标签: opencv ffmpeg ip-camera

我正在尝试使用OpenCV从我的程序访问AXIS IP摄像头。 我的OpenCV版本是3.1。我按照本教程link

我安装了所有库。 我的以下程序可以成功加载mp4视频。这意味着ffmpeg和必要的库工作正常。

cv::VideoCapture vcap("rtsp://root:pass@192.168.0.90/axis-media/media.amp?camera=1");

当我尝试按以下方式访问IP摄像机时

GStreamer Plugin: Embedded video playback halted; module source reported: Could 
not open resource for reading and writing.
OpenCV Error: Unspecified error (GStreamer: unable to start pipeline
) in cvCaptureFromCAM_GStreamer, file /home/Softwares/opencv/opencv/modules
/videoio/src/cap_gstreamer.cpp, line 818
terminate called after throwing an instance of 'cv::Exception'
  what():  /home/Softwares/opencv/opencv/modules/videoio/src/cap_gstreamer.
cpp:818: error: (-2) GStreamer: unable to start pipeline
 in function cvCaptureFromCAM_GStreamer

我有以下错误

ifconfig
eth0      Link encap:Ethernet  HWaddr b8:2a:72:c6:b8:13  
          inet6 addr: fe80::ba2a:72ff:fec6:b813/64 Scope:Link
          UP BROADCAST RUNNING MULTICAST  MTU:1500  Metric:1
          RX packets:723959 errors:0 dropped:0 overruns:0 frame:0
          TX packets:116637 errors:0 dropped:0 overruns:0 carrier:0
          collisions:0 txqueuelen:1000 
          RX bytes:199422245 (199.4 MB)  TX bytes:13701699 (13.7 MB)

lo        Link encap:Local Loopback  
          inet addr:127.0.0.1  Mask:255.0.0.0
          inet6 addr: ::1/128 Scope:Host
          UP LOOPBACK RUNNING  MTU:65536  Metric:1
          RX packets:24829 errors:0 dropped:0 overruns:0 frame:0
          TX packets:24829 errors:0 dropped:0 overruns:0 carrier:0
          collisions:0 txqueuelen:0 
          RX bytes:2502903 (2.5 MB)  TX bytes:2502903 (2.5 MB)

wlan0     Link encap:Ethernet  HWaddr a0:a8:cd:99:92:60  
          UP BROADCAST MULTICAST  MTU:1500  Metric:1
          RX packets:0 errors:0 dropped:0 overruns:0 frame:0
          TX packets:0 errors:0 dropped:0 overruns:0 carrier:0
          collisions:0 txqueuelen:1000 
          RX bytes:0 (0.0 B)  TX bytes:0 (0.0 B)

用户是root,密码是pass,ip 192.168.0.90都是默认值。

我的if config给了我

public class MainActivity extends AppCompatActivity {
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.main_activity);
  }
}

访问相机可能会出现什么问题?

由于

1 个答案:

答案 0 :(得分:0)

问题出在网络配置上。 我需要设置静态IP地址,如下所示。

auto eth0
iface eth0 inet static
address 192.168.0.100
netmask 255.255.255.0
network 192.168.0.0
broadcast 192.168.0.255
gateway 192.168.0.1
dns-nameservers 192.168.0.1

然后重新启动电脑。

之后我可以使用

cv::VideoCapture vcap("rtsp://root:pass@192.168.0.90/axis-media/media.amp?camera=1");