• 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;
    }
    
  • 相关阅读:
    Js注释和对象
    卸载Oracle
    数据库设计三大范式
    Oracle用户管理
    Oracle权限管理详解
    Linux 性能监控之CPU&内存&I/O监控Shell脚本2
    Linux 性能监控之CPU&内存&I/O监控Shell脚本1
    Windows Win7建立wifi热点,手机共享WIFI上网
    Mariadb MySQL逻辑条件判断相关语句、函数使用举例介绍
    Mariadb MySQL、Mariadb中GROUP_CONCAT函数使用介绍
  • 原文地址:https://www.cnblogs.com/gongluck/p/9160829.html
Copyright © 2020-2023  润新知