#include "opencv2/opencv.hpp"
#include <windows.h>
using namespace cv;
using namespace std;
POINT TEMP;
POINT LAST_CENTER;
void skinExtract(const Mat &frame, Mat &skinArea);
int main(int argc, char* argv[])
{
Mat frame, skinArea;
VideoCapture capture;
capture.open(0);
if (!capture.isOpened())
{
cout << "No camera!\n" << endl;
return -1;
}
while (1)
{
capture >> frame;
//Mat frame = imread("fingertips(1).jpg");
if (frame.empty())
break;
skinArea.create(frame.rows, frame.cols, CV_8UC1);//和原图像等行数/等列数的/8位无符号通/道数1
skinExtract(frame, skinArea);//找到皮肤
Mat show_img;
frame.copyTo(show_img, skinArea);
vector<vector<Point> > contours;
vector<Vec4i> hierarchy;//四维int向量
//寻找轮廓
findContours(skinArea, contours, hierarchy, CV_RETR_CCOMP, CV_CHAIN_APPROX_SIMPLE);
// 找到最大的轮廓
int index;
double area, maxArea(0);
for (int i = 0; i < contours.size(); i++)
{
area = contourArea(Mat(contours[i]));
if (area > maxArea)
{
maxArea = area;
index = i;
}
}
//drawContours(frame, contours, index, Scalar(0, 0, 255), 2, 8, hierarchy );
Moments moment
opencv形态学手势识别1-5
最新推荐文章于 2023-04-27 12:06:15 发布
![](https://img-home.csdnimg.cn/images/20240711042549.png)