Monday, January 30, 2017

OpenCV Node js Bindings - Progress

I've decided to try and take a break today from implementing APIs, optimizing the node-overload-resolution and trying to execute OpenCV tests and just see if the fruits of my labor are actually working.

So I've started with this piece of code:

 var m = new alvision.Mat(500, 500, alvision.MatrixType.CV_8SC3);  
 alvision.circle(m, new alvision.Point(250, 250), 100, new alvision.Scalar(0, 0, 255), 3, alvision.LineTypes.FILLED);  
 alvision.imshow("test window", m);  
 alvision.waitKey(10000);  

Seems simple enough no?

but then I've discovered that I didn't implement circle yet:

alvision.circle(m, new alvision.Point(250, 250), 100, new alvision.Scalar(0, 0, 255), 3, alvision.LineTypes.FILLED);
         ^
Error: error executing +circle not implemented
    at Error (native)
    at Object. (node-alvision\test\tmp.ts:73:10)
    at Module._compile (module.js:556:32)
    at Module.m._compile (node-alvision\node_modules\ts-node\src\index.ts:299:25)
    at Module._extensions..js (module.js:565:10)
    at Object.require.extensions.(anonymous function) [as .ts] (node-alvision\node_modules\ts-node\src\index.ts:302:14)
    at Module.load (module.js:473:32)
    at tryModuleLoad (module.js:432:12)
    at Function.Module._load (module.js:424:3)
    at Function.Module.runMain (module.js:590:10)


but now that I got the overload resolution working, I've added these lines:

POLY_METHOD(imgproc::circle){
  auto img =info.at<IOArray*>(0)->GetInputOutputArray();
  auto center =info.at<Point*>(1)->_point;
  auto radius =info.at<int>(2);
  auto color =info.at<Scalar*>(3)->_scalar;
  auto thickness =info.at<int>(4);
  auto lineType =info.at<int>(5);
  auto shift =info.at<int>(6);
  cv::circle(img, *center, radius, *color, thickness, lineType, shift);

 }

Took about 20 seconds including compile time. 

And the result:



So far so good!

No comments:

Post a Comment