资源简介
本文对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协议
- 下一篇:班费管理系统主函数所以代码
相关资源
- vc++&opencv图像分块
- OpenCv背景差分228299
- 在VC 6.0的opencv环境下视频显示与捕捉
- openCV获取车流
- Opencv C++ 读取、保存图片
- OpenCV视频的保存以及显示
- c++中的chamfer matching 实现
- opencv背景差分
- vibe算法opencv+c++,RGB图像可用
- 行人检测 opencv
- opencv 对视频进行感兴趣区域设置并保
- fastMatch的c++实现(需要opencv支持)
- OpenCV 装入一幅彩色图像然后在源图像
- 车道线识别源码
- 基于opencv园检测
- 植物大战僵尸基于OpenCv和C++实现
- OPENCV角点检测
- opencv标志识别
- 基于轮廓的倾斜仪表校正
- 在opencv中将两个图像给融合,让图像
- 使用OpenCV编写一个程序,该程序完成
- 使用 OpenCV 编制一个简单的徒手绘图程
- OpenCV解决PnP问题
- 基于opencv3.2的Moravec、Forstner、Harris算
- opencv+udp+c++ 的摄像头实时传输显示源
- MFC中嵌入显示opencv图像
- opencv调用海康摄像头
- 激光雷达数据读取以及显示C++需配置
- OpenCV在TI 达芬奇以及OMAP平台下的移植
- 双目视觉匹配得到视差图
评论
共有 条评论