2016-03-18 05:43:34 -0600
| commented question | Classification using Normal Bayes Classifier when Convexity Defects was used for extraction No i didn't apply any normalization. I was thinking about using a matrix consisting of the start of the defect, end of defect and the depth of the defect. |
2016-03-18 05:29:46 -0600
| asked a question | Classification using Normal Bayes Classifier when Convexity Defects was used for extraction Hello ! I am trying to build an automated hand recognition system in c++. I have already extracted the hand features using convex hull and convexity defects. Now i need to classify the gestures then match the gestures from the database. I am having confusion on which classification techniques i should use. What classification techniques should i used ? I read that i should build a matrix. How should i build the matrix ? Thank you |
2016-03-18 05:25:29 -0600
| received badge | ● Enthusiast
|
2016-03-18 05:25:29 -0600
| received badge | ● Enthusiast
|
2016-03-17 03:56:03 -0600
| asked a question | Non-rotational invariant feature extraction i am currently implementing a hand gesture recognition system and i need to extract features that are not rotation invariant. What feature extraction, classification method can i used to extract feature? |
2016-03-15 05:26:20 -0600
| asked a question | The whole frame is being considered as the biggest contour instead of the hand itself Hello ! I am trying to build a hand recognition system. The hand is not being considered as the biggest contour. The whole frame is considered as the biggest contour. Can you help me out ? Here's the code : #include "stdafx.h"
#include <opencv\cv.h>
#include <opencv\highgui.h>
#include <opencv2\imgproc\imgproc.hpp>
#include <opencv2\highgui\highgui.hpp>
#include <opencv2\video\background_segm.hpp>
#include <opencv2\opencv.hpp>
using namespace cv;
using namespace std;
int H_MIN = 0;
int H_MAX = 256;
int S_MIN = 0;
int S_MAX = 256;
int V_MIN = 0;
int V_MAX = 256;
int findBiggestContour(vector<vector<Point> > contours);
int IndexOfBiggestContour;
int _tmain(int argc, _TCHAR* argv[])
{
VideoCapture cap("mudras.mp4");
Mat frame(Size(640, 420), CV_8UC3);
Mat frame2(Size(640, 420), CV_8UC3);
if (!cap.isOpened())
return -1;
while (true){
cap >> frame;
cap >> frame2;
Size kSize;
kSize.height = 3;
kSize.width = 3;
double sigma = 0.3*(3 / 2 - 1) + 0.8;
GaussianBlur(frame, frame, kSize, sigma, 0.0, 4);
Mat hsv(Size(640, 420), CV_8UC3);
cvtColor(frame, hsv, CV_RGB2HSV);
Mat bw(Size(640, 420), CV_8UC1);
inRange(hsv, Scalar(H_MIN, S_MIN, V_MIN), Scalar(H_MAX, S_MAX, V_MAX), bw);
vector<Vec4i> hierarchy;
vector<vector<Point> > contours_hull;
Mat Erode(Size(640, 420), CV_8UC1);
cv::erode(bw, Erode, cv::Mat(), cv::Point(-1, -1));
Mat Dialate(Size(640, 420), CV_8UC1);
cv::dilate(Erode, Dialate, cv::Mat(), cv::Point(-1, -1), 2);
findContours(Dialate.clone(), contours_hull, hierarchy, CV_RETR_TREE, CV_CLOCKWISE, Point(0, 0)); // CV_CHAIN_APPROX_SIMPLE
if (contours_hull.size() > 0)
{
/// Find the convex hull object for each contour
vector<vector<Point> >hull(contours_hull.size());
//find the defects points for each contour
vector<vector<Vec4i>> defects(contours_hull.size());
vector<vector<int> > hullsI(contours_hull.size());
//find the biggest contour
IndexOfBiggestContour = findBiggestContour(contours_hull);
Point2f rect_points[4];
vector<RotatedRect> minRect(contours_hull.size());
vector<vector<Point> > contours_poly(contours_hull.size());
vector<Rect> boundRect(contours_hull.size());
try{
for (int i = 0; i < contours_hull.size(); i++)
{
convexHull(Mat(contours_hull[i]), hull[i], false);
convexHull(Mat(contours_hull[i]), hullsI[i], false);
convexityDefects(Mat(contours_hull[i]), hullsI[i], defects[i]);
if (IndexOfBiggestContour == i)
{
minRect[i] = minAreaRect(Mat(contours_hull[i]));
drawContours(frame2, contours_hull, IndexOfBiggestContour, CV_RGB(255, 255, 255), 2, 8, hierarchy, 0, Point());
drawContours(frame2, hull, IndexOfBiggestContour, CV_RGB(255, 0, 0), 2, 8, hierarchy, 0, Point());
approxPolyDP(Mat(contours_hull[i]), contours_poly[i], 3, true);
boundRect[i] = boundingRect(Mat(contours_poly[i]));
rectangle(frame2, boundRect[i].tl(), boundRect[i].br(), CV_RGB(0, 0, 0), 2, 8, 0);
Point2f rect_points[4];
minRect[i].points(rect_points);
for (int j = 0; j < 4; j++)
{
line(frame2, rect_points[j], rect_points[(j + 1) % 4], CV_RGB(255, 255, 0), 2, 8);
}
}
}
}
catch (Exception ex)
{
std::cout << "Object Not Found!!!" << std::endl;
}
for (int i = 0; i< contours_hull.size(); i++)
{
size_t count = contours_hull[i].size();
std::cout << "Count : " << count << std::endl;
if (count < 300)
continue;
vector<Vec4i>::iterator d = defects[i].begin();
while (d != defects[i].end()) {
Vec4i& v = (*d);
if (IndexOfBiggestContour == i){
int startidx = v[0];
Point ptStart(contours_hull[i][startidx]); // point of the contour where the defect begins
int endidx = v[1];
Point ptEnd(contours_hull[i][endidx]); // point ... (more) |
2016-03-15 03:40:53 -0600
| commented question | Stack around the variable 'hull_header' was corrupted when using convexity defects I have edited the question and shared the code |
2016-03-09 02:46:13 -0600
| asked a question | Stack around the variable 'hull_header' was corrupted when using convexity defects Hello ! I am trying to develop a hand recognition system. I am actually using convex hull but the problem is that i am getting the error Stack around the variable 'hull_header' was corrupted and the error come from this piece of code : void findConvexityDefects(vector<Point>& contour, vector<int>& hull, vector<Point>& convexDefects){
if (hull.size() > 0 && contour.size() > 0){
CvSeq* contourPoints;
CvSeq* defects;
CvMemStorage* storage;
CvMemStorage* strDefects;
CvMemStorage* contourStr;
CvConvexityDefect *defectArray = 0;
strDefects = cvCreateMemStorage();
defects = cvCreateSeq(CV_SEQ_KIND_GENERIC | CV_32SC2, sizeof(CvSeq), sizeof(CvPoint), strDefects);
// transform our vector<Point> into a CvSeq* object of CvPoint.
contourStr = cvCreateMemStorage();
contourPoints = cvCreateSeq(CV_SEQ_KIND_GENERIC | CV_32SC2, sizeof(CvSeq), sizeof(CvPoint),contourStr);
for (int i = 0; i<(int)contour.size(); i++) {
CvPoint cp = { contour[i].x, contour[i].y };
cvSeqPush(contourPoints, &cp);
}
// do the same thing with the hull index
int count = (int)hull.size();
int* hullK = (int*)malloc(count*sizeof(int));
for (int i = 0; i<count; i++){hullK[i] = hull.at(i); }
CvMat hullMat = cvMat(1, count, CV_32SC1, hullK);
// calculate convexity defects
storage = cvCreateMemStorage(0);
defects = cvConvexityDefects(contourPoints, &hullMat, storage);
defectArray = (CvConvexityDefect*)malloc(sizeof(CvConvexityDefect)*defects->total);
cvCvtSeqToArray(defects, defectArray, CV_WHOLE_SEQ);
// store defects points in the convexDefects parameter.
for (int i = 0; i<defects->total; i++){
CvPoint ptf;
ptf.x = defectArray[i].depth_point->x;
ptf.y = defectArray[i].depth_point->y;
convexDefects.push_back(ptf);
}
// release memory
cvReleaseMemStorage(&contourStr);
cvReleaseMemStorage(&strDefects);
cvReleaseMemStorage(&storage);
}
}
Here's the whole code : #include <opencv2/core/core.hpp>
#include <opencv2/highgui/highgui.hpp>
#include <opencv2/imgproc/imgproc.hpp>
#include <iostream>
#include <opencv2\opencv.hpp>
#include <vector>
#include <cmath>
#include <opencv2/features2d/features2d.hpp>
#include <opencv\highgui.h>
#include <opencv2\imgproc\imgproc_c.h>
#include <stdarg.h>
using namespace cv;
using namespace std;
/////////////////////////////////////////////////////////////
/// Global Variables
int filterKernelSize = 15; // size of median filter, need to be odd number
int resultDigit; // the outcome of the recognition algorithm
Mat src; Mat srcSm;
/// Function headers
int getContourAndHull(cv::Mat);
vector<int> elimNeighborHulls(vector<int>, vector<Point>); // to remove neighbor hulls
vector<int> filterHulls(vector<int>, vector<Point>, RotatedRect); // to remove hulls below a height
vector<int> filterHulls2(vector<int>, vector<Point>, vector<Point>, RotatedRect); // to further remove hulls around palm
vector<Point> filterDefects(vector<Point>, RotatedRect); // to remove defects below a height
void findConvexityDefects(vector<Point>&, vector<int>&, vector<Point>&);
void display(char*, cv::Mat);
/////////////////////////////////////////////////////////////
// void cvShowManyImages(char* title, int nArgs, ...);
int main(int argc, char** argv)
{
int i, j;
int n;
double handDepth = 24;
double maxVal1 = 0, minVal = 0;
unsigned char data = 90;
int lastNum = 0;
//Mat image;
Mat num1, num2, num3, num4, num5, num0;
const char* inFileSrc1 = "C:/Users/HDR/Documents/Visual Studio 2010/Projects/openCV_tutorial/1.png";
const char* inFileSrc2 = "C:/Users/HDR/Documents/Visual Studio 2010/Projects/openCV_tutorial/2.png";
const char* inFileSrc3 = "C:/Users/HDR/Documents/Visual Studio 2010/Projects/openCV_tutorial/3.png";
const char* inFileSrc4 = "C:/Users/HDR/Documents/Visual Studio 2010/Projects/openCV_tutorial/4.png";
const char* inFileSrc5 = "C:/Users/HDR/Documents/Visual Studio 2010/Projects/openCV_tutorial/5.png";
const char* inFileSrc0 = "C:/Users/HDR/Documents/Visual Studio 2010/Projects/openCV_tutorial ... (more) |
2016-03-04 04:44:03 -0600
| commented question | Hand detection using convex hull Oh i didn't realise .. I edited the question ... |
2016-03-04 04:43:15 -0600
| received badge | ● Editor
(source)
|
2016-03-04 04:25:38 -0600
| asked a question | Hand detection using convex hull I am trying to implement a hand recognition system using convex hull. I tried to detect the hand using biggest contour but it is getting the whole frame as biggest contour instead of the hand itself. Help ! #include "stdafx.h"
#include <opencv\cv.h>
#include <opencv\highgui.h>
#include <opencv2\imgproc\imgproc.hpp>
#include <opencv2\highgui\highgui.hpp>
#include <opencv2\video\background_segm.hpp>
#include <opencv2\opencv.hpp>
#include "opencv2/objdetect.hpp"
#include < stdio.h>
#include <iostream>
using namespace cv;
using namespace std;
const string trackbarWindowName = "Trackbars";
int H_MIN = 0;
int H_MAX = 256;
int S_MIN = 0;
int S_MAX = 256;
int V_MIN = 0;
int V_MAX = 256;
int findBiggestContour(vector<vector<Point> > contours);
int IndexOfBiggestContour;
void on_trackbar( int, void* )
{//This function gets called whenever a
// trackbar position is changed
}
void createTrackbars(){
namedWindow(trackbarWindowName,0);
//create memory to store trackbar name on window
char TrackbarName[50];
sprintf( TrackbarName, "H_MIN", H_MIN);
sprintf( TrackbarName, "H_MAX", H_MAX);
sprintf( TrackbarName, "S_MIN", S_MIN);
sprintf( TrackbarName, "S_MAX", S_MAX);
sprintf( TrackbarName, "V_MIN", V_MIN);
sprintf( TrackbarName, "V_MAX", V_MAX);
//create trackbars and insert them into window
//3 parameters are: the address of the variable that is changing when the trackbar is moved(eg.H_LOW),
//the max value the trackbar can move (eg. H_HIGH),
//and the function that is called whenever the trackbar is moved(eg. on_trackbar)
// ----> ----> ---->
createTrackbar( "H_MIN", trackbarWindowName, &H_MIN, H_MAX, on_trackbar );
createTrackbar( "H_MAX", trackbarWindowName, &H_MAX, H_MAX, on_trackbar );
createTrackbar( "S_MIN", trackbarWindowName, &S_MIN, S_MAX, on_trackbar );
createTrackbar( "S_MAX", trackbarWindowName, &S_MAX, S_MAX, on_trackbar );
createTrackbar( "V_MIN", trackbarWindowName, &V_MIN, V_MAX, on_trackbar );
createTrackbar( "V_MAX", trackbarWindowName, &V_MAX, V_MAX, on_trackbar );
}
int _tmain(int argc, _TCHAR* argv[])
{
VideoCapture cap("pathaka.MP4");
Mat frame(Size(640, 420),CV_8UC3);
Mat frame2(Size(640, 420),CV_8UC3);
createTrackbars();
if(!cap.isOpened())
return -1;
while(true){
cap>>frame;
cap>>frame2;
//blur( frame, frame, Size(3,3) );
Size kSize;
kSize.height = 3;
kSize.width = 3;
double sigma = 0.3*(3/2 - 1) + 0.8;
GaussianBlur(frame,frame,kSize,sigma,0.0,4);
Mat hsv(Size(640, 420),CV_8UC3);
cvtColor(frame,hsv,CV_BGR2YCrCb);
Mat bw(Size(640, 420),CV_8UC1);
inRange(hsv,Scalar(H_MIN,S_MIN,V_MIN),Scalar(H_MAX,S_MAX,V_MAX),bw);
vector<Vec4i> hierarchy;
vector<vector<Point> > contours_hull;
Mat Erode(Size(640, 420),CV_8UC1);
cv::erode(bw, Erode, cv::Mat(), cv::Point(-1,-1));
Mat Dialate(Size(640, 420),CV_8UC1);
cv::dilate(Erode, Dialate, cv::Mat(), cv::Point(-1,-1),2);
findContours(Dialate.clone(), contours_hull, hierarchy, CV_RETR_TREE , CV_CLOCKWISE, Point(0, 0) ); // CV_CHAIN_APPROX_SIMPLE
if(contours_hull.size() > 0)
{
/// Find the convex hull object for each contour
vector<vector<Point> >hull( contours_hull.size() );
//find the defects points for each contour
vector<vector<Vec4i>> defects( contours_hull.size()) ;
vector<vector<int> > hullsI(contours_hull.size());
//find the biggest contour
IndexOfBiggestContour = findBiggestContour(contours_hull);
Point2f rect_points[4];
vector<RotatedRect> minRect( contours_hull.size() );
vector<vector<Point> > contours_poly( contours_hull.size() );
vector<Rect> boundRect( contours_hull.size() );
try{
for( int i = 0; i < contours_hull.size(); i++ )
{
convexHull( Mat(contours_hull[i]), hull[i], false );
convexHull( Mat(contours_hull[i]), hullsI[i], false );
convexityDefects(Mat(contours_hull[i]),hullsI[i], defects[i]);
if(IndexOfBiggestContour == i)
{
minRect[i] = minAreaRect( Mat(contours_hull[i]) );
drawContours( frame2, contours_hull,IndexOfBiggestContour, CV_RGB ... (more) |
2016-03-03 04:46:10 -0600
| received badge | ● Scholar
(source)
|
2016-03-02 05:57:44 -0600
| commented answer | Debug assertion fail when using grayscale I am now getting a total black image. |
2016-03-02 05:36:01 -0600
| commented question | Debug assertion fail when using grayscale Debug Assertion Failed! Program: C:\Windows\system32\MSVCP120D.dll File: c:\program files\microsoft visual studio12.0\vc\include\vector Line:1201 Expression:vector subscript out of range |
2016-03-02 05:23:50 -0600
| asked a question | Debug assertion fail when using grayscale I am trying to make a hand recognition system but when i used grayscale for cvtColor, i get debug assertion fail but when i use HSV the code works fine. Can you resolve this ? I am a newbie in opencv. #include "stdafx.h"
#include "opencv2/imgproc/imgproc.hpp"
#include "opencv2/highgui/highgui.hpp"
#include "opencv2/objdetect.hpp"
#include < opencv2\opencv.hpp>
#include < stdio.h>
#include <iostream>
using namespace std;
using namespace cv;
int thresh = 100;
int findBiggestContour(vector<vector<Point> > contours){
int indexOfBiggestContour = -1;
int sizeOfBiggestContour = 0;
for (int i = 0; i < contours.size(); i++){
if (contours[i].size() > sizeOfBiggestContour){
sizeOfBiggestContour = contours[i].size();
indexOfBiggestContour = i;
}
}
return indexOfBiggestContour;
}
void shifcontour(vector<Point>& contour, int x, int y)
{
for (size_t i = 0; i<contour.size(); i++)
{
contour[i].x += x;
contour[i].y += y;
}
}
int main()
{
cout << "beginning";
VideoCapture cap("pathaka.MP4");
if (!cap.isOpened()) // check if we succeeded
return -1;
Ptr<BackgroundSubtractor> pMOG2 = createBackgroundSubtractorMOG2();
for (;;)
{
Mat original, img;
cap >> img;
imshow("Source", img);
Mat hsv;
cvtColor(img, hsv, CV_BGR2GRAY);
Mat bw;
inRange(hsv, Scalar(0, 30, 80), Scalar(20, 150, 255), bw);
GaussianBlur(bw, bw, Size(7, 7), 1.5, 1.5);
Canny(bw, bw, 0, 30, 3);
vector<vector<Point> > contours;
vector<vector<Point> > convex_hull;
vector<Vec4i> hierarchy;
int erosion_type = MORPH_ELLIPSE;
int erosion_size = 0;
Mat element = getStructuringElement(erosion_type,
Size(2 * erosion_size + 1, 2 * erosion_size + 1),
Point(erosion_size, erosion_size));
dilate(bw, bw, element);
findContours(bw, contours, hierarchy, CV_RETR_TREE, CV_CHAIN_APPROX_SIMPLE, Point(0, 0));
int s = findBiggestContour(contours);
Mat drawing = Mat::zeros(img.size(), CV_8UC1);
dilate(drawing, drawing, getStructuringElement(MORPH_ELLIPSE, Size(5, 5)));
dilate(drawing, drawing, getStructuringElement(MORPH_ELLIPSE, Size(5, 5)));
std::vector<cv::Point> cnt;
cnt = contours[s];
Moments M;
M = cv::moments(cnt);
cv::Point result;
result = cv::Point(M.m10 / M.m00, M.m01 / M.m00);
Point center(drawing.cols / 2, drawing.rows / 2);
cv::circle(drawing, center, 3, Scalar(255, 255, 255), -1, 8, 0);
int x;
if (result.x > center.x)
{
x = result.x - center.x;
x = -x;
}
else
{
x = result.x - center.x;
}
int y;
if (result.y < center.y)
{
y = center.y - result.y;
}
else
{
y = center.y - result.y;
}
cout << "x:" << x << endl;
cout << "y: " << y << endl;
shifcontour(contours[s], x, y);
drawContours(drawing, contours, s, Scalar(255), -1, 8, hierarchy, 0, Point());
imshow("Hsv", drawing);
if (waitKey(30) >= 0) break;
}
return 0;
}
|