栏目分类:
子分类:
返回
名师互学网用户登录
快速导航关闭
当前搜索
当前分类
子分类
实用工具
热门搜索
名师互学网 > IT > 软件开发 > 后端开发 > C/C++/C#

Jeston Nano 使用摄像头(c++)

C/C++/C# 更新时间: 发布时间: IT归档 最新发布 模块sitemap 名妆网 法律咨询 聚返吧 英语巴士网 伯小乐 网商动力

Jeston Nano 使用摄像头(c++)

阅读一些大佬的代码,整理在一起,方便以后使用

1.调用csi摄像头 1.1 代码
#include 
#include 
#include 
#include 
#include 
#include 
#include 
#include 
#include 

using namespace std;
using namespace cv;

string gstreamer_pipeline (int capture_width, int capture_height, int display_width, int display_height, int framerate, int flip_method)
{
    return "nvarguscamerasrc ! video/x-raw(memory:NVMM), width=(int)" + to_string(capture_width) + ", height=(int)" +
           to_string(capture_height) + ", format=(string)NV12, framerate=(fraction)" + to_string(framerate) +
           "/1 ! nvvidconv flip-method=" + to_string(flip_method) + " ! video/x-raw, width=(int)" + to_string(display_width) + ", height=(int)" +
           to_string(display_height) + ", format=(string)BGRx ! videoconvert ! video/x-raw, format=(string)BGR ! appsink";
}

int main( int argc, char** argv )
{
    int capture_width = 1280 ;
    int capture_height = 720 ;
    int display_width = 1280 ;
    int display_height = 720 ;
    int framerate = 60 ;
    int flip_method = 0 ;

    //创建管道
    string pipeline = gstreamer_pipeline(capture_width,
    capture_height,
    display_width,
    display_height,
    framerate,
    flip_method);
    std::cout << "使用gstreamer管道: nt" << pipeline << "n";

    //管道与视频流绑定
    VideoCapture cap(pipeline, CAP_GSTREAMER);
    if(!cap.isOpened())
    {
        std::cout<<"打开摄像头失败."<800)
          {
             new_height=int(new_width*1.0/width*height);
           }
         resize(img, img, cv::Size(new_width, new_height));

        imshow("CSI Camera",img);

        int keycode = cv::waitKey(30) & 0xff ; //ESC键退出
            if (keycode == 27) break ;
    }

    cap.release();
    destroyAllWindows() ;
}
1.2控制台编译

csi_camera.cpp为代码名称,test为想要生成可执行文件的名字(自己决定)

1.    g++ csi_camera.cpp -o test `pkg-config --cflags --libs opencv4`
2.    ./test
2.调用USB摄像头 2.1 代码
#include 
#include 
#include 
#include 
#include 
#include 
#include 
#include 
#include 
 
using namespace std;
using namespace cv;
 
int main( int argc, char** argv )
{
    //打开摄像头
    VideoCapture cap(1);    //使用 ls /dev/vid*查看使用的摄像头
 
    //创建显示窗口
    namedWindow("USB Camera", WINDOW_AUTOSIZE);
    Mat img;
 
    //逐帧显示
    while(true)
    {
        if (!cap.read(img))
        {
            std::cout<<"捕获失败"<800)
        {
            new_height=int(new_width*1.0/width*height);
        }
 
        resize(img, img, cv::Size(new_width, new_height));
        imshow("USB Camera",img);
 
        int keycode = cv::waitKey(30) & 0xff ; //ESC键退出
            if (keycode == 27) break ;
    }
 
    cap.release();
    destroyAllWindows() ;
}
2.2 控制台编译
1.    g++ usb_camera.cpp -o test `pkg-config --cflags --libs opencv4`
2.    ./test

Jetson Nano使用CSI摄像头教程(c++)_chutu2018的博客-CSDN博客_jetsonnano打开摄像头

转载请注明:文章转载自 www.mshxw.com
本文地址:https://www.mshxw.com/it/1038840.html
我们一直用心在做
关于我们 文章归档 网站地图 联系我们

版权所有 (c)2021-2022 MSHXW.COM

ICP备案号:晋ICP备2021003244-6号