void draw_projection(vector<int>& pos, int mode)
{
vector<int>::iterator max = std::max_element(std::begin(pos), std::end(pos)); //求最大值
if (mode == H_PROJECT)
{
int height = pos.size();
int width = *max;
Mat project = Mat::zeros(height, width, CV_8UC1);
for (int i = 0; i < project.rows; i++)
{
for (int j = 0; j < pos[i]; j++)
{
project.at<uchar>(i, j) = 255;
}
}
imshow("horizational projection", project);
}
else if (mode == V_PROJECT)
{
int height = *max;
int width = pos.size();
Mat project = Mat::zeros(height, width, CV_8UC1);
for (int i = 0; i < project.cols; i++)
{
for (int j = project.rows - 1; j >= project.rows - pos[i]; j--)
{
//std::cout << "j:" << j << "i:" << i << std::endl;
project.at<uchar>(j, i) = 255;
}
}
imshow("vertical projection", project);
}
waitKey();
}
版权声明:本文为qq_26134355原创文章,遵循 CC 4.0 BY-SA 版权协议,转载请附上原文出处链接和本声明。