zoukankan      html  css  js  c++  java
  • opencv mat

    mat基础教程:

    http://blog.csdn.net/sinat_31802439/article/details/50083291

    mat 初始化:

    Mat M(0,3,CV_32FC1);
    Mat shftMat=(Mat_<double>(3,3)<<1.0,0,leftImg.cols, 0,1.0,0, 0,0,1.0);

    mat 读取:

    topleft2 = presentToLastCorners.col(0);
    topleft2<float>(0,0);

    Keep in mind that the size identifier used in the at operator cannot be chosen at random. It depends
    on the image from which you are trying to retrieve the data. The table below gives a better insight in this:
    - If matrix is of type `CV_8U` then use `Mat.at<uchar>(y,x)`.
    - If matrix is of type `CV_8S` then use `Mat.at<schar>(y,x)`.
    - If matrix is of type `CV_16U` then use `Mat.at<ushort>(y,x)`.
    - If matrix is of type `CV_16S` then use `Mat.at<short>(y,x)`.
    - If matrix is of type `CV_32S` then use `Mat.at<int>(y,x)`.
    - If matrix is of type `CV_32F` then use `Mat.at<float>(y,x)`.
    - If matrix is of type `CV_64F` then use `Mat.at<double>(y,x)`.

    在Mat.at中看到

    mat 转变数据类型: 转载自http://blog.csdn.net/xiaxiazls/article/details/51204265

    cv::Mat matTemp = cv::Mat::zeros(100,100,CV_32F); //得到一个浮点型的100*100的矩阵  
    cv::Mat MatTemp2;  
    matTemp.convertTo(MatTemp2, CV_8U); //把矩阵matTemp转为unsing char类型的矩阵,注在转换过程中有可能数值上会出现一些变化,这个要注意  

    如何初始化一个任意大小mat

    使用构造函数

    Mat formedMat(1380,480,CV_8UC3);

    图片彩色转黑白

    http://blog.csdn.net/qq5132834/article/details/37736693

    cvtColor(OpencvimageColor,OpencvimageGray,COLOR_RGB2GRAY);

    将两幅图像链接成一幅图片

    http://blog.csdn.net/quincuntial/article/details/49947791

    计算图片像素平均值和方差

    void meanStdDev_test()
    {
        const char* imagename = "E:/1.jpg";   
        //产生灰度图
        Mat img = imread(imagename);
        Mat gray,color;
        cvtColor(img, gray, CV_RGB2GRAY);
        cout << "Channel: " << gray.channels() << endl;
    
        Mat tmp_m, tmp_sd;
        double m = 0, sd = 0;
    
        m = mean(gray)[0];
        cout << "Mean: " << m << endl;
    
        meanStdDev(gray, tmp_m, tmp_sd);
        m = tmp_m.at<double>(0,0);
        sd = tmp_sd.at<double>(0,0);
        cout << "Mean: " << m << " , StdDev: " << sd << endl;
    }

    Mat type()返回值对应类型:

    http://ninghang.blogspot.com/2012/11/list-of-mat-type-in-opencv.html

    使用mat出现corrupted unsorted chunks corrupted double-linked list错误,原因在于原来按Mat(col,row) 访问mat,应该是按照Mat(row,col)访问mat才对

    逐点访问Mat

    http://blog.csdn.net/xiaowei_cqu/article/details/7771760

    Mat& ScanImageAndReduceIterator(Mat& I, const uchar* const table)
    {
        // accept only char type matrices
        CV_Assert(I.depth() != sizeof(uchar));
        const int channels = I.channels();
        switch(channels)
        {
        case 1:
            {
                MatIterator_<uchar> it, end;
                for( it = I.begin<uchar>(), end = I.end<uchar>(); it != end; ++it)
                    *it = table[*it];
                break;
            }
        case 3:
            {
                MatIterator_<Vec3b> it, end;
                for( it = I.begin<Vec3b>(), end = I.end<Vec3b>(); it != end; ++it)
                {
                    (*it)[0] = table[(*it)[0]];
                    (*it)[1] = table[(*it)[1]];
                    (*it)[2] = table[(*it)[2]];
                }
            }
        }
        return I;
    }



  • 相关阅读:
    css 实现的纸张卷曲效果
    前端如何优化代码&前端web安全
    React native
    君士坦丁堡分叉引起的安全问题
    不用外部插件启用u盘ntfs写功能
    使用ubuntu搭建时间机器备份服务
    从一起“盗币”事件再谈合约安全问题
    如何让你的项目同时支持go vendor和go module
    golang plugin的依赖问题
    Plasma Cash合约解读
  • 原文地址:https://www.cnblogs.com/hong2016/p/6999884.html
Copyright © 2011-2022 走看看