1 | initial version |
First: OpenCV is column major.
Second: ImageF.at<Vec3f>(y, x) == ImageF.at<Vec3f>(Point(x, y));
This should work
#include "opencv2/highgui/highgui.hpp"
#include <iostream>
using namespace std;
using namespace cv;
int main()
{
Mat imageF(36,36, CV_32F);
int i = 0;
int j = 0;
float blue = 0.0;
float green= 0.0;
float red= 0.0;
Vec3f intensity;
for(y=0; y<imageF.rows; y++)
{
for(x=0; x<imageF.cols; x++)
{
// The next two rows do the same
//intensity = imageF.at<Vec3f>(y, x);
intensity = imageF.at<Vec3f>(Point(x, y));
//blue = intensity.val[0];
//green = intensity.val[1];
//red = intensity.val[2];
blue = red = green = 0.4;
intensity.val[0] = blue;
intensity.val[1] = green;
intensity.val[2] = red;
// The next two rows do the same
//imageF.at<Vec3f>(y, x) = intensity;
imageF.at<Vec3f>(Point(x, y)) = intensity;
}
}
imshow("Output", imageF);
waitKey(0);
return 0;
}
2 | No.2 Revision |
First: i: OpenCV is column row major.
Second: ii: ImageF.at<Vec3f>(y, x) == ImageF.at<Vec3f>(Point(x, y));
This should work
#include "opencv2/highgui/highgui.hpp"
#include <iostream>
using namespace std;
using namespace cv;
int main()
{
Mat imageF(36,36, CV_32F);
int i = 0;
int j = 0;
float blue = 0.0;
float green= 0.0;
float red= 0.0;
Vec3f intensity;
for(y=0; y<imageF.rows; y++)
{
for(x=0; x<imageF.cols; x++)
{
// The next two rows do the same
//intensity = imageF.at<Vec3f>(y, x);
intensity = imageF.at<Vec3f>(Point(x, y));
//blue = intensity.val[0];
//green = intensity.val[1];
//red = intensity.val[2];
blue = red = green = 0.4;
intensity.val[0] = blue;
intensity.val[1] = green;
intensity.val[2] = red;
// The next two rows do the same
//imageF.at<Vec3f>(y, x) = intensity;
imageF.at<Vec3f>(Point(x, y)) = intensity;
}
}
imshow("Output", imageF);
waitKey(0);
return 0;
}
3 | No.3 Revision |
i: OpenCV is row major.
ii: `ImageF.at<vec3f>(y, x) == ImageF.at<Vec3f>(y,
ImageF.at<Vec3f>(Point(x, y));ImageF.at<vec3f>(Point(x, y));'
iii: Do not use per Pixel manipulation. For constant values of the whole image use
cv::Mat imageF = cv::Mat(nRows, nCols, nType, cv::Scalar(blue, green, red));
or
imageF.setTo(cv::Scalar(blue, green, red));
This should work
#include "opencv2/highgui/highgui.hpp"
#include <iostream>
using namespace std;
using namespace cv;
int main()
{
Mat imageF(36,36, CV_32F);
int i = 0;
int j = 0;
float blue = 0.0;
float green= 0.0;
float red= 0.0;
Vec3f intensity;
for(y=0; y<imageF.rows; y++)
{
for(x=0; x<imageF.cols; x++)
{
// The next two rows do the same
//intensity = imageF.at<Vec3f>(y, x);
intensity = imageF.at<Vec3f>(Point(x, y));
//blue = intensity.val[0];
//green = intensity.val[1];
//red = intensity.val[2];
blue = red = green = 0.4;
intensity.val[0] = blue;
intensity.val[1] = green;
intensity.val[2] = red;
// The next two rows do the same
//imageF.at<Vec3f>(y, x) = intensity;
imageF.at<Vec3f>(Point(x, y)) = intensity;
}
}
imshow("Output", imageF);
waitKey(0);
return 0;
}
4 | No.4 Revision |
i: OpenCV is row major.
ii: `ImageF.at<vec3f>(y, x) == ImageF.at<vec3f>(Point(x, y));'
iii: Do not use per Pixel manipulation. For constant values of the whole image use
cv::Mat imageF = cv::Mat(nRows, nCols, nType, cv::Mat(36, 36, CV_32FC3, cv::Scalar(blue, green, red));
or
imageF.setTo(cv::Scalar(blue, green, red));
This should work
#include "opencv2/highgui/highgui.hpp"
#include <iostream>
using namespace std;
using namespace cv;
int main()
{
Mat imageF(36,36, CV_32F);
int i = 0;
int j = 0;
float blue = 0.0;
float green= 0.0;
float red= 0.0;
Vec3f intensity;
for(y=0; y<imageF.rows; y++)
{
for(x=0; x<imageF.cols; x++)
{
// The next two rows do the same
//intensity = imageF.at<Vec3f>(y, x);
intensity = imageF.at<Vec3f>(Point(x, y));
//blue = intensity.val[0];
//green = intensity.val[1];
//red = intensity.val[2];
blue = red = green = 0.4;
intensity.val[0] = blue;
intensity.val[1] = green;
intensity.val[2] = red;
// The next two rows do the same
//imageF.at<Vec3f>(y, x) = intensity;
imageF.at<Vec3f>(Point(x, y)) = intensity;
}
}
imshow("Output", imageF);
waitKey(0);
return 0;
}
5 | No.5 Revision |
i: OpenCV is row major.
ii: `ImageF.at<vec3f>(y, x) == ImageF.at<vec3f>(Point(x, y));'
iii: You allocate an 1 channel image with CV_32F
. Use CV_32FC3
iv: Do not use per Pixel manipulation. For constant values of the whole image use
cv::Mat imageF = cv::Mat(36, 36, CV_32FC3, cv::Scalar(blue, green, red));
or
imageF.setTo(cv::Scalar(blue, green, red));
This should work
#include "opencv2/highgui/highgui.hpp"
#include <iostream>
using namespace std;
using namespace cv;
int main()
{
Mat imageF(36,36, CV_32F);
CV_32FC3);
int i = 0;
int j = 0;
float blue = 0.0;
float green= 0.0;
float red= 0.0;
Vec3f intensity;
for(y=0; y<imageF.rows; y++)
{
for(x=0; x<imageF.cols; x++)
{
// The next two rows do the same
//intensity = imageF.at<Vec3f>(y, x);
intensity = imageF.at<Vec3f>(Point(x, y));
//blue = intensity.val[0];
//green = intensity.val[1];
//red = intensity.val[2];
blue = red = green = 0.4;
intensity.val[0] = blue;
intensity.val[1] = green;
intensity.val[2] = red;
// The next two rows do the same
//imageF.at<Vec3f>(y, x) = intensity;
imageF.at<Vec3f>(Point(x, y)) = intensity;
}
}
imshow("Output", imageF);
waitKey(0);
return 0;
}
6 | No.6 Revision |
i: OpenCV is row major.
ii: `ImageF.at<vec3f>(y, ImageF.at<Vec3f>(y,
x) == ImageF.at<vec3f>(Point(x, y));'ImageF.at<Vec3f>(Point(x, y));
iii: You allocate an 1 channel image with CV_32F
. Use CV_32FC3
iv: Do not use per Pixel manipulation. For constant values of the whole image use
cv::Mat imageF = cv::Mat(36, 36, CV_32FC3, cv::Scalar(blue, green, red));
or
imageF.setTo(cv::Scalar(blue, green, red));
This should work
#include "opencv2/highgui/highgui.hpp"
#include <iostream>
using namespace std;
using namespace cv;
int main()
{
Mat imageF(36,36, CV_32FC3);
int i = 0;
int j = 0;
float blue = 0.0;
float green= 0.0;
float red= 0.0;
Vec3f intensity;
for(y=0; y<imageF.rows; y++)
{
for(x=0; x<imageF.cols; x++)
{
// The next two rows do the same
//intensity = imageF.at<Vec3f>(y, x);
intensity = imageF.at<Vec3f>(Point(x, y));
//blue = intensity.val[0];
//green = intensity.val[1];
//red = intensity.val[2];
blue = red = green = 0.4;
intensity.val[0] = blue;
intensity.val[1] = green;
intensity.val[2] = red;
// The next two rows do the same
//imageF.at<Vec3f>(y, x) = intensity;
imageF.at<Vec3f>(Point(x, y)) = intensity;
}
}
imshow("Output", imageF);
waitKey(0);
return 0;
}