当前位置: 首页 > news >正文

cv::Mat图像操作

图像读写

//include  header
#include <opencv2/imgcodecs.hpp>/**
Currently, the following file formats are supported:
Windows bitmaps - *.bmp, *.dib (always supported)
JPEG files - *.jpeg, *.jpg, *.jpe (see the Note section)
JPEG 2000 files - *.jp2 (see the Note section)
Portable Network Graphics - *.png (see the Note section)
WebP - *.webp (see the Note section)
Portable image format - *.pbm, *.pgm, *.ppm *.pxm, *.pnm (always supported)
Sun rasters - *.sr, *.ras (always supported)
TIFF files - *.tiff, *.tif (see the Note section)
OpenEXR Image files - *.exr (see the Note section)
Radiance HDR - *.hdr, *.pic (always supported)
Raster and Vector geospatial data supported by GDAL (see the Note section)
*/
Mat cv::imread	(	const String & 	filename,
int 	flags = IMREAD_COLOR 
);
bool cv::imwrite	(	const String & 	filename,
InputArray 	img,
const std::vector< int > & 	params = std::vector< int >() 
);

图像ROI选取

cv::Mat roi=frame(cv::Rect(x, y, roi_WIDTH, roi_HEIGHT));

图像多通道分离合并

//include header
#include <opencv2/core.hpp>
/**
void cv::split	(	const Mat & 	src,
Mat * 	mvbegin 
);
void cv::merge	(	const Mat * 	mv,
size_t 	count,
OutputArray 	dst 
);
*/
cv::Mat  src,dst;
std::vector<cv::Mat> imgplanes;
cv::split(src,imgplanes);
cv::merge(imgplanes,imgplanes.size(),dst);

图像串联组合

cv::Mat img_encode, img_encode1, img_encode2;
//水平串联
cv::hconcat(img_camera[0], img_camera[1], img_encode1);
cv::hconcat(img_camera[2], img_camera[3], img_encode2);
//垂直串联
cv::vconcat(img_encode1, img_encode2, img_encode);

Camera实时数据/视频回放

Camera实时数据

#include <opencv2/core.hpp>
#include <opencv2/videoio.hpp>
#include <opencv2/highgui.hpp>
#include <iostream>
#include <stdio.h>
using namespace cv;
using namespace std;
int main(int, char**)
{Mat frame;//--- INITIALIZE VIDEOCAPTUREVideoCapture cap;// open the default camera using default API// cap.open(0);// OR advance usage: select any API backendint deviceID = 0;             // 0 = open default cameraint apiID = cv::CAP_ANY;      // 0 = autodetect default API// open selected camera using selected APIcap.open(deviceID, apiID);// check if we succeededif (!cap.isOpened()) {cerr << "ERROR! Unable to open camera\n";return -1;}//--- GRAB AND WRITE LOOPcout << "Start grabbing" << endl<< "Press any key to terminate" << endl;for (;;){// wait for a new frame from camera and store it into 'frame'cap.read(frame);// check if we succeededif (frame.empty()) {cerr << "ERROR! blank frame grabbed\n";break;}// show live and wait for a key with timeout long enough to show imagesimshow("Live", frame);if (waitKey(5) >= 0)break;}// the camera will be deinitialized automatically in VideoCapture destructorreturn 0;
}

视频回放

cv::VideoCapture capture(videoPath);
for (;;)
{capture >> frame;
}
http://www.lryc.cn/news/305620.html

相关文章:

  • 【机器学习基础】一元线性回归(适合初学者的保姆级文章)
  • 2024年软件测试岗位-面试
  • 【坑】Spring Boot整合MyBatis,一级缓存失效
  • J7 - 对于ResNeXt-50算法的思考
  • R3F(React Three Fiber)基础篇
  • torch\tensorflow在大语言模型LLM中的作用
  • 设计模式-创建型模式-单例模式
  • 备战蓝桥杯—— 双指针技巧巧答链表1
  • 微信小程序返回上一级页面并自动刷新数据
  • Spring⼯⼚创建复杂对象
  • Top-N 泛型工具类
  • Java 后端面试指南
  • 142.环形链表 ||
  • Nacos、Eureka、Zookeeper注册中心的区别
  • CSS重点知识整理1
  • 【Langchain多Agent实践】一个有推销功能的旅游聊天机器人
  • 算法学习(十二)并查集
  • TensorRT及CUDA自学笔记003 NVCC及其命令行参数
  • 数据库管理-第154期 Oracle Vector DB AI-06(20240223)
  • 解决uni-app vue3 nvue中使用pinia页面空白问题
  • 不用加减乘除做加法
  • 旅游组团自驾游拼团系统 微信小程序python+java+node.js+php
  • LeetCode 第41天 | 背包问题 二维数组 一维数组 416.分割等和子集 动态规划
  • Ubuntu20.04和Windows11下配置StarCraft II环境
  • 【NCom】:通过高温气相合成调节Pt-CeO2相互作用以提高晶格氧的还原性
  • git 将一个分支的提交移动到另一个分支
  • vue3 实现 el-pagination页面分页组件的封装以及调用
  • #FPGA(IRDA)
  • Sora—openai最新大模型文字生成视频
  • VoIP(Voice over Internet Protocol 基于IP的语音传输)介绍(网络电话、ip电话)