OpenCV Q&A Forum - RSS feedhttp://answers.opencv.org/questions/OpenCV answersenCopyright <a href="http://www.opencv.org">OpenCV foundation</a>, 2012-2018.Tue, 23 Jan 2018 11:57:55 -0600Find the most frequently occurring element in a rowhttp://answers.opencv.org/question/183059/find-the-most-frequently-occurring-element-in-a-row/ I have a vector of 5 mat objects each of size 60 x 1.
I need to return a single 60 x 1 matrix where each value in a row corresponds to the most frequently occurring value in the corresponding row in the 5 matrices.
How should I do this?Tue, 23 Jan 2018 09:03:01 -0600http://answers.opencv.org/question/183059/find-the-most-frequently-occurring-element-in-a-row/Comment by sjhalayka for <p>I have a vector of 5 mat objects each of size 60 x 1.
I need to return a single 60 x 1 matrix where each value in a row corresponds to the most frequently occurring value in the corresponding row in the 5 matrices.
How should I do this?</p>
http://answers.opencv.org/question/183059/find-the-most-frequently-occurring-element-in-a-row/?comment=183068#post-id-183068The previous code counts each unique pixel value. ci->first is the pixel value, and ci->second is the count.Tue, 23 Jan 2018 09:41:09 -0600http://answers.opencv.org/question/183059/find-the-most-frequently-occurring-element-in-a-row/?comment=183068#post-id-183068Comment by sjhalayka for <p>I have a vector of 5 mat objects each of size 60 x 1.
I need to return a single 60 x 1 matrix where each value in a row corresponds to the most frequently occurring value in the corresponding row in the 5 matrices.
How should I do this?</p>
http://answers.opencv.org/question/183059/find-the-most-frequently-occurring-element-in-a-row/?comment=183067#post-id-183067#include <opencv2/opencv.hpp>
using namespace cv;
#pragma comment(lib, "opencv_world340.lib")
#include <iostream>
#include <map>
using namespace std;
int main(void)
{
Mat frame = imread("strip.png");
if (frame.empty())
{
cout << "Error loading image file" << endl;
return -1;
}
map<unsigned char, size_t> pixel_map;
for (int j = 0; j < frame.rows; j++)
for (int i = 0; i < frame.cols; i++)
pixel_map[frame.at<unsigned char>(j, i)]++;
for (map<unsigned char, size_t>::const_iterator ci = pixel_map.begin(); ci != pixel_map.end(); ci++)
cout << static_cast<unsigned int>(ci->first) << " -> " << ci->second << endl;
return 0;
}Tue, 23 Jan 2018 09:37:10 -0600http://answers.opencv.org/question/183059/find-the-most-frequently-occurring-element-in-a-row/?comment=183067#post-id-183067Comment by teenvan95 for <p>I have a vector of 5 mat objects each of size 60 x 1.
I need to return a single 60 x 1 matrix where each value in a row corresponds to the most frequently occurring value in the corresponding row in the 5 matrices.
How should I do this?</p>
http://answers.opencv.org/question/183059/find-the-most-frequently-occurring-element-in-a-row/?comment=183066#post-id-183066yes CV_8UC1Tue, 23 Jan 2018 09:27:41 -0600http://answers.opencv.org/question/183059/find-the-most-frequently-occurring-element-in-a-row/?comment=183066#post-id-183066Comment by sjhalayka for <p>I have a vector of 5 mat objects each of size 60 x 1.
I need to return a single 60 x 1 matrix where each value in a row corresponds to the most frequently occurring value in the corresponding row in the 5 matrices.
How should I do this?</p>
http://answers.opencv.org/question/183059/find-the-most-frequently-occurring-element-in-a-row/?comment=183065#post-id-183065OK, what is the Mat type? CV_8UC1?Tue, 23 Jan 2018 09:25:22 -0600http://answers.opencv.org/question/183059/find-the-most-frequently-occurring-element-in-a-row/?comment=183065#post-id-183065Comment by teenvan95 for <p>I have a vector of 5 mat objects each of size 60 x 1.
I need to return a single 60 x 1 matrix where each value in a row corresponds to the most frequently occurring value in the corresponding row in the 5 matrices.
How should I do this?</p>
http://answers.opencv.org/question/183059/find-the-most-frequently-occurring-element-in-a-row/?comment=183063#post-id-183063Not an image per se. It is just a Mat object of labels generated from the DTree I trained. Specifically, it consists of the class labels.Tue, 23 Jan 2018 09:19:36 -0600http://answers.opencv.org/question/183059/find-the-most-frequently-occurring-element-in-a-row/?comment=183063#post-id-183063Comment by sjhalayka for <p>I have a vector of 5 mat objects each of size 60 x 1.
I need to return a single 60 x 1 matrix where each value in a row corresponds to the most frequently occurring value in the corresponding row in the 5 matrices.
How should I do this?</p>
http://answers.opencv.org/question/183059/find-the-most-frequently-occurring-element-in-a-row/?comment=183061#post-id-183061Colour or greyscale?
Are you familiar with the C++ Standard Template Library map container?Tue, 23 Jan 2018 09:12:49 -0600http://answers.opencv.org/question/183059/find-the-most-frequently-occurring-element-in-a-row/?comment=183061#post-id-183061Answer by berak for <p>I have a vector of 5 mat objects each of size 60 x 1.
I need to return a single 60 x 1 matrix where each value in a row corresponds to the most frequently occurring value in the corresponding row in the 5 matrices.
How should I do this?</p>
http://answers.opencv.org/question/183059/find-the-most-frequently-occurring-element-in-a-row/?answer=183081#post-id-183081you can use cv::max(), recursively:
vector<Mat> images;
Mat theMax = Mat::zeros(images[0].size(), images[0].type());
for (int i=0; i<5; i++) {
theMax = cv::max( theMax, images[i] );
}Tue, 23 Jan 2018 11:57:55 -0600http://answers.opencv.org/question/183059/find-the-most-frequently-occurring-element-in-a-row/?answer=183081#post-id-183081