Skip to content
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

Vec operators mean() and cross() throw 'is not a function' #282

Open
fakob opened this issue May 2, 2018 · 4 comments
Open

Vec operators mean() and cross() throw 'is not a function' #282

fakob opened this issue May 2, 2018 · 4 comments

Comments

@fakob
Copy link

fakob commented May 2, 2018

Hi, sorry it is me again.
Thanks for fixing the Mat.mean() issue. Now I wanted to use the vec mean() operator and got the following error:

Uncaught Exception:
TypeError: mat.mean(...).mean is not a function

I then tested out all the other vec operators and found that cross() also throws the same exception.
All other operators worked fine. Am I doing something wrong?
First I was calculating mat.mean() which gave me Vec4 { z: 0, y: 0, x: 0, w: 0 }
The result I then used for the vec operator like so mat.mean().mean().

@justadudewhohacks
Copy link
Owner

Ah yeah, the Vec classes don't implement mean. Yet another fix to be done.

@dnguneratne
Copy link

I'd like to work on this. Any tips on how/where to get started?

@justadudewhohacks
Copy link
Owner

Mean is already implemented for Mat. You could simply take that implementation as an example and adjust it for the Vector classes:

struct MeanWorker : public CatchCvExceptionWorker {
public:
cv::Mat self;
MeanWorker(cv::Mat self) {
this->self = self;
}
cv::Mat mask = cv::noArray().getMat();
cv::Scalar mean;
std::string executeCatchCvExceptionWorker() {
mean = cv::mean(self, mask);
return "";
}
v8::Local<v8::Value> getReturnValue() {
return Vec4::Converter::wrap(cv::Vec4d(mean));
}
bool unwrapOptionalArgs(Nan::NAN_METHOD_ARGS_TYPE info) {
return (
Mat::Converter::optArg(0, &mask, info)
);
}
};

NAN_METHOD(Mat::Mean) {
FF::SyncBinding(
std::make_shared<MatBindings::MeanWorker>(Mat::Converter::unwrap(info.This())),
"Mat::Mean",
info
);
}
NAN_METHOD(Mat::MeanAsync) {
FF::AsyncBinding(
std::make_shared<MatBindings::MeanWorker>(Mat::Converter::unwrap(info.This())),
"Mat::MeanAsync",
info
);
}

@dnguneratne
Copy link

Hey, I started working on this but I need some help.

What does Mat::Converter do in opencv4nodejs/cc/core/Mat.cc? I'm trying to adapt it to Vec.cc.

NAN_METHOD(Mat::Mean) {
	FF::SyncBinding(
		std::make_shared<MatBindings::MeanWorker>(Mat::Converter::unwrap(info.This())),
		"Mat::Mean",
		info
	);
}

So far I created a VecBindings.h file, which I'm not quite sure how to proceed with:

#include "Vec.h"

#ifndef __FF_VECBINDINGS_H__
#define __FF_VECBINDINGS_H__

namespace VecBindings {
  struct MeanWorker : public CatchCvExceptionWorker {
  public:
	  cv::Mat self;
	  MeanWorker(cv::Mat self) {
		  this->self = self;
      return("test");
	  }
  };
}

Then I added the Mean method to Vec.h

class Vec : public Nan::ObjectWrap {
public:
  static NAN_MODULE_INIT(Init);
  static NAN_METHOD(New);
	static NAN_METHOD(NewVec2);
	static NAN_METHOD(NewVec3);
	static NAN_METHOD(NewVec4);
	
	static NAN_METHOD(Mean);

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants