hzt_asc 1.1.0 → 1.1.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/ask.cc +32 -5
- package/package.json +1 -1
- package/sample/demo.js +17 -5
package/ask.cc
CHANGED
|
@@ -152,6 +152,10 @@ Napi::Value ASK::faceDetectUrl(const Napi::CallbackInfo& info) {
|
|
|
152
152
|
string filePath = info[0].As<Napi::String>().ToString();
|
|
153
153
|
int Width, Height;
|
|
154
154
|
MUInt8* imageData = processFileUrl(filePath.c_str(), Width, Height);
|
|
155
|
+
if (!imageData) {
|
|
156
|
+
Napi::TypeError::New(env, "image download error").ThrowAsJavaScriptException();
|
|
157
|
+
return errorData(env, "image download error"); //Napi::Number::New(info.Env(), -1);
|
|
158
|
+
}
|
|
155
159
|
ASVLOFFSCREEN offscreen = { 0 };
|
|
156
160
|
ColorSpaceConversion(Width, Height, ASVL_PAF_NV21, imageData, offscreen);
|
|
157
161
|
ASF_MultiFaceInfo detectedFaces = { 0 };
|
|
@@ -244,6 +248,10 @@ Napi::Value ASK::faceFeatureExtractUrl(const Napi::CallbackInfo& info) {
|
|
|
244
248
|
|
|
245
249
|
int Width, Height;
|
|
246
250
|
MUInt8* imageData = processFileUrl(filePath.c_str(), Width, Height);
|
|
251
|
+
if (!imageData) {
|
|
252
|
+
Napi::TypeError::New(env, "image download error").ThrowAsJavaScriptException();
|
|
253
|
+
return errorData(env, "image download error"); //Napi::Number::New(info.Env(), -1);
|
|
254
|
+
}
|
|
247
255
|
ASVLOFFSCREEN offscreen = { 0 };
|
|
248
256
|
ColorSpaceConversion(Width, Height, ASVL_PAF_NV21, imageData, offscreen);
|
|
249
257
|
|
|
@@ -562,6 +570,10 @@ Napi::Value ASK::ImageFaceCompareUrl2(const Napi::CallbackInfo& info) {
|
|
|
562
570
|
string filePath = info[0].As<Napi::String>().ToString();
|
|
563
571
|
int Width, Height;
|
|
564
572
|
MUInt8* imageData = processFileUrl(filePath.c_str(), Width, Height);
|
|
573
|
+
if (!imageData) {
|
|
574
|
+
Napi::TypeError::New(env, "image download error").ThrowAsJavaScriptException();
|
|
575
|
+
return errorData(env, "image download error"); //Napi::Number::New(info.Env(), -1);
|
|
576
|
+
}
|
|
565
577
|
ASVLOFFSCREEN offscreen = { 0 };
|
|
566
578
|
ColorSpaceConversion(Width, Height, ASVL_PAF_NV21, imageData, offscreen);
|
|
567
579
|
|
|
@@ -589,6 +601,10 @@ Napi::Value ASK::ImageFaceCompareUrl(const Napi::CallbackInfo& info) {
|
|
|
589
601
|
string filePath = info[0].As<Napi::String>().ToString();
|
|
590
602
|
int Width, Height;
|
|
591
603
|
MUInt8* imageData = processFileUrl(filePath.c_str(), Width, Height);
|
|
604
|
+
if (!imageData) {
|
|
605
|
+
Napi::TypeError::New(env, "image download error").ThrowAsJavaScriptException();
|
|
606
|
+
return errorData(env, "image download error"); //Napi::Number::New(info.Env(), -1);
|
|
607
|
+
}
|
|
592
608
|
ASVLOFFSCREEN offscreen = { 0 };
|
|
593
609
|
ColorSpaceConversion(Width, Height, ASVL_PAF_NV21, imageData, offscreen);
|
|
594
610
|
|
|
@@ -762,7 +778,7 @@ size_t write_data(char *ptr, size_t size, size_t nmemb, void *userdata)
|
|
|
762
778
|
//function to retrieve the image as cv::Mat data type
|
|
763
779
|
cv::Mat curlImg(const char *img_url, int timeout=100000)
|
|
764
780
|
{
|
|
765
|
-
cout<<img_url<<endl;
|
|
781
|
+
//cout<<img_url<<endl;
|
|
766
782
|
vector<uchar> stream;
|
|
767
783
|
CURL *curl = curl_easy_init();
|
|
768
784
|
curl_easy_setopt(curl, CURLOPT_URL, img_url); //the img url
|
|
@@ -771,8 +787,14 @@ cv::Mat curlImg(const char *img_url, int timeout=100000)
|
|
|
771
787
|
curl_easy_setopt(curl, CURLOPT_TIMEOUT, timeout); // timeout if curl_easy hangs,
|
|
772
788
|
curl_easy_setopt(curl, CURLOPT_FOLLOWLOCATION, 1); //重定向一次
|
|
773
789
|
CURLcode res = curl_easy_perform(curl); // start curl
|
|
790
|
+
|
|
774
791
|
curl_easy_cleanup(curl); // cleanup
|
|
775
|
-
|
|
792
|
+
if (res != CURLE_OK) {
|
|
793
|
+
cout << "curl errcode=" << res << img_url <<endl;
|
|
794
|
+
cv::Mat dest(0, 0, 1);
|
|
795
|
+
return dest;
|
|
796
|
+
}
|
|
797
|
+
cout<<res<<" xxxx " << stream.size() << img_url << stream.max_size()<<endl;
|
|
776
798
|
return imdecode(stream, -1); // 'keep-as-is'
|
|
777
799
|
}
|
|
778
800
|
|
|
@@ -792,6 +814,10 @@ void modifyImageFormat(cv::Mat& out, cv::Mat& in, int channel)
|
|
|
792
814
|
MUInt8* ASK::processFileUrl(const char* url, int& picWidth, int& picHeight) {
|
|
793
815
|
cv::Mat src = curlImg(url);
|
|
794
816
|
int Width = src.cols;
|
|
817
|
+
if (Width == 0) {
|
|
818
|
+
src.release();
|
|
819
|
+
return NULL;
|
|
820
|
+
}
|
|
795
821
|
int Height = src.rows;
|
|
796
822
|
int depth = src.depth();
|
|
797
823
|
int channel = src.channels();
|
|
@@ -799,12 +825,13 @@ MUInt8* ASK::processFileUrl(const char* url, int& picWidth, int& picHeight) {
|
|
|
799
825
|
cout << "dims: " << src.dims << endl;
|
|
800
826
|
cout << "channels: " << channel << endl;
|
|
801
827
|
cout << "depth: " << depth << endl;
|
|
802
|
-
|
|
828
|
+
//src.reshape(channels, rows)
|
|
829
|
+
//src.assignTo(mid, depth)
|
|
803
830
|
int wScore = Width % 4;
|
|
804
831
|
int hScore = Height % 2;
|
|
805
832
|
cv::Mat dest;
|
|
806
833
|
if (wScore != 0 || hScore != 0) {
|
|
807
|
-
cout << "processFileUrl ou:" <<endl;
|
|
834
|
+
//cout << "processFileUrl ou:" <<endl;
|
|
808
835
|
Width -= wScore;
|
|
809
836
|
Height -= hScore;
|
|
810
837
|
cv::Mat dst;
|
|
@@ -820,7 +847,7 @@ MUInt8* ASK::processFileUrl(const char* url, int& picWidth, int& picHeight) {
|
|
|
820
847
|
|
|
821
848
|
dst.release();
|
|
822
849
|
} else {
|
|
823
|
-
cout << "processFileUrl ji:" <<endl;
|
|
850
|
+
//cout << "processFileUrl ji:" <<endl;
|
|
824
851
|
if (depth != 0) { //bit数仅支持8
|
|
825
852
|
cv::Mat mid;
|
|
826
853
|
modifyImageFormat(mid, src, channel);
|
package/package.json
CHANGED
package/sample/demo.js
CHANGED
|
@@ -17,14 +17,26 @@ let start = Date.now();
|
|
|
17
17
|
let ask = new addon.ASK(APPID, SDKKEY, ACTIVEKEY);
|
|
18
18
|
//let ask2 = new addon.ASK(APPID, SDKKEY, ACTIVEKEY);
|
|
19
19
|
printMem()
|
|
20
|
-
let xx2 = ask.FaceDetectUrl("http://image.haizitong.com/cc123be3667143e3af5c53a5906c6b42");
|
|
21
|
-
console.log("init end", xx2, Date.now() - start);
|
|
20
|
+
// let xx2 = ask.FaceDetectUrl("http://image.haizitong.com/cc123be3667143e3af5c53a5906c6b42");
|
|
21
|
+
// console.log("init end", xx2, Date.now() - start);
|
|
22
22
|
|
|
23
|
-
let xx = ask.FaceDetectUrl("http://upload-file.haizitong.com/api/getFile/119c44a5-193f-4953-b59c-c1e55cd29f1a")
|
|
23
|
+
//let xx = ask.FaceDetectUrl("http://upload-file.haizitong.com/api/getFile/119c44a5-193f-4953-b59c-c1e55cd29f1a")
|
|
24
24
|
//let xx = ask.FaceDetectUrl("https://min.haizitong.com/2/ali/i/fbad726e022742a78a2666580a9a0f0f139317")
|
|
25
|
-
//
|
|
25
|
+
//http://upload-file.haizitong.com/api/getCacheFile/62e23c73991e856c4411bbe4
|
|
26
|
+
//let xx = ask.FaceDetectUrl("https://upload-file.haizitong.com/api/getCacheFile/62e23c73991e856c4411bbe4")
|
|
27
|
+
|
|
28
|
+
const urls = [
|
|
29
|
+
"http://image.haizitong.com/cc123be3667143e3af5c53a5906c6b42",
|
|
30
|
+
"http://upload-file.haizitong.com/api/getFile/119c44a5-193f-4953-b59c-c1e55cd29f1a",
|
|
31
|
+
"https://min.haizitong.com/2/ali/i/fbad726e022742a78a2666580a9a0f0f139317",
|
|
32
|
+
"http://upload-file.haizitong.com/api/getCacheFile/62e23c73991e856c4411bbe4"
|
|
33
|
+
]
|
|
34
|
+
for(let o of urls) {
|
|
35
|
+
let xx2 = ask.FaceDetectUrl(o);
|
|
36
|
+
console.log("init end", xx2, Date.now() - start);
|
|
37
|
+
}
|
|
26
38
|
|
|
27
|
-
console.log("init end", xx, Date.now() - start);
|
|
39
|
+
//console.log("init end", xx, Date.now() - start);
|
|
28
40
|
|
|
29
41
|
// for(let i = 0; i < 10000; ++i) {
|
|
30
42
|
// let num = ask.FaceFeatureExtractUrl("http://min.haizitong.com/2/ali/i/a5f91d52783d49989777e8b82b545e2c");
|