Opencv4.0:遍历Mat图像空间、读取摄像头

GitHub

https://github.com/gongluck/Opencv3.4-study.git

#include "opencv2/opencv.hpp"
using namespace cv;
#pragma comment(lib, "opencv_calib3d340d.lib")
#pragma comment(lib, "opencv_core340d.lib")
#pragma comment(lib, "opencv_dnn340d.lib")
#pragma comment(lib, "opencv_features2d340d.lib")
#pragma comment(lib, "opencv_flann340d.lib")
#pragma comment(lib, "opencv_highgui340d.lib")
#pragma comment(lib, "opencv_imgcodecs340d.lib")
#pragma comment(lib, "opencv_imgproc340d.lib")
#pragma comment(lib, "opencv_ml340d.lib")
#pragma comment(lib, "opencv_objdetect340d.lib")
#pragma comment(lib, "opencv_photo340d.lib")
#pragma comment(lib, "opencv_shape340d.lib")
#pragma comment(lib, "opencv_stitching340d.lib")
#pragma comment(lib, "opencv_superres340d.lib")
#pragma comment(lib, "opencv_video340d.lib")
#pragma comment(lib, "opencv_videoio340d.lib")
#pragma comment(lib, "opencv_videostab340d.lib")

int main()
{
    //显示图片
    Mat image = imread("test.png");
    namedWindow("window");
    imshow("window", image);

    //遍历Mat图像空间
    Mat mat(500, 300, CV_8UC3);
    //mat.create(500, 300, CV_8UC3);
    int size = mat.rows*mat.cols*mat.elemSize();
    int esize = mat.elemSize();
    for (int i = 0; i < size; i += esize)
    {
        mat.data[i] = 0;//B
        mat.data[i+1] = 255;//G
        mat.data[i+2] = 0;//R
    }
    namedWindow("Mat");
    imshow("Mat", mat);

    //读取摄像头
    VideoCapture cam;
    bool res = cam.open("rtsp://184.72.239.149/vod/mp4://BigBuckBunny_175k.mov");
    //bool res = cam.open(0);
    Mat capture;
    namedWindow("Cap");
    if (cam.isOpened())
    {
        while (true)
        {
            //cam.read(capture);
            if (!cam.grab())//读取并解码
                continue;
            if(!cam.retrieve(capture))//YUV转RGB
                continue;
            imshow("Cap", capture);
            waitKey(1);
        }
        cam.release();
    }
        
    waitKey(0);
    system("pause");
    return 0;
}

本文参与腾讯云自媒体分享计划,欢迎正在阅读的你也加入,一起分享。

发表于

我来说两句

0 条评论
登录 后参与评论

相关文章

来自专栏张善友的专栏

LINQ via C# 系列文章

LINQ via C# Recently I am giving a series of talk on LINQ. the name “LINQ via C...

2615
来自专栏Ceph对象存储方案

Luminous版本PG 分布调优

Luminous版本开始新增的balancer模块在PG分布优化方面效果非常明显,操作也非常简便,强烈推荐各位在集群上线之前进行这一操作,能够极大的提升整个集群...

3095
来自专栏一个爱瞎折腾的程序猿

sqlserver使用存储过程跟踪SQL

USE [master] GO /****** Object: StoredProcedure [dbo].[sp_perfworkload_trace_s...

2000
来自专栏张善友的专栏

Mix 10 上的asp.net mvc 2的相关Session

Beyond File | New Company: From Cheesy Sample to Social Platform Scott Hansel...

2527
来自专栏杨龙飞前端

scrollto 到指定位置

2494
来自专栏飞扬的花生

jsencrypt参数前端加密c#解密

      写程序时一般是通过form表单或者ajax方式将参数提交到服务器进行验证,如何防止提交的请求不被抓包后串改,虽然无法说绝对安全却给非法提交提高了难度...

3859
来自专栏张善友的专栏

Miguel de Icaza 细说 Mix 07大会上的Silverlight和DLR

Mono之父Miguel de Icaza 详细报道微软Mix 07大会上的Silverlight和DLR ,上面还谈到了Mono and Silverligh...

2667
来自专栏陈仁松博客

ASP.NET Core 'Microsoft.Win32.Registry' 错误修复

今天在发布Asp.net Core应用到Azure的时候出现错误InvalidOperationException: Cannot find compilati...

4808
来自专栏大内老A

The .NET of Tomorrow

Ed Charbeneau(http://developer.telerik.com/featured/the-net-of-tomorrow/) Exciti...

30810
来自专栏芋道源码1024

熔断器 Hystrix 源码解析 —— 断路器 HystrixCircuitBreaker

本文主要基于 Hystrix 1.5.X 版本 1. 概述 2. HystrixCircuitBreaker 3. HystrixCircuitBreaker....

5277

扫码关注云+社区