资源简介
本文对http://docs.opencv.org/doc/tutorials/imgproc/shapedescriptors/hull/hull.html#hull以及http://www.intorobotics.com/9-opencv-tutorials-hand-gesture-detection-recognition/两个部分进行合并。并加入自己的图像预处理,包括采集、去背景和二值化。实现了手掌的特征点提取。
代码片段和文件信息
#include “stdafx.h“
#include
#include
// TODO: reference additional headers your program requires here
#include
#include // for strings
#include // for controlling float print precision
#include // string to number conversion
#include
#include
#include
#include
#include
#include “opencv2/core/core.hpp“
#include “opencv2/imgproc/imgproc.hpp“
#include “opencv2/highgui/highgui.hpp“
#include “opencv2/objdetect/objdetect.hpp“
#include “opencv2/video/video.hpp“
using namespace std;
using namespace cv;
#define PI 3.14159265
std::clock_t clock_start; //start clock
double time_consume; // time consume
cv::Mat raw_frame; //raw image
cv::Mat gray_frame; //my_gray_frame
cv::Mat segmented_frame; //image after segmentation
cv::Mat ROI_frame;
cv::Mat src;
cv::Mat src_gray;
cv::Mat drawing;
cv::Mat poly_frame;
cv::Mat convex_frame;
std::vector defects;
std::vector real_defects;
std::vector convexhull;
VideoCapture capture_single;
bool capture_image (int id); //get raw frame
void segment_image (int gray_lower_bound int gray_upper_bound); //segmentation
bool substract_background (); //get rid of background noise
void draw_contour(Mat frame std::vector contour Scalar scalar); //draw contour on a frame
int calc_point_angle(cv::Point point cv::Point center); //calculate the point angle based on the center point
int calc_points_dist (cv::Point point1 cv::Point point2)
{
int x_delta=point1.x - point2.x;
int y_delta=point1.y - point2.y;
int dist=(int)sqrt((double)(x_delta*x_delta + y_delta*y_delta));
return dist;
}
int calc_point_angle(cv::Point point cv::Point center)
{
//calculate two point dist
int angle = 0;
float sin_value = 0.0;
int dist = calc_points_dist(point center);
if(dist==0) return -1;
#ifdef DEBUG
// printf(“dist %d\n“dist);
#endif
//calculate sin value based on two points
sin_value = ((float)point.y- (float)center.y)/(float)dist;
if(sin_value>1) sin_value = 1; //exception handling
//get value
angle = (int)((double)std::asin(sin_value)*180/PI);
#ifdef DEBUG
// printf(“sin value %f\n“sin_value);
// printf(“my angle %d\n“angle);
#endif
if(point.x > center.x){
if(point.y < center.y)
{
//re calculate the angle
angle = 360+angle;
}
}
else
{
angle = 180 - angle;
}
return angle;
}
bool capture_image(int id){
capture_single.open(id);
//open fail
if(!capture_single.isOpened())
{
printf(“Error: cannot open camera!“);
return false;
}
}
void segment_image(int gray_lower_bound int gray_upper_bound){
cv::cvtColor(raw_frame gray_frame CV_BGR2GRAY);
//gray_lower_bound = pre_cut(raw_frame);
gray_lower_bound = 100;
cv::inRange(gray_frame gray_lower_bound gray_upper_bound segmented_frame);
/
- 上一篇:用Socket 实现http协议
- 下一篇:班费管理系统主函数所以代码
相关资源
- 人脸识别(opencv_facedetect_v4l2)
- 基于opencv的模板匹配代码
- opencv图片扫描以及校正
- opencv手部轮廓识别以及轨迹识别
- opencv2 3D标定.cpp
- 基于opencv漫水填充算法综合
- opencv激光中心线的提取
- OpenCV Computer Vision Application Programming
- 基于图割的图像分割OpenCV+MFC实现
- 识别魔方颜色
- opencv版俄罗斯方块源码
- VS2013 / MFC + OpenCV 2.4.9实现视频的播放
- 粒子滤波器+目标跟踪的C++实现,VS2
- 张平OpenCV算法精讲基于python和C++教材
- 虹膜识别开源代码OSIRIS4.1基于opencv
- Sift特征点提取与匹配opencv库
- YCbCr、混合高斯以及YCbCg肤色检测模型
- 光流法代码
- 基于leapmotion的HMM手势识别
- OpenCV打开摄像机显示在MFC窗口工程源
- 使用c++读取图像到二维矩阵
- 三维点云的圆柱面拟合
- MFC+OPENCV摄像机标定程序
- 基于特征脸的人脸识别MFC+OpenCV
- opencv图像处理MFC
- OPENCV人脸检测加角点检测并输出坐标
- FillHole.rar
- 道路提取算法 c++ opencv
- PCA代码实现详解
- opencv卡尔曼滤波
评论
共有 条评论