diff --git a/bea/cv.bea b/bea/cv.bea index cb6721f..eb2b0d2 100644 --- a/bea/cv.bea +++ b/bea/cv.bea @@ -334,4 +334,5 @@ @manual void polylines(Mat& img, const Point** pts, const int* npts, int ncontours, bool isClosed, const Scalar& color, int thickness=1, int lineType=8, int shift=0) @manual double kmeans(const Mat& samples, int clusterCount, Mat& labels, TermCriteria termcrit, int attempts, int flags, Mat* centers) @manual void calcBackProject(const Mat* arrays, int narrays, const int* channels, const SparseMat& hist, Mat& backProject, const float** ranges, double scale=1, bool uniform=true) - @manual std::vector detectObject(const std::string& cascadeName, int imageWidth, int imageHeight) \ No newline at end of file + @manual std::vector detectObject(const std::string& cascadeName, int imageWidth, int imageHeight) + @manual node::Buffer imencode(const std::string& ext, const Mat& img, const std::vector& params=std::vector()) diff --git a/bea/opencv.bea b/bea/opencv.bea index 0abf063..e18461b 100644 --- a/bea/opencv.bea +++ b/bea/opencv.bea @@ -10,6 +10,8 @@ \#include \#include "bea.h" \#include "customTypes.h" + \#include + \#include #C++ code added to the cpp file @cpp diff --git a/src/opencv_manual.cpp b/src/opencv_manual.cpp index d7bd239..2c58892 100644 --- a/src/opencv_manual.cpp +++ b/src/opencv_manual.cpp @@ -164,4 +164,25 @@ namespace opencvjs { METHOD_END(); } + v8::Handle JOpenCV::imencode(const v8::Arguments& args) { + METHOD_BEGIN(2); + //node::Buffer imencode(const std::string& ext, const Mat& img, const std::vector& params=std::vector()) + std::string ext = bea::Convert::FromJS(args[0], 0); + cv::Mat* img = bea::Convert::FromJS(args[1], 1); + std::vector params = bea::Optional >::FromJS(args, 2, std::vector()); + std::vector vecVal; + cv::imencode(ext, *img, vecVal, params); + node::Buffer *buf = node::Buffer::New(vecVal.size()); + uchar* data = (uchar*) node::Buffer::Data(buf); + memcpy(data, &vecVal[0], vecVal.size()); + + v8::Local globalObj = v8::Context::GetCurrent()->Global(); + v8::Local bufferConstructor = v8::Local::Cast(globalObj->Get(v8::String::New("Buffer"))); + v8::Handle constructorArgs[3] = {buf->handle_, v8::Integer::New(vecVal.size()), v8::Integer::New(0)}; + v8::Local actualBuffer = bufferConstructor->NewInstance(3, constructorArgs); + + return actualBuffer; + METHOD_END(); + } + } diff --git a/src/opencvjs.cpp b/src/opencvjs.cpp index 9dc4393..9d8917f 100644 --- a/src/opencvjs.cpp +++ b/src/opencvjs.cpp @@ -2891,6 +2891,7 @@ namespace opencvjs { obj->exposeMethod("calcBackProject", calcBackProject); obj->exposeMethod("minMaxLoc", minMaxLoc); obj->exposeMethod("cvSmooth", cvSmooth); + obj->exposeMethod("imencode", imencode); obj->exposeMethod("doTick", doTick); obj->exposeMethod("discardMats", discardMats); obj->exposeMethod("fillPoly", fillPoly); diff --git a/src/opencvjs.h b/src/opencvjs.h index 83e2cd2..7cb6974 100644 --- a/src/opencvjs.h +++ b/src/opencvjs.h @@ -6,6 +6,8 @@ #include #include "bea.h" #include "customTypes.h" +#include +#include namespace bea { template<> struct Convert { static bool Is(v8::Handle v) { @@ -574,6 +576,7 @@ namespace opencvjs { static v8::Handle calcBackProject(const v8::Arguments& args); static v8::Handle minMaxLoc(const v8::Arguments& args); static v8::Handle cvSmooth(const v8::Arguments& args); + static v8::Handle imencode(const v8::Arguments& args); static v8::Handle doTick(const v8::Arguments& args); static v8::Handle discardMats(const v8::Arguments& args); static v8::Handle fillPoly(const v8::Arguments& args);