Skip to content

Commit

Permalink
Merge pull request justadudewhohacks#248 from justadudewhohacks/openc…
Browse files Browse the repository at this point in the history
…v-exception-handling

Opencv exception handling
  • Loading branch information
justadudewhohacks authored Apr 9, 2018
2 parents 90260f3 + 546ec70 commit 2bede49
Show file tree
Hide file tree
Showing 44 changed files with 803 additions and 920 deletions.
19 changes: 19 additions & 0 deletions cc/CatchCvExceptionWorker.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
#include "Workers.h"

#ifndef __FF_CATCHCVEXCEPTIONWORKER_H__
#define __FF_CATCHCVEXCEPTIONWORKER_H__

struct CatchCvExceptionWorker : public SimpleWorker {
public:
std::string execute() {
try {
return executeCatchCvExceptionWorker();
} catch (std::exception e) {
return std::string(e.what());
}
}

virtual std::string executeCatchCvExceptionWorker() = 0;
};

#endif
84 changes: 42 additions & 42 deletions cc/core/Mat.cc
Original file line number Diff line number Diff line change
Expand Up @@ -280,7 +280,7 @@ NAN_METHOD(Mat::Set) {
}
}

struct Mat::PushBackWorker : public SimpleWorker {
struct Mat::PushBackWorker : public CatchCvExceptionWorker {
public:
cv::Mat self;
PushBackWorker(cv::Mat self) {
Expand All @@ -289,7 +289,7 @@ struct Mat::PushBackWorker : public SimpleWorker {

cv::Mat mat;

const char* execute() {
std::string executeCatchCvExceptionWorker() {
self.push_back(mat);
return "";
}
Expand Down Expand Up @@ -317,7 +317,7 @@ NAN_METHOD(Mat::PushBackAsync) {
}


struct Mat::PopBackWorker : public SimpleWorker {
struct Mat::PopBackWorker : public CatchCvExceptionWorker {
public:
cv::Mat self;
PopBackWorker(cv::Mat self) {
Expand All @@ -326,7 +326,7 @@ struct Mat::PopBackWorker : public SimpleWorker {

int num = 1;

const char* execute() {
std::string executeCatchCvExceptionWorker() {
self.pop_back(num);
return "";
}
Expand All @@ -353,7 +353,7 @@ NAN_METHOD(Mat::PopBackAsync) {
FF_WORKER_ASYNC("Mat::PopBackAsync", PopBackWorker, worker);
}

struct Mat::GetDataWorker : SimpleWorker {
struct Mat::GetDataWorker : CatchCvExceptionWorker {
public:
cv::Mat mat;

Expand All @@ -364,7 +364,7 @@ struct Mat::GetDataWorker : SimpleWorker {
size_t size;
char *data;

const char* execute() {
std::string executeCatchCvExceptionWorker() {
size = mat.rows * mat.cols * mat.elemSize();
data = static_cast<char *>(malloc(size));
memcpy(data, mat.data, size);
Expand Down Expand Up @@ -408,7 +408,7 @@ NAN_METHOD(Mat::GetRegion) {
FF_RETURN(jsRegion);
}

struct Mat::CopyWorker : public SimpleWorker {
struct Mat::CopyWorker : public CatchCvExceptionWorker {
public:
cv::Mat self;
CopyWorker(cv::Mat self) {
Expand All @@ -418,7 +418,7 @@ struct Mat::CopyWorker : public SimpleWorker {
cv::Mat dst;
cv::Mat mask = cv::noArray().getMat();

const char* execute() {
std::string executeCatchCvExceptionWorker() {
self.copyTo(dst, mask);
return "";
}
Expand Down Expand Up @@ -476,7 +476,7 @@ NAN_METHOD(Mat::CopyToAsync) {
}


struct Mat::ConvertToWorker : public SimpleWorker {
struct Mat::ConvertToWorker : public CatchCvExceptionWorker {
public:
cv::Mat self;
ConvertToWorker(cv::Mat self) {
Expand All @@ -489,7 +489,7 @@ struct Mat::ConvertToWorker : public SimpleWorker {

cv::Mat dst;

const char* execute() {
std::string executeCatchCvExceptionWorker() {
self.convertTo(dst, rtype, alpha, beta);
return "";
}
Expand Down Expand Up @@ -586,7 +586,7 @@ NAN_METHOD(Mat::Normalize) {
FF_RETURN(jsMat);
}

struct Mat::SplitChannelsWorker : public SimpleWorker {
struct Mat::SplitChannelsWorker : public CatchCvExceptionWorker {
public:
cv::Mat self;
SplitChannelsWorker(cv::Mat self) {
Expand All @@ -596,7 +596,7 @@ struct Mat::SplitChannelsWorker : public SimpleWorker {

std::vector<cv::Mat> mv;

const char* execute() {
std::string executeCatchCvExceptionWorker() {
cv::split(self, mv);
return "";
}
Expand All @@ -617,7 +617,7 @@ NAN_METHOD(Mat::SplitChannelsAsync) {
FF_WORKER_ASYNC("Mat::SplitChannelsAsync", SplitChannelsWorker, worker);
}

struct Mat::AddWeightedWorker : public SimpleWorker {
struct Mat::AddWeightedWorker : public CatchCvExceptionWorker {
public:
cv::Mat self;
AddWeightedWorker(cv::Mat self) {
Expand All @@ -632,7 +632,7 @@ struct Mat::AddWeightedWorker : public SimpleWorker {

cv::Mat dst;

const char* execute() {
std::string executeCatchCvExceptionWorker() {
cv::addWeighted(self, alpha, src2, beta, gamma, dst, dtype);
return "";
}
Expand Down Expand Up @@ -669,7 +669,7 @@ NAN_METHOD(Mat::AddWeightedAsync) {
}


struct Mat::MinMaxLocWorker : public SimpleWorker {
struct Mat::MinMaxLocWorker : public CatchCvExceptionWorker {
public:
cv::Mat self;
MinMaxLocWorker(cv::Mat self) {
Expand All @@ -680,7 +680,7 @@ struct Mat::MinMaxLocWorker : public SimpleWorker {
cv::Point2i minLoc, maxLoc;
cv::Mat mask = cv::noArray().getMat();

const char* execute() {
std::string executeCatchCvExceptionWorker() {
cv::minMaxLoc(self, &minVal, &maxVal, &minLoc, &maxLoc, mask);
return "";
}
Expand Down Expand Up @@ -710,7 +710,7 @@ NAN_METHOD(Mat::MinMaxLocAsync) {
FF_WORKER_ASYNC("Mat::MinMaxLocAsync", MinMaxLocWorker, worker);
}

struct Mat::FindNonZeroWorker : public SimpleWorker {
struct Mat::FindNonZeroWorker : public CatchCvExceptionWorker {
public:
cv::Mat self;
FindNonZeroWorker(cv::Mat self) {
Expand All @@ -719,7 +719,7 @@ struct Mat::FindNonZeroWorker : public SimpleWorker {

std::vector<cv::Point> idx;

const char* execute() {
std::string executeCatchCvExceptionWorker() {
cv::findNonZero(self, idx);
return "";
}
Expand All @@ -740,7 +740,7 @@ NAN_METHOD(Mat::FindNonZeroAsync) {
FF_WORKER_ASYNC("Mat::FindNonZeroAsync", FindNonZeroWorker, worker);
}

struct Mat::CountNonZeroWorker : public SimpleWorker {
struct Mat::CountNonZeroWorker : public CatchCvExceptionWorker {
public:
cv::Mat self;
CountNonZeroWorker(cv::Mat self) {
Expand All @@ -749,7 +749,7 @@ struct Mat::CountNonZeroWorker : public SimpleWorker {

int num;

const char* execute() {
std::string executeCatchCvExceptionWorker() {
num = cv::countNonZero(self);
return "";
}
Expand All @@ -770,7 +770,7 @@ NAN_METHOD(Mat::CountNonZeroAsync) {
FF_WORKER_ASYNC("Mat::CountNonZeroAsync", CountNonZeroWorker, worker);
}

struct Mat::PadToSquareWorker : public SimpleWorker {
struct Mat::PadToSquareWorker : public CatchCvExceptionWorker {
public:
cv::Mat self;
PadToSquareWorker(cv::Mat self) {
Expand All @@ -779,7 +779,7 @@ struct Mat::PadToSquareWorker : public SimpleWorker {

cv::Vec3d fillVec = cv::Vec3d();
cv::Mat out;
const char* execute() {
std::string executeCatchCvExceptionWorker() {
int maxDim = (std::max)(self.cols, self.rows);
out = cv::Mat(maxDim, maxDim, self.type(), (cv::Vec3b)fillVec);

Expand Down Expand Up @@ -816,7 +816,7 @@ NAN_METHOD(Mat::PadToSquareAsync) {
FF_WORKER_ASYNC("Mat::PadToSquareAsync", PadToSquareWorker, worker);
}

struct Mat::DTWorker : public SimpleWorker {
struct Mat::DTWorker : public CatchCvExceptionWorker {
public:
cv::Mat mat;
bool isInverse;
Expand All @@ -843,7 +843,7 @@ struct Mat::DCTWorker : public DTWorker {
DCTWorker(cv::Mat mat, bool isInverse = false) : DTWorker(mat, isInverse) {
}

const char* execute() {
std::string executeCatchCvExceptionWorker() {
if (isInverse) {
cv::idct(mat, dst, flags);
}
Expand All @@ -864,7 +864,7 @@ struct Mat::DFTWorker : public DTWorker {

int nonzeroRows = 0;

const char* execute() {
std::string executeCatchCvExceptionWorker() {
if (isInverse) {
cv::idft(mat, dst, flags, nonzeroRows);
}
Expand Down Expand Up @@ -938,7 +938,7 @@ NAN_METHOD(Mat::IdftAsync) {
FF_WORKER_ASYNC("Mat::IdftAsync", DFTWorker, worker);
}

struct Mat::MulSpectrumsWorker {
struct Mat::MulSpectrumsWorker : public CatchCvExceptionWorker {
public:
cv::Mat mat;
bool isInverse;
Expand All @@ -953,7 +953,7 @@ struct Mat::MulSpectrumsWorker {

cv::Mat dst;

const char* execute() {
std::string executeCatchCvExceptionWorker() {
int flags = (dftRows ? cv::DFT_ROWS : 0);
cv::mulSpectrums(mat, mat2, dst, flags, conjB);
return "";
Expand Down Expand Up @@ -999,7 +999,7 @@ NAN_METHOD(Mat::MulSpectrumsAsync) {
}


struct Mat::TransformWorker : public SimpleWorker {
struct Mat::TransformWorker : public CatchCvExceptionWorker {
public:
cv::Mat self;
TransformWorker(cv::Mat self) {
Expand All @@ -1010,7 +1010,7 @@ struct Mat::TransformWorker : public SimpleWorker {

cv::Mat dst;

const char* execute() {
std::string executeCatchCvExceptionWorker() {
cv::transform(self, dst, m);
return "";
}
Expand Down Expand Up @@ -1042,7 +1042,7 @@ struct Mat::PerspectiveTransformWorker : public Mat::TransformWorker {
PerspectiveTransformWorker(cv::Mat self) : Mat::TransformWorker(self) {
}

const char* execute() {
std::string executeCatchCvExceptionWorker() {
cv::perspectiveTransform(self, dst, m);
return "";
}
Expand All @@ -1060,7 +1060,7 @@ NAN_METHOD(Mat::PerspectiveTransformAsync) {
}


struct Mat::OpWithCodeWorker : public SimpleWorker {
struct Mat::OpWithCodeWorker : public CatchCvExceptionWorker {
public:
cv::Mat self;
OpWithCodeWorker(cv::Mat self) {
Expand All @@ -1071,7 +1071,7 @@ struct Mat::OpWithCodeWorker : public SimpleWorker {

cv::Mat dst;

const char* execute() {
std::string executeCatchCvExceptionWorker() {
cv::flip(self, dst, code);
return "";
}
Expand All @@ -1092,7 +1092,7 @@ struct Mat::FlipWorker : public OpWithCodeWorker {
FlipWorker(cv::Mat self) : OpWithCodeWorker(self) {
}

const char* execute() {
std::string executeCatchCvExceptionWorker() {
cv::flip(self, dst, code);
return "";
}
Expand All @@ -1109,7 +1109,7 @@ NAN_METHOD(Mat::FlipAsync) {
FF_WORKER_ASYNC("Mat::FlipAsync", FlipWorker, worker);
}

struct Mat::SumWorker : public SimpleWorker {
struct Mat::SumWorker : public CatchCvExceptionWorker {
public:
cv::Mat self;
SumWorker(cv::Mat self) {
Expand All @@ -1118,7 +1118,7 @@ struct Mat::SumWorker : public SimpleWorker {

cv::Scalar sum;

const char* execute() {
std::string executeCatchCvExceptionWorker() {
sum = cv::sum(self);
return "";
}
Expand Down Expand Up @@ -1151,7 +1151,7 @@ NAN_METHOD(Mat::SumAsync) {
}


struct Mat::ConvertScaleAbsWorker : public SimpleWorker {
struct Mat::ConvertScaleAbsWorker : public CatchCvExceptionWorker {
public:
cv::Mat self;
ConvertScaleAbsWorker(cv::Mat self) {
Expand All @@ -1163,7 +1163,7 @@ struct Mat::ConvertScaleAbsWorker : public SimpleWorker {

cv::Mat dst;

const char* execute() {
std::string executeCatchCvExceptionWorker() {
cv::convertScaleAbs(self, dst, alpha, beta);
return "";
}
Expand Down Expand Up @@ -1204,7 +1204,7 @@ NAN_METHOD(Mat::ConvertScaleAbsAsync) {
}


struct Mat::GoodFeaturesToTrackWorker : public SimpleWorker {
struct Mat::GoodFeaturesToTrackWorker : public CatchCvExceptionWorker {
public:
cv::Mat self;
GoodFeaturesToTrackWorker(cv::Mat self) {
Expand Down Expand Up @@ -1272,7 +1272,7 @@ struct Mat::GoodFeaturesToTrackWorker : public SimpleWorker {
}


const char* execute() {
std::string executeCatchCvExceptionWorker() {
#if CV_VERSION_MINOR >= 4
cv::goodFeaturesToTrack(
self, corners,
Expand Down Expand Up @@ -1305,7 +1305,7 @@ NAN_METHOD(Mat::GoodFeaturesToTrackAsync) {
FF_WORKER_ASYNC("Mat::GoodFeaturesToTrackAsync", GoodFeaturesToTrackWorker, worker);
}

struct Mat::MeanStdDevWorker : public SimpleWorker {
struct Mat::MeanStdDevWorker : public CatchCvExceptionWorker {
public:
cv::Mat self;
MeanStdDevWorker(cv::Mat self) {
Expand All @@ -1317,7 +1317,7 @@ struct Mat::MeanStdDevWorker : public SimpleWorker {
cv::Mat mean;
cv::Mat stddev;

const char* execute() {
std::string executeCatchCvExceptionWorker() {
cv::meanStdDev(self, mean, stddev, mask);
return "";
}
Expand Down Expand Up @@ -1353,7 +1353,7 @@ struct Mat::RotateWorker : public OpWithCodeWorker {
RotateWorker(cv::Mat self) : OpWithCodeWorker(self) {
}

const char* execute() {
std::string executeCatchCvExceptionWorker() {
cv::rotate(self, dst, code);
return "";
}
Expand Down
Loading

0 comments on commit 2bede49

Please sign in to comment.