opencv学习记录1 //cv::gemm()

因为学习需要,所以要用到矩阵相乘,看别人的程序,会用到cvGEMM,但这是OpenCV的老函数了,网上都是老式的用法,新版的操作方法几乎没有说明,查了一下函数库,有gemm函数可以代替,描述如下:

Performs generalized matrix multiplication.
C++: void gemm(InputArray src1, InputArray src2, double alpha, InputArray src3, double gamma, OutputArray dst, int flags=0 )

src1 – first multiplied input matrix that should have CV_32FC1, CV_64FC1, CV_32FC2, orCV_64FC2 type.
src2 – second multiplied input matrix of the same type as src1.
alpha – weight of the matrix product.
src3 – third optional delta matrix added to the matrix product; it should have the same type
as src1 and src2.
beta – weight of src3.
dst – output matrix; it has the proper size and the same type as input matrices.
flags – operation flags:
– GEMM_1_T transposes src1.
– GEMM_2_T transposes src2.
– GEMM_3_T transposes src3

于是写了以下的语句:

 Mat   T;
 Mat   A=Mat::eye(1,3,CV_32FC1);
 Mat   C=Mat::eye(3,3,CV_32FC1);
 std::cout<<"A="<<A<<std::endl<<"C="<<C<<std::endl;
 gemm(A,C,1,0,1,T,0);
 std::cout<<"T="<<T;

编译没问题,但运行就悲剧了,不知名原因异常弹出!!后来试了又试,终于调通了:

 Mat   T;
 Mat   A=Mat::eye(1,3,CV_32FC1);
 Mat   C=Mat::eye(3,3,CV_32FC1);
 std::cout<<"A="<<A<<std::endl<<"C="<<C<<std::endl;
 gemm(A,C,1,10,0,T,0);//the src3 can't be 0,so if you 
			//want to ignore the src3,
                        //you should set the b  eater as 0
 std::cout<<"T="<<T;
如果你不想做加操作,也就是如果你想忽略src3时,不可以把src3设为0,而应该把beater设为0,这样src3就不会影响运算。
  • 1
    点赞
  • 2
    收藏
    觉得还不错? 一键收藏
  • 1
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值