opencv学习09-30

  • Output image allocation for OpenCV functions is automatic (unless specified otherwise).
  • opencv函数的输出图像是自动独立分配内存。
  • You do not need to think about memory management with OpenCVs C++ interface.
  • The assignment operator and the copy constructor only copies the header.
  • 复制构造函数和=运算符仅仅赋值的mat的header,mat的data部分是共享的。
  • The underlying matrix of an image may be copied using the cv::Mat::clone() and cv::Mat::copyTo() functions.
  • mat的clone()和copyTo()方法可以完成分配内存的复制mat操作。
  • RGB is the most common as our eyes use something similar, however keep in mind that OpenCV standard display system composes colors using the BGR color space (a switch of the red and blue channel).
  • opencv中的通道是按BGR顺序存储的。
  • CV_[The number of bits per item][Signed or Unsigned][Type Prefix]C[The channel number]
  • For instance, CV_8UC3 means we use unsigned char types that are 8 bit long and each pixel has three of these to form the three channels. This are predefined for up to four channel numbers. CV_8UC3表示,每个像素由3个通道组成,每个通道由8bits的无符号整型(unsigned int)表示.
  • The cv::Scalar is four element short vector. Specify this and you can initialize all matrix points with a custom value. If you need more you can create the type with the upper macro, setting the channel number in parenthesis as you can see below.
  • cv::Scalar 是一个最多4个短容器,可以用来初始化mat中的每个像素,也可以建立更大的容器来进行初始化操作。
  • imread(string filename, int flags)
  • flags:

    MREAD_UNCHANGED 

    If set, return the loaded image as is (with alpha channel, otherwise it gets cropped).

    IMREAD_GRAYSCALE 

    If set, always convert image to the single channel grayscale image.

    IMREAD_COLOR 

    If set, always convert image to the 3 channel BGR color image.

    IMREAD_ANYDEPTH 

    If set, return 16-bit/32-bit image when the input has the corresponding depth, otherwise convert it to 8-bit.

    IMREAD_ANYCOLOR 

    If set, the image is read in any possible color format.

    IMREAD_LOAD_GDAL 

    If set, use the gdal driver for loading the image.

    IMREAD_REDUCED_GRAYSCALE_2 

    If set, always convert image to the single channel grayscale image and the image size reduced 1/2.

    IMREAD_REDUCED_COLOR_2 

    If set, always convert image to the 3 channel BGR color image and the image size reduced 1/2.

    IMREAD_REDUCED_GRAYSCALE_4 

    If set, always convert image to the single channel grayscale image and the image size reduced 1/4.

    IMREAD_REDUCED_COLOR_4 

    If set, always convert image to the 3 channel BGR color image and the image size reduced 1/4.

    IMREAD_REDUCED_GRAYSCALE_8 

    If set, always convert image to the single channel grayscale image and the image size reduced 1/8.

    IMREAD_REDUCED_COLOR_8 

    If set, always convert image to the 3 channel BGR color image and the image size reduced 1/8.

    IMREAD_IGNORE_ORIENTATION 

    If set, do not rotate the image according to EXIF's orientation flag.

  • Mat creat(...)
  • #include <stdio.h>
    #include <fstream>
    #include <opencv2/opencv.hpp>
    using namespace cv;
    using namespace std;
    int main(int argc, char** argv)
    {
    	if(argc < 2)
    		return -1;
    	Mat img;
    	img = imread(argv[1],IMREAD_GRAYSCALE);
    	namedWindow("img", WINDOW_AUTOSIZE);
    	imshow("img", img);
    	Mat M(4,4,CV_8UC(2),Scalar(1,0));
    	cout << "M = "<< endl << " "  << M << endl << endl;
    	M.create(4,5, CV_8UC(2));
        cout << "M = "<< endl << " "  << M << endl << endl;
    	waitKey(0);
    	return 0;
    }
    M = 
     [  1,   0,   1,   0,   1,   0,   1,   0;
       1,   0,   1,   0,   1,   0,   1,   0;
       1,   0,   1,   0,   1,   0,   1,   0;
       1,   0,   1,   0,   1,   0,   1,   0]
    
    M = 
     [  0,   0,   0,   0,   0,   0,   0,   0,   0,   0;
       0,   0,   0,   0,   0,   0, 168,  97,   0,   0;
       0,   0,   0,   0, 113,   0,   0,   0,   0,   0;
       0,   0, 216, 219, 217, 153, 207, 127,   0,   0]
    

    You cannot initialize the matrix values with this construction(creat()). It will only reallocate its matrix data memory if the new size will not fit into the old one

  • You can fill out a matrix with random values using the cv::randu() function. You need to give the lower and upper value for the random values:

    Mat R = Mat(3, 2, CV_8UC3);

    randu(R, Scalar::all(0), Scalar::all(255));

  •  

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值