#include <opencv/cv.h>
#include <iostream>
using namespace cv;
// sum up given row
long int sumup(Mat row, int width)
{
std::cout << "Sumup" << std::endl;
long int total = 0;
for (int i = 0; i < width; i++)
{
total += row.at<uchar>(0, i);
}
std::cout << "total: " << total << std::endl;
return total;
}
// find the bottom threshold value.
int find_bottom(Mat img, int threshold)
{
int rows = img.rows;
int cols = img.cols;
int total_rows;
int bottom;
bottom = -1;
for (int i = rows - 1; i >= 0; i --)
{
total_rows = sumup(img.row(i), cols);
if (total_rows > threshold)
{
bottom = i;
break;
}
}
return bottom;
}
// test img function
void test()
{
Mat img = Mat::ones(3, 3, CV_8UC1);
img.at<uchar>(0, 0) = 2;
int bottom = find_bottom(img, 3);
std::cout << "Bottom: "<< bottom << std::endl;
}
int main()
{
test();
return 0;
}