Opencv Mat的操作
cout << mat 有错误的原因
You are using OpenCV built with VS10. The ostream operator << in the DLL is using the operator from VC 10 Runtime. While you are calling the ostream operator << from VC 11 Runtime. The DLLs are conflicting
template T& Mat::at(int i) const 必须在编译期确定参数T
#include <opencv2/opencv.hpp>
#include <iostream>
#include <iomanip>
using namespace std;
using namespace cv;
void print(Mat mat, int prec)
{
cout << "[" << endl;
for (int i = 0; i < mat.size().height; i++)
{
for (int j = 0; j < mat.size().width; j++)
{
cout << setprecision(prec) << mat.at<float>(i, j);
if (j != mat.size().width - 1)
cout << ", ";
else
cout << endl;
}
}
cout << "]" << endl;
}
int main()
{
float array[] = { 1,2,3 };
float array1[] = { 2,3,1 };
//用数组初始化Mat
Mat mat = Mat(1, 3, CV_32F, array);
Mat mat1 = Mat(1, 3, CV_32F, array1);
Mat tempmat;
//对mat拷贝
mat.copyTo(tempmat);
print(tempmat,5);
//选择roi,rect的四个参数分别是(x,y)坐标,第三个参数是宽度,第四个参数是高度
Mat roi(mat, Rect(0, 0, 2, 1));
print(roi,5);
//mat-mat1的1范数
cout << norm(mat, mat1, CV_L1) << endl;
//mat-mat1的2范数
cout << norm(mat, mat1, CV_L2) << endl;
//打印mat的内容
print(mat ,5);
//创建对角为1的矩阵
Mat eyemat = Mat::eye(4, 4, CV_32F);
print(eyemat,5 );
//提取eyemat的0-1行,2-3列
Mat submat = eyemat(Range(0, 2), Range(2, 4));
print(submat,5);
//abs(),max(),min(),+,-,*,/等操作很简单,就不写了
float a[2][2] = { 2,3,1,2 };
float b[2][2] = { 2,1,0,-1 };
Mat amat(2, 2, CV_32F, a);
Mat bmat(2, 2, CV_32F, b);
print( amat ,5);
print( bmat,5);
//求amat的逆
print( amat.inv(),5);
//两矩阵相乘
print( amat.mul(bmat),5 );
print(amat.mul(6), 5);
//生成一个值为0的矩阵
print( Mat::zeros(3, 3, CV_32F),5 );
//生成一个值为1的矩阵
print( Mat::ones(3, 3, CV_32F) ,5);
system("pause");
}
Opencv Mat的操作的更多相关文章
- opencv Mat 像素操作
1 cv::Mat cv::Mat是一个n维矩阵类,声明在<opencv2/core/core.hpp>中. class CV_EXPORTS Mat { public: //a lo ...
- opencv MAT数据操作
1.存取单个像素值 最通常的方法就是 img.at<uchar>(i,j) = 255; img.at<Vec3b>(i,j)[0] = 255; 2.用指针扫描一幅图像 对于 ...
- Opencv Mat矩阵操作注意事项
矩阵操作通常不会进行元素复制,应注意: Mat a=Mat(100,100,CV_32S); Mat b=Mat(100,100,CV_32S); b=a.col(8);//此时并未进行元素赋值,而只 ...
- Visual Studio 控制台应用程序 同时使用OpenCV和matlab mat文件操作
matalb具有灵活的图像处理,代码编写起来简洁而高效.而OpenCV具有很多成熟的计算机视觉算法,能够处理很多实时的识别处理等问题,而且代码运行起来效率很高.所以如何结合两者之间的优点,是让很多学术 ...
- OpenCV MAT基本图像容器
参考博客: OpenCv中cv::Mat和IplImage,CvMat之间的转换 Mat - 基本图像容器 Mat类型较CvMat和IplImage有更强的矩阵运算能力,支持常见的矩阵运算(参照Mat ...
- 如何用OpenCV跟踪鼠标操作
转载:如何用OpenCV跟踪鼠标操作 http://blog.skyoung.org/2014/05/01/how-to-track-mouse/ 在视频第一帧手动标记出目标的位置是在线视觉跟踪中最基 ...
- [OpenCV]Mat类详解
http://blog.csdn.net/yang_xian521/article/details/7107786 Preface Mat:Matrix Mat类可以被看做是opencv中C++版本的 ...
- [opencv]常用阵列操作函数总结
/*=========================================================================*/ // 阵列操作 /*============ ...
- MAT文件操作
o李YZo 原文 MAT文件打开方法汇总及其他操作 MAT文件简介 为MATLAB使用的一种特有的二进制数据文件.MAT文件可以包含一个或者多个MATLAB 变量.MATLAB通常采用MAT文件把工作 ...
随机推荐
- Magical Forest
Problem Description There is a forest can be seen as N * M grid. In this forest, there is some magic ...
- 自定义 Yasnippet 模板
yasnippet可以把我们常用的代码段或文本储存起来,到使用的时候只需键入几个字母就会自动带出. 比如我们在写python代码时,常常会在文件的第一行写下: #!/usr/bin/env pytho ...
- ArcGIS Server 10.2 实战(四)格栅动态配色服务
当你的地理处理服务输出的是格栅,那个不可避免地需要为格栅的各类型数据添加不同色彩进行区分,而默认时格栅的色彩是随机的,或者固定死一套着色方案是也显得不够人性化,难以满足多样的客户需求,下面谈谈如何解决 ...
- CF Covered Path (贪心)
Covered Path time limit per test 1 second memory limit per test 256 megabytes input standard input o ...
- okhttputils开源库的混淆配置(Eclipse)
#=====================okhttputils框架===================== #====okhttputils==== -libraryjars libs/okht ...
- 上传系列:ajaxupload.js
ajaxupload.js 上次说了jquery.upload.js,这次再说一下ajaxupload.js,这个其实也比较简答,只有一个JS文件: html代码: $(function () { v ...
- error LNK2005: DDX_Control 已经在 uafxcwd.lib(wincore2.obj) 中定义
编译错误提示: 1>afxnmcdd.lib(wincore2.obj) : error LNK2005: "void __stdcall DDX_Control(classCData ...
- 【整理修订】Android.mk详解
Android.mk详解 1. Android.mk 的应用范围 Android.mk文件是GNU Makefile的一小部分,它用来对Android程序进行编译. 一个Android.mk文件可以编 ...
- 分布式系统怎样体现了CAP
`references:` 1. http://zh.wikipedia.org/wiki/CAP%E5%AE%9A%E7%90%86 2. http://en.wikipedia.org/wiki/ ...
- Unity User Group 北京站图文报道:《Unity3D VR游戏与应用开发》
很高兴,能有机会回报Unity技术社区:我和雨松MOMO担任UUG北京站的负责人, 组织Unity技术交流和分享活动. 本次北京UUG活动场地–微软大厦 成功的UUG离不开默默无闻的付出:提前2小时到 ...