1 Star 4 Fork 3

FelixWang810/Kinect动作捕捉软件

加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
文件
克隆/下载
OpencvFunc.cpp 5.97 KB
一键复制 编辑 原始数据 按行查看 历史
FelixWang810 提交于 2020-09-18 16:13 +08:00 . 功能代码
#include "OpencvFunc.h"
void draw_point(Mat& img, Point2f fp, Scalar color)
{
circle(img, fp, 2, color, FILLED, LINE_AA, 0);
}
void draw_delaunay(Mat& img, Subdiv2D& subdiv, Scalar delaunay_color)
{
vector<Vec6f> triangleList;
subdiv.getTriangleList(triangleList);
vector<Point> pt(3);
Size size = img.size();
Rect rect(0, 0, size.width, size.height);
for (size_t i = 0; i < triangleList.size(); i++)
{
Vec6f t = triangleList[i];
pt[0] = Point(cvRound(t[0]), cvRound(t[1]));
pt[1] = Point(cvRound(t[2]), cvRound(t[3]));
pt[2] = Point(cvRound(t[4]), cvRound(t[5]));
// Draw rectangles completely inside the image.
if (rect.contains(pt[0]) && rect.contains(pt[1]) && rect.contains(pt[2]))
{
line(img, pt[0], pt[1], delaunay_color, 1, LINE_AA, 0);
line(img, pt[1], pt[2], delaunay_color, 1, LINE_AA, 0);
line(img, pt[2], pt[0], delaunay_color, 1, LINE_AA, 0);
}
}
}
void draw_voronoi(Mat& img, Subdiv2D& subdiv)
{
vector<vector<Point2f> > facets;
vector<Point2f> centers;
subdiv.getVoronoiFacetList(vector<int>(), facets, centers);
vector<Point> ifacet;
vector<vector<Point> > ifacets(1);
for (size_t i = 0; i < facets.size(); i++)
{
ifacet.resize(facets[i].size());
for (size_t j = 0; j < facets[i].size(); j++)
ifacet[j] = facets[i][j];
Scalar color;
color[0] = rand() & 255;
color[1] = rand() & 255;
color[2] = rand() & 255;
fillConvexPoly(img, ifacet, color, 8, 0);
ifacets[0] = ifacet;
polylines(img, ifacets, true, Scalar(), 1, LINE_AA, 0);
circle(img, centers[i], 3, Scalar(), FILLED, LINE_AA, 0);
}
}
//去除二值图像边缘的突出部
//uthreshold、vthreshold分别表示突出部的宽度阈值和高度阈值
//type代表突出部的颜色,0表示黑色,1代表白色
void delete_jut(Mat& src, Mat& dst, int uthreshold, int vthreshold, int type)
{
//int threshold;
src.copyTo(dst);
int height = dst.rows;
int width = dst.cols;
int k; //用于循环计数传递到外部
for (int i = 0; i < height - 1; i++)
{
uchar* p = dst.ptr<uchar>(i);
for (int j = 0; j < width - 1; j++)
{
if (type == 0)
{
//行消除
if (p[j] == 255 && p[j + 1] == 0)
{
if (j + uthreshold >= width)
{
for (int k = j + 1; k < width; k++)
p[k] = 255;
}
else
{
for (k = j + 2; k <= j + uthreshold; k++)
{
if (p[k] == 255) break;
}
if (p[k] == 255)
{
for (int h = j + 1; h < k; h++)
p[h] = 255;
}
}
}
//列消除
if (p[j] == 255 && p[j + width] == 0)
{
if (i + vthreshold >= height)
{
for (k = j + width; k < j + (height - i)*width; k += width)
p[k] = 255;
}
else
{
for (k = j + 2 * width; k <= j + vthreshold * width; k += width)
{
if (p[k] == 255) break;
}
if (p[k] == 255)
{
for (int h = j + width; h < k; h += width)
p[h] = 255;
}
}
}
}
else //type = 1
{
//行消除
if (p[j] == 0 && p[j + 1] == 255)
{
if (j + uthreshold >= width)
{
for (int k = j + 1; k < width; k++)
p[k] = 0;
}
else
{
for (k = j + 2; k <= j + uthreshold; k++)
{
if (p[k] == 0) break;
}
if (p[k] == 0)
{
for (int h = j + 1; h < k; h++)
p[h] = 0;
}
}
}
//列消除
if (p[j] == 0 && p[j + width] == 255)
{
if (i + vthreshold >= height)
{
for (k = j + width; k < j + (height - i)*width; k += width)
p[k] = 0;
}
else
{
for (k = j + 2 * width; k <= j + vthreshold * width; k += width)
{
if (p[k] == 0) break;
}
if (p[k] == 0)
{
for (int h = j + width; h < k; h += width)
p[h] = 0;
}
}
}
}
}
}
}
//图片边缘光滑处理
//size表示取均值的窗口大小,threshold表示对均值图像进行二值化的阈值
void imageblur(Mat& src, Mat& dst, Size size, int threshold)
{
int height = src.rows;
int width = src.cols;
blur(src, dst, size);
for (int i = 0; i < height; i++)
{
uchar* p = dst.ptr<uchar>(i);
for (int j = 0; j < width; j++)
{
if (p[j] < threshold)
p[j] = 0;
else p[j] = 255;
}
}
}
Loading...
马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化
C++
1
https://gitee.com/felixwang810/kinect-motion-capture-software.git
git@gitee.com:felixwang810/kinect-motion-capture-software.git
felixwang810
kinect-motion-capture-software
Kinect动作捕捉软件
master

搜索帮助