zoukankan      html  css  js  c++  java
  • Jetson TX2(3)opencv3 打开usb摄像头

    ubuntu2604

    opencv3.4.0

    https://blog.csdn.net/ultimate1212/article/details/80936175?utm_source=blogxgwz7

    cmake_minimum_required(VERSION 2.8)
    project(DisplayImage)  
    
    set( CMAKE_CXX_FLAGS "-std=c++11 -O3" )
    
    find_package( OpenCV REQUIRED )  
    #if(CMAKE_VERSION VERSION_LESS "2.8.11")
      # Add OpenCV headers location to your include paths
      include_directories(
      include
      ${OpenCV_INCLUDE_DIRS}
       )
    #endif()
    
    #单个包添加
    #add_executable( DisplayImage src/DisplayImage.cpp )  
    
    #文件路径自动读取添加
    AUX_SOURCE_DIRECTORY(./src DIR_SRCS)
    ADD_EXECUTABLE(DisplayImage ${DIR_SRCS})
    target_link_libraries( DisplayImage ${OpenCV_LIBS} )
    
    
    
    #设置可执行文件的输出目录
    SET(EXECUTABLE_OUTPUT_PATH ${PROJECT_SOURCE_DIR}/bin)     
    

      

    #include <iostream>
    #include <opencv2/opencv.hpp>
    #include <string>
    using namespace cv;
    using namespace std;
    int main()
    {
        VideoCapture capture(0);
        if(capture.isOpened())
        {
            cout<<"success"<<endl;
        }
        Mat frame;
        while (capture.isOpened())
        {
            capture >> frame;
            imshow("capture", frame);
            char key = static_cast<char>(cvWaitKey(10));//控制视频流的帧率,10ms一帧
            if (key == 27)  //按esc退出
                break;               
        }
        return 0;
    }
    
    

      报错问题

    https://blog.csdn.net/dhaduce/article/details/80379792

    笔者在进行测试时,出现如下错误:

    libv4l2: error setting pixformat: Invalid argument
    libv4l2: error setting pixformat: Invalid argument
    libv4l2: error setting pixformat: Invalid argument
    libv4l2: error setting pixformat: Invalid argument
    VIDEOIO ERROR: V4L2: Pixel format of incoming image is unsupported by OpenCV
    Couldn't connect to webcam.

    OPENCV默认采用0号摄像头,TX2的0号摄像头是板子上自带的板上摄像头,而我们的usb摄像头是1号,故笔者使用如下代码,解决了问题

    如果上述方法不能解决问题,可以尝试如下操作:

    首先检查是否安装了v4l1compat.so

    dpkg -S v4l1compat.so
    

      若没有安装,则安装;若找到该文件,则跳过安装,进行下一步

    apt-cache search libv4l
    sudo apt-get install libv4l-ruby1.8
    

      然后添加环境变量

    export LD_PRELOAD=/usr/lib/aarch64-linux-gnueabihf/libv4l/v4l1compat.so
    export LD_PRELOAD=/usr/lib/aarch64-linux-gnueabihf/libv4l/v4l2convert.so
    

      

    sudo ldconfig
    

      

  • 相关阅读:
    最近面试遇到的技术问题
    Oracle 查看表空间使用情况
    流水账日记20150626
    Mantis及TestLink运维问题处理
    Mantis维护之显示姓名
    汤姆猫(。。。。)
    mac配置svn服务器
    如何使用TestFlight进行Beta测试
    artice与section的区别
    article元素设计网络新闻展示
  • 原文地址:https://www.cnblogs.com/kekeoutlook/p/10604226.html
Copyright © 2011-2022 走看看