Skip to content

Added imencode #8

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion bea/cv.bea
Original file line number Diff line number Diff line change
Expand Up @@ -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<cv::Rect> detectObject(const std::string& cascadeName, int imageWidth, int imageHeight)
@manual std::vector<cv::Rect> detectObject(const std::string& cascadeName, int imageWidth, int imageHeight)
@manual node::Buffer imencode(const std::string& ext, const Mat& img, const std::vector<int>& params=std::vector<int>())
2 changes: 2 additions & 0 deletions bea/opencv.bea
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,8 @@
\#include <highgui.h>
\#include "bea.h"
\#include "customTypes.h"
\#include <node.h>
\#include <node_buffer.h>

#C++ code added to the cpp file
@cpp
Expand Down
21 changes: 21 additions & 0 deletions src/opencv_manual.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -164,4 +164,25 @@ namespace opencvjs {
METHOD_END();
}

v8::Handle<v8::Value> JOpenCV::imencode(const v8::Arguments& args) {
METHOD_BEGIN(2);
//node::Buffer imencode(const std::string& ext, const Mat& img, const std::vector<int>& params=std::vector<int>())
std::string ext = bea::Convert<std::string>::FromJS(args[0], 0);
cv::Mat* img = bea::Convert<cv::Mat*>::FromJS(args[1], 1);
std::vector<int> params = bea::Optional<std::vector<int> >::FromJS(args, 2, std::vector<int>());
std::vector<uchar> 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<v8::Object> globalObj = v8::Context::GetCurrent()->Global();
v8::Local<v8::Function> bufferConstructor = v8::Local<v8::Function>::Cast(globalObj->Get(v8::String::New("Buffer")));
v8::Handle<v8::Value> constructorArgs[3] = {buf->handle_, v8::Integer::New(vecVal.size()), v8::Integer::New(0)};
v8::Local<v8::Object> actualBuffer = bufferConstructor->NewInstance(3, constructorArgs);

return actualBuffer;
METHOD_END();
}

}
1 change: 1 addition & 0 deletions src/opencvjs.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
3 changes: 3 additions & 0 deletions src/opencvjs.h
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@
#include <highgui.h>
#include "bea.h"
#include "customTypes.h"
#include <node.h>
#include <node_buffer.h>
namespace bea {
template<> struct Convert<cv::TermCriteria> {
static bool Is(v8::Handle<v8::Value> v) {
Expand Down Expand Up @@ -574,6 +576,7 @@ namespace opencvjs {
static v8::Handle<v8::Value> calcBackProject(const v8::Arguments& args);
static v8::Handle<v8::Value> minMaxLoc(const v8::Arguments& args);
static v8::Handle<v8::Value> cvSmooth(const v8::Arguments& args);
static v8::Handle<v8::Value> imencode(const v8::Arguments& args);
static v8::Handle<v8::Value> doTick(const v8::Arguments& args);
static v8::Handle<v8::Value> discardMats(const v8::Arguments& args);
static v8::Handle<v8::Value> fillPoly(const v8::Arguments& args);
Expand Down