reshape函数—— Matlab和opencv的reshape函数 不同点

opencv:

void PrintMat( Mat &_m)
 {
     Mat m = Mat_<float>( _m );
     for ( int k1=0; k1<m.rows; k1++ )
     {
         for ( int k2=0; k2<m.cols; k2++ )
         {
             cout << m.at<float>(k1,k2) << "    ";
         }
         cout << endl;
     }
 }
 
int _tmain(int argc, _TCHAR* argv[])
{
    Mat m = Mat::zeros(2,2,CV_32F);
 
    m.at<float>(0,0) = 1;
    m.at<float>(0,1) = 2;
    m.at<float>(1,0) = 3;
    m.at<float>(1,1) = 4;
 
    Mat m1 = m.reshape(0, 1);
    Mat m2 = m.reshape(0, 4);
 
    cout << "m:" << endl;
    PrintMat(m);
    cout << "m.reshape(0, 1):" << endl;
    PrintMat(m1);
    cout << "m.reshape(0, 4):" << endl;
    PrintMat(m2);
  return 0;
}
m:
1       2
3       4

m.reshape(0, 1):
1       2       3       4

m.reshape(0, 4):
1
2
3
4
请按任意键继续. . .

 

Matlab:

>> m = [1,2;3,4]
 
m =
 
     1     2
     3     4
 
>> m1 = reshape(m,1,4)
 
m1 =
 
     1     3     2     4
 
>> m2 = reshape(m,4,1)
 
m2 =
 
     1
     3
     2
     4

 

可以看出OPENCV是行优先,而matlab是列优先。

 

就这个小问题,让我的N久的训练全都是错位的!!!!

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值