Jetson xavier nx 入门系列——c++调用opencv,读取rtsp视频流

发布时间:2023-06-07 08:00

1、问题检索

pkg-config --modversion opencv命令,查看opencv版本,提示找不到
在这里插入图片描述

Package opencv was not found in the pkg-config search path.
Perhaps you should add the directory containing `opencv.pc'
to the PKG_CONFIG_PATH environment variable
No package 'opencv' found

报错原因:是因为没有找到opencv.pc,而刷机时是安装了OpenCV的,不过是OpenCV4,在/usr/lib/aarch64-linux-gnu/pkgconfig中找到了opencv4.pc

2、解决方案

采用如下命令查看nx板中opencv版本,可知为opencv4

dpkg -l libopencv

Jetson xavier nx 入门系列——c++调用opencv,读取rtsp视频流_第1张图片
将pkg-config的命令修改为opencv4即可正常使用

pkg-config --modversion opencv4

在这里插入图片描述

3、C++使用opencv,并正确编译的方法

3.1 读取rtsp视频流示例
#include "opencv2\opencv.hpp"
#include 

using namespace cv;

int main()
{

  VideoCapture capture;
  //capture.open("../../bin/data/1.mp4");
  capture.open("rtsp://admin:admin123@192.168.1.164:554/cam/realmonitor?channel=1&subtype=0");

  int frameH = capture.get(4);
  int frameW = capture.get(3);
  std::cout << "frameH:" << frameH << "  frameW:" << frameW << std::endl;

  while (1)
  {
      Mat frame;
      capture >> frame;
      
      if (frame.empty())
      {
          break;
      }
      imshow("test", frame);
      waitKey(30);
  }
}
3.2 编译代码
方法一:直接进行命令行编译

注意,此处要写为opencv4

g++ -o Main capture_video.cpp `pkg-config opencv4 --libs --cflags`
方法二:编写CMakeLists.txt进行编译
  1. 编写CMakeLists.txt,内容如下
cmake_minimum_required(VERSION 2.8)

find_package(OpenCV)
include_directories(OpenCV_INCLUDE_DIRS)
message(${OpenCV_INCLUDE_DIRS})
message(${OpenCV_LIBRARIES})

add_definitions("-Wall -std=c++11")
add_executable(Main capture_video.cpp)

target_link_libraries(Main ${OpenCV_LIBRARIES})
  1. 开始编译,命令如下
mkdir build
cd build
cmake ..
make

参考文献

  1. Jetson AGX Xavier配置使用OpenCV(报错:No package ‘opencv’ found)
  2. opencv RTSP拉流

ItVuer - 免责声明 - 关于我们 - 联系我们

本网站信息来源于互联网,如有侵权请联系:561261067@qq.com

桂ICP备16001015号