从Mat / cv :: Mat显示矩阵形式的图像数据(OpenCV)

时间:2016-04-27 16:22:31

标签: c++ c opencv

我现在处理学校项目,并且我跳跃以矩阵形式显示随机图像的像素值。下面是我用来确定行数和列数的代码,但我希望按列和行获取所有像素值。很抱歉,由于我对opencv越来越熟悉,因此我会很熟悉opencv,但我希望有人能真正帮助我。

由于

if( src.empty() )
{ cout << "No input picture" << endl;return -1; }

namedWindow( "Original image", CV_WINDOW_FREERATIO );
    imshow( "Original image", src);


cvtColor(src, gray, CV_BGR2GRAY);
namedWindow( "Gray image", CV_WINDOW_FREERATIO );  
    imshow( "Gray image", gray );

Canny( gray, edge, 50, 150, 3);
edge.convertTo(draw, CV_8U);
    namedWindow("edge", CV_WINDOW_FREERATIO );
    imshow("edge", draw);   

int rows = draw.rows;
int cols = draw.cols;

for(int y=0; y<rows; ++y) for(int x=0; x<cols; ++x) std::cout << "("<<x<<","<<y<<") = " << draw.at<unsigned char>(y,x) << std::endl;

//cout<< edge <<endl;   
cout<<"Number of rows:  "<<draw.rows<<endl;
cout<<"Number of columns:  "<<draw.cols<<endl;  


//cout << src << endl;


waitKey(0);                                       
    return 0;

0 个答案:

没有答案