Hi everyone, I´m new in C++ and OpenCv and have a little problem with scanning an image with pointers.
I want to switch my running (slowly) Source into faster code by using pointers instead of the iteration through the loop.
The actual code is listed below:
for (int i = 0; i < Image.rows; i++)
{
for (int j = 0; j < Image.cols; j++)
{
int y = x - Image.at<cv::Vec3b>(i, j)[2];
if ( (y - Image.at<cv::Vec3b>(i, j)[1] < Threshold1) && (x - Image.at<cv::Vec3b>(i, j)[0] < Threshold2))
{
BinaryImage.at<cv::Vec3b>(i, j)[0] = 255;
BinaryImage.at<cv::Vec3b>(i, j)[1] = 255;
BinaryImage.at<cv::Vec3b>(i, j)[2] = 255;
}
}
}
I´m not sure how to replace the part for computing the y-value and the if-line:
int y = x - Image.at<cv::Vec3b>(i, j)[2];
and
if ( (y - Image.at<cv::Vec3b>(i, j)[1] < Threshold1) && (x - Image.at<cv::Vec3b>(i, j)[0] < Threshold2))
My first solution doesn´t work.
uchar* ptr_Image = Image.ptr<uchar>(i);
for (int j = 0; j < Image.cols; ++j)
{
int y = x - *ptr_oImage+2;
if ( (y - *ptr_oImage++ < Threshold1) && (x - *ptr_oImage < Threshold2))
{ *ptr_oImage++ = 255;
*ptr_oImage++ = 255;
*ptr_oImage++ = 255;
}
}
I know, that an binary-image is ordinarily type CV_8U not CV_8UC3 but I need this with three channels ;)
Thank you!
Daniel S.