/* first method */
cv::Mat_<double> myMat_ = ( cv::Mat_<double>(3, 3) <<
1.0, 2.0, 3.0,
4.0, 5.0, 6.0,
7.0, 8.0, 9.0);
cv::Mat_<double> myMat_ = cv::Mat_<double>::zeros(3, 3); // others: eyes, diag, ones
/* second method */
cv::Mat_<double> myMat_(3, 1, 0.0);
// -> cv::Mat image(3, 1, CV_64FC1, cv::Scalar(0.0));
// create a 100x100 color image and fill it with green(in RGB space)
cv::Mat_<cv::Vec3b> image( 100, 100, cv::Vec3b(0, 255, 0) );
/* third method */
cv::Mat myMat( 100, 100, CV_64F1, cv::Scalar(0) );
cv::Mat_<double>& myMat_ = (cv::Mat_<double>&)myMat;
/*
Note that Mat::at<_Tp>(int y, int x) and
Mat_<_Tp>::operator ()(int y, int x) do
absolutely the same and run at the same speed
*/
int rows = myMat_.rows;
int cols = myMat_.cols;
/* first method */
for ( int i=0; i<rows; i++ )
{
for ( int j=0; j<cols; j++ )
{
std::cout << myMat_(i, j) << std::endl;
}
}
// for multi-channel images/matrices:
for ( int i = 0; i < rows; i++ )
{
for( int j = 0; j < cols; j++ )
{
// scramble the 2nd (red) channel of each pixel
image(i, j)[2] ^= (uchar)(i ^ j); // ^: exclusive or operation
}
}
/* second method */
int matCount = rows * cols;
for ( int idx=0; idx < matCount; idx++ )
{
std::cout << myMat_(idx) <<std::endl;
}