• 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");
    }
    
  • 相关阅读:
    JS浅拷贝和深拷贝
    使用阿里云短信服务
    autojs相关的文档地址记录和简单使用
    Linux 根目录所在分区被脏数据占满
    openstack宿主机故障,虚拟实例恢复
    openstack创建vlan网络并配置网络设备
    联想 lenove 3750 M4服务器更改启动项和管理口IP
    ansible常用方法
    Mysql数据库-多实例主从复制-主从故障详解
    Linux 系统优化-workstation实践
  • 原文地址:https://www.cnblogs.com/shhu1993/p/4898451.html
Copyright © 2020-2023  润新知