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;
    }



  • 相关阅读:
    Ubuntu20.04 安装AMD显卡驱动
    Ubuntu IBus RIME 输入法 配置小鹤双拼
    python time常用转换
    Linux 目录软链接
    MarkDown 插入图片 && Picture To Base64
    Bitmap 简介
    Linux 使用命令发送邮件
    Linux分区
    PyQt graphicsView自适应显示图像
    Python 图片转视频
  • 原文地址:https://www.cnblogs.com/hong2016/p/6999884.html
Copyright © 2011-2022 走看看