-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathimager.cpp
More file actions
56 lines (45 loc) · 1.25 KB
/
imager.cpp
File metadata and controls
56 lines (45 loc) · 1.25 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
#include <node.h>
#include <opencv2/opencv.hpp>
namespace imager {
void get_orientation(const v8::FunctionCallbackInfo<v8::Value>& args) {
v8::Isolate* isolate = args.GetIsolate();
if(args.Length() < 1) {
isolate->ThrowException(
v8::Exception::TypeError(
v8::String::NewFromUtf8(isolate, "Number of arguments should be 2")
)
);
return;
}
if(!args[0]->IsString()) {
isolate->ThrowException(
v8::Exception::TypeError(
v8::String::NewFromUtf8(isolate, "First argument should be a string")
)
);
return;
}
v8::String::Utf8Value strarg(args[0]);
std::string imagepath(*strarg);
cv::Mat image;
image = cv::imread(imagepath, 1);
if(!image.data) {
isolate->ThrowException(
v8::Exception::TypeError(
v8::String::NewFromUtf8(isolate, "Image is invalid")
)
);
return;
}
cv::Mat edges;
Canny(image, edges, 50, 200, 3);
cv::vector<cv::Vec2f> lines;
HoughLines(edges, lines, 1, CV_PI/180, 100);
int angle = static_cast<int>(std::round(lines[0][1] * 57.2958f));
args.GetReturnValue().Set(v8::Number::New(isolate, angle));
}
void init(v8::Local<v8::Object> exports) {
NODE_SET_METHOD(exports, "get_orientation", get_orientation);
}
NODE_MODULE(imager,init)
}