Merge pull request #269 from emanuelandrada/master

Fixes error trying to load an image that is not an image.
This commit is contained in:
Peter Braden 2015-07-24 09:35:25 +02:00
commit 757de05823
2 changed files with 35 additions and 32 deletions

View File

@ -54,17 +54,21 @@ class AsyncDetectMultiScale : public NanAsyncWorker {
~AsyncDetectMultiScale() {}
void Execute () {
std::vector<cv::Rect> objects;
try {
std::vector<cv::Rect> objects;
cv::Mat gray;
cv::Mat gray;
if(this->im->mat.channels() != 1)
cvtColor(this->im->mat, gray, CV_BGR2GRAY);
equalizeHist( gray, gray);
this->cc->cc.detectMultiScale(gray, objects, this->scale, this->neighbors, 0 | CV_HAAR_SCALE_IMAGE, cv::Size(this->minw, this->minh));
res = objects;
if(this->im->mat.channels() != 1) {
cvtColor(this->im->mat, gray, CV_BGR2GRAY);
}
equalizeHist( gray, gray);
this->cc->cc.detectMultiScale(gray, objects, this->scale, this->neighbors, 0 | CV_HAAR_SCALE_IMAGE, cv::Size(this->minw, this->minh));
res = objects;
}
catch( cv::Exception& e ){
SetErrorMessage(e.what());
}
}
void HandleOKCallback () {

View File

@ -18,20 +18,20 @@ OpenCV::Init(Handle<Object> target) {
NAN_METHOD(OpenCV::ReadImage) {
NanEscapableScope();
REQ_FUN_ARG(1, cb);
Local<Value> argv[2];
argv[0] = NanNull();
Local<Object> im_h = NanNew(Matrix::constructor)->GetFunction()->NewInstance();
Matrix *img = ObjectWrap::Unwrap<Matrix>(im_h);
argv[1] = im_h;
try{
Local<Object> im_h = NanNew(Matrix::constructor)->GetFunction()->NewInstance();
Matrix *img = ObjectWrap::Unwrap<Matrix>(im_h);
cv::Mat mat;
REQ_FUN_ARG(1, cb);
Local<Value> argv[2];
argv[0] = NanNull();
argv[1] = im_h;
if (args[0]->IsNumber() && args[1]->IsNumber()){
int width, height;
@ -58,19 +58,18 @@ NAN_METHOD(OpenCV::ReadImage) {
img->mat = mat;
TryCatch try_catch;
cb->Call(NanGetCurrentContext()->Global(), 2, argv);
if (try_catch.HasCaught()) {
FatalException(try_catch);
}
NanReturnUndefined();
} catch( cv::Exception& e ){
const char* err_msg = e.what();
NanThrowError(err_msg);
NanReturnUndefined();
argv[0] = NanError(e.what());
argv[1] = NanNull();
}
TryCatch try_catch;
cb->Call(NanGetCurrentContext()->Global(), 2, argv);
if (try_catch.HasCaught()) {
FatalException(try_catch);
}
NanReturnUndefined();
};