当前位置:网站首页>Creation and assignment of graphic objects

Creation and assignment of graphic objects

2022-07-07 12:46:00 When will we get ashore?

  Here is the sample code :

void demo::tuxiang_creation()
{
    Mat m3 = Mat::ones(Size(400, 400), CV_8UC3);
    //std::cout << "width " << m3.cols << "height " << m3.rows << "channels " << m3.channels() << std::endl;
    m3 = Scalar(0,255,0);
    //std::cout << m3 << std::endl;
    //imshow(" Create an image ", m3);
    //Mat m4 = m3;
    Mat m4;
    m4=m3.clone();
    m4 = Scalar(255, 0, 0);
    imshow(" Images ", m3);
    imshow(" Images 4", m4);
    
}

stay opencv The basic calculation unit is matrix , use Mat As a prefix, you can define the matrix , stay C++ The most important concept is the concept of class , We can Mat As a matrix class , The class contains some basic operations on the class , and ones( Image size , Channel type ), It is such an operation , It creates a pixel for 400x400, Three channel images , Assign the return value to m3.

std::cout << "width " << m3.cols << "height " << m3.rows << "channels " << m3.channels() << std::endl;
// The president of the output matrix , Column length , Element length 

give the result as follows :

Assign a value to a matrix , If you assign a value to the matrix directly , for example m3=255, Just give m3 The first value of the element is assigned 255, The rest of the element remains unchanged ,

m3 = 255;
std::cout << m3 << std::endl;

 

 Mat m4=m3;

m4 And m3 Share one data ,m4 When the change ,m3 Also change at the same time , Empathy ,m3 change ,m4 It will change too. , Like C++ The concepts cited in it .

Another point was discovered today , Namely imshow() If the name of the created window is the same , He will only show one window , The latter window will overwrite the previous window .

over!!! 

原网站

版权声明
本文为[When will we get ashore?]所创,转载请带上原文链接,感谢
https://yzsam.com/2022/188/202207071032235034.html