本文大部分代码转自:https://blog.csdn.net/ltg01/article/details/50492556
看到原文有很多人求完整代码,于是在这里给出完整代码,并且补充了更详细的注释,以便于更好的理解代码。具体的步骤和思路,原文里有详细的说明,这里就不再阐述了。
以下为完整代码:
#include "cv.h"
#include "highgui.h"
#include "cxcore.h"
using namespace std;
using namespace cv;
int getColSum(Mat src,int col)//统计所有列像素的总和
{
int sum = 0;
int height = src.rows;
int width = src.cols;
for (int i = 0; i < height; i++)
{
sum = sum + src.at <uchar>(i, col);
}
return sum;
}
int getRowSum(Mat src, int row)//统计所有行像素的总和
{
int sum = 0;
int height = src.rows;
int width = src.cols;
for (int i = 0; i < width; i++)
{
sum += src.at <uchar>(row, i);
}
return sum;
}
void cutTop(Mat& src, Mat& dstImg)//上下切割
{
int top, bottom;
top = 0;
bottom = src.rows;
int i