opencv 中对矩阵的排序例子

#include <iostream>  
#include <opencv/cv.h>  
#include <opencv/highgui.h>  
using namespace std;
using namespace cv;
int main()  
{  
    //cv::Mat testMat = cv::Mat::zeros ( 3, 3, CV_8UC1 );
	Mat dst;
	Mat testMat=(Mat_<int>(4,4) << 1,5,4,2,8,9,7,3,6,10,2,3,6,9,8,5);

    std::cout << "size of testMat: " << testMat.rows << " x " << testMat.cols << std::endl;  
    std::cout<<"testMat = "<<testMat<<std::endl;  
    //cv::Mat result = testMat.reshape ( 0, 1 );  

	cv::Mat flat; 
	testMat.reshape(1,1).copyTo(flat); 
	cv::sort(flat,flat,CV_SORT_EVERY_ROW + CV_SORT_ASCENDING);

	flat.reshape(1,4).copyTo(dst); 
    cout << " size of flat: " << flat.rows << " x " << flat.cols << std::endl;  
    cout << " size of reshaped dst: " << dst.rows << " x " << dst.cols << std::endl;  
    cout << "result = " << dst << std::endl;  
    waitKey(0);  
    system("pause");  
    return 0;  
}



reshape有两个参数:

其中,参数:cn为新的通道数,如果cn = 0,表示通道数不会改变。

参数rows为新的行数,如果rows = 0,表示行数不会改变。

注意:新的行*列必须与原来的行*列相等。

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值