Mat::forEach operation is resulting in error
by going through this link I got some information , and tested it. I am working on opencv v3.4.2 in Ubuntu 18.04.
If I am using cv::Point_<uchar> Pixel, its giving me a wrong output, but if uchar Pixel is being used the error is given at the compilation time only.
In member function 'void Operator::operator()(Pixel&, const int*) const': for_each.cpp:23:78: error: request for member 'x' in 'pixel', which is of non-class type 'Pixel {aka unsigned char}' rmat("[%d,%d]= %d \n",position[0],position[1],(uchar)pixel.x);
code
#include <opencv2/opencv.hpp>
#include <stdio.h>
#include "opencv2/highgui/highgui.hpp"
#include "opencv2/imgproc/imgproc.hpp"
#include <iostream>
using namespace std;
using namespace cv;
using std::cout;
typedef cv::Point_<uchar> Pixel;//wrong
//typedef uchar Pixel; // correct
//typedef Point3_<uint8_t> Pixel;
struct Operator {
void operator ()(Pixel &pixel, const int * position) const
{
cout << format("[%d,%d]= %d \n",position[0],position[1],(uchar)pixel.x);
}
};
int main( int argc, char* argv[])
{
Mat mTest(Size(3, 2), CV_8UC1,Scalar(0));
randn(mTest,Scalar(125),Scalar(125));
cout<<"I am using ----> cv::Point_<uchar> Pixel \n";
//cout<<"I am using ----> uchar Pixel \n";
cout<< format (" Size : %d , %d \n\n",mTest.rows,mTest.cols);
//for(;;)
{
for (int Rows = 0; Rows < mTest.rows; Rows++)
{
for (int Cols = 0; Cols < mTest.cols; Cols++)
{
cout << format("[%d,%d]= %d \t",Rows,Cols,mTest.at<uchar>(Rows,Cols));
}
cout << "\n";
}
cout << "\n\n";
}
//for(;;)
mTest.forEach<Pixel>(Operator());
waitKey();
return 0;
}
Is the problem with the new opencv version ?? And can it be resolved??