From 23fc1c04edcf6fa20a090a8d6d7c7dd25288ee0c Mon Sep 17 00:00:00 2001 From: Dmitry Ivanov Date: Thu, 23 Oct 2014 15:50:05 -0400 Subject: [PATCH] HoughCircles added --- src/Matrix.cc | 36 ++++++++++++++++++++++++++++++++++++ src/Matrix.h | 1 + 2 files changed, 37 insertions(+) diff --git a/src/Matrix.cc b/src/Matrix.cc index 5df1b19..4e97c64 100755 --- a/src/Matrix.cc +++ b/src/Matrix.cc @@ -68,6 +68,7 @@ Matrix::Init(Handle target) { NODE_SET_PROTOTYPE_METHOD(ctor, "drawAllContours", DrawAllContours); NODE_SET_PROTOTYPE_METHOD(ctor, "goodFeaturesToTrack", GoodFeaturesToTrack); NODE_SET_PROTOTYPE_METHOD(ctor, "houghLinesP", HoughLinesP); + NODE_SET_PROTOTYPE_METHOD(ctor, "houghCircles", HoughCircles); NODE_SET_PROTOTYPE_METHOD(ctor, "inRange", inRange); NODE_SET_PROTOTYPE_METHOD(ctor, "adjustROI", AdjustROI); NODE_SET_PROTOTYPE_METHOD(ctor, "locateROI", LocateROI); @@ -1257,6 +1258,41 @@ NAN_METHOD(Matrix::HoughLinesP) { } +NAN_METHOD(Matrix::HoughCircles) { + NanScope(); + + Matrix *self = ObjectWrap::Unwrap(args.This()); + + double dp = args.Length() < 1 ? 1 : args[0]->NumberValue(); + double minDist = args.Length() < 2 ? 1 : args[1]->NumberValue(); + double higherThreshold = args.Length() < 3 ? 100 : args[2]->NumberValue(); + double accumulatorThreshold = args.Length() < 4 ? 100 : args[3]->NumberValue(); + int minRadius = args.Length() < 5 ? 0 : args[4]->Uint32Value(); + int maxRadius = args.Length() < 6 ? 0 : args[5]->Uint32Value(); + std::vector circles; + + cv::Mat gray; + + + equalizeHist(self->mat, gray); + + cv::HoughCircles(gray, circles, CV_HOUGH_GRADIENT, dp, minDist, higherThreshold, accumulatorThreshold, minRadius, maxRadius); + + v8::Local arr = NanNew(circles.size()); + + + for (unsigned int i=0; i < circles.size(); i++){ + v8::Local pt = NanNew(3); + pt->Set(0, NanNew((double) circles[i][0]));// center x + pt->Set(1, NanNew((double) circles[i][1]));// center y + pt->Set(2, NanNew((double) circles[i][2]));// radius + arr->Set(i, pt); + } + + NanReturnValue(arr); + +} + cv::Scalar setColor(Local objColor) { Local valB = objColor->Get(0); diff --git a/src/Matrix.h b/src/Matrix.h index 535134f..f041bca 100755 --- a/src/Matrix.h +++ b/src/Matrix.h @@ -74,6 +74,7 @@ class Matrix: public node::ObjectWrap { // Feature Detection JSFUNC(GoodFeaturesToTrack) JSFUNC(HoughLinesP) + JSFUNC(HoughCircles) JSFUNC(Crop)