hzt_asc 1.1.2 → 1.1.4

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.
Files changed (2) hide show
  1. package/ask.cc +29 -48
  2. package/package.json +1 -1
package/ask.cc CHANGED
@@ -149,19 +149,22 @@ Napi::Value ASK::faceDetectUrl(const Napi::CallbackInfo& info) {
149
149
  Napi::TypeError::New(env, "input expected").ThrowAsJavaScriptException();
150
150
  return errorData(env, "input expected"); //Napi::Number::New(info.Env(), -1);
151
151
  }
152
+ Napi::Object obj = Napi::Object::New(env);
152
153
  string filePath = info[0].As<Napi::String>().ToString();
153
154
  int Width, Height;
154
155
  MUInt8* imageData = processFileUrl(filePath.c_str(), Width, Height);
155
156
  if (!imageData) {
156
- Napi::TypeError::New(env, "image download error").ThrowAsJavaScriptException();
157
- return errorData(env, "image download error"); //Napi::Number::New(info.Env(), -1);
157
+ // Napi::TypeError::New(env, "image download error").ThrowAsJavaScriptException();
158
+ // return errorData(env, "image download error");
159
+ obj.Set(Napi::String::New(env, "faceNum"), 0);
160
+ return obj;
158
161
  }
159
162
  ASVLOFFSCREEN offscreen = { 0 };
160
163
  ColorSpaceConversion(Width, Height, ASVL_PAF_NV21, imageData, offscreen);
161
164
  ASF_MultiFaceInfo detectedFaces = { 0 };
162
165
  MRESULT res = ASFDetectFacesEx(this->handle, &offscreen, &detectedFaces);
163
166
 
164
- Napi::Object obj = Napi::Object::New(env);
167
+
165
168
  obj.Set(Napi::String::New(env, "faceNum"), detectedFaces.faceNum);
166
169
  Napi::Array list = Napi::Array::New(env, detectedFaces.faceNum);
167
170
  for(int i = 0; i < detectedFaces.faceNum; ++i) {
@@ -245,12 +248,14 @@ Napi::Value ASK::faceFeatureExtractUrl(const Napi::CallbackInfo& info) {
245
248
  return errorData(env, "input expected"); //Napi::Number::New(info.Env(), -1);
246
249
  }
247
250
  string filePath = info[0].As<Napi::String>().ToString();
248
-
251
+ Napi::Object obj = Napi::Object::New(env);
249
252
  int Width, Height;
250
253
  MUInt8* imageData = processFileUrl(filePath.c_str(), Width, Height);
251
254
  if (!imageData) {
252
- Napi::TypeError::New(env, "image download error").ThrowAsJavaScriptException();
253
- return errorData(env, "image download error"); //Napi::Number::New(info.Env(), -1);
255
+ // Napi::TypeError::New(env, "image download error").ThrowAsJavaScriptException();
256
+ // return errorData(env, "image download error"); //Napi::Number::New(info.Env(), -1);
257
+ obj.Set(Napi::String::New(env, "faceNum"), 0);
258
+ return obj;
254
259
  }
255
260
  ASVLOFFSCREEN offscreen = { 0 };
256
261
  ColorSpaceConversion(Width, Height, ASVL_PAF_NV21, imageData, offscreen);
@@ -258,7 +263,7 @@ Napi::Value ASK::faceFeatureExtractUrl(const Napi::CallbackInfo& info) {
258
263
  ASF_MultiFaceInfo detectedFaces = { 0 };
259
264
  MRESULT res = ASFDetectFacesEx(this->handle, &offscreen, &detectedFaces);
260
265
 
261
- Napi::Object obj = Napi::Object::New(env);
266
+
262
267
  obj.Set(Napi::String::New(env, "faceNum"), detectedFaces.faceNum);
263
268
  if (0 == detectedFaces.faceNum) {
264
269
  SafeFree(imageData);
@@ -567,19 +572,22 @@ Napi::Value ASK::ImageFaceCompareUrl2(const Napi::CallbackInfo& info) {
567
572
  Napi::TypeError::New(env, "input expected").ThrowAsJavaScriptException();
568
573
  return errorData(env, "input expected");
569
574
  }
575
+ Napi::Object obj = Napi::Object::New(env);
570
576
  string filePath = info[0].As<Napi::String>().ToString();
571
577
  int Width, Height;
572
578
  MUInt8* imageData = processFileUrl(filePath.c_str(), Width, Height);
573
579
  if (!imageData) {
574
- Napi::TypeError::New(env, "image download error").ThrowAsJavaScriptException();
575
- return errorData(env, "image download error"); //Napi::Number::New(info.Env(), -1);
580
+ // Napi::TypeError::New(env, "image download error").ThrowAsJavaScriptException();
581
+ // return errorData(env, "image download error"); //Napi::Number::New(info.Env(), -1);
582
+ obj.Set(Napi::String::New(env, "faceNum"), 0);
583
+ return obj;
576
584
  }
577
585
  ASVLOFFSCREEN offscreen = { 0 };
578
586
  ColorSpaceConversion(Width, Height, ASVL_PAF_NV21, imageData, offscreen);
579
587
 
580
588
  ASF_MultiFaceInfo detectedFaces = { 0 };
581
589
  MRESULT res = ASFDetectFacesEx(this->handle, &offscreen, &detectedFaces);
582
- Napi::Object obj = Napi::Object::New(env);
590
+
583
591
  obj.Set(Napi::String::New(env, "faceNum"), detectedFaces.faceNum);
584
592
  if (0 == detectedFaces.faceNum) {
585
593
  SafeFree(imageData);
@@ -598,19 +606,22 @@ Napi::Value ASK::ImageFaceCompareUrl(const Napi::CallbackInfo& info) {
598
606
  Napi::TypeError::New(env, "input expected").ThrowAsJavaScriptException();
599
607
  return errorData(env, "input expected");
600
608
  }
609
+ Napi::Object obj = Napi::Object::New(env);
601
610
  string filePath = info[0].As<Napi::String>().ToString();
602
611
  int Width, Height;
603
612
  MUInt8* imageData = processFileUrl(filePath.c_str(), Width, Height);
604
613
  if (!imageData) {
605
- Napi::TypeError::New(env, "image download error").ThrowAsJavaScriptException();
606
- return errorData(env, "image download error"); //Napi::Number::New(info.Env(), -1);
614
+ // Napi::TypeError::New(env, "image download error").ThrowAsJavaScriptException();
615
+ // return errorData(env, "image download error"); //Napi::Number::New(info.Env(), -1);
616
+ obj.Set(Napi::String::New(env, "faceNum"), 0);
617
+ return obj;
607
618
  }
608
619
  ASVLOFFSCREEN offscreen = { 0 };
609
620
  ColorSpaceConversion(Width, Height, ASVL_PAF_NV21, imageData, offscreen);
610
621
 
611
622
  ASF_MultiFaceInfo detectedFaces = { 0 };
612
623
  MRESULT res = ASFDetectFacesEx(this->handle, &offscreen, &detectedFaces);
613
- Napi::Object obj = Napi::Object::New(env);
624
+
614
625
  obj.Set(Napi::String::New(env, "faceNum"), detectedFaces.faceNum);
615
626
  if (0 == detectedFaces.faceNum) {
616
627
  SafeFree(imageData);
@@ -779,6 +790,7 @@ size_t write_data(char *ptr, size_t size, size_t nmemb, void *userdata)
779
790
  cv::Mat curlImg(const char *img_url, int timeout=100000)
780
791
  {
781
792
  //cout<<img_url<<endl;
793
+ char *pCaPath = "/opt/ssl_csr/*.haizitong.com.chained.crt";
782
794
  vector<uchar> stream;
783
795
  CURL *curl = curl_easy_init();
784
796
  curl_easy_setopt(curl, CURLOPT_URL, img_url); //the img url
@@ -786,6 +798,10 @@ cv::Mat curlImg(const char *img_url, int timeout=100000)
786
798
  curl_easy_setopt(curl, CURLOPT_WRITEDATA, &stream); // pass the stream ptr to the writefunction
787
799
  curl_easy_setopt(curl, CURLOPT_TIMEOUT, timeout); // timeout if curl_easy hangs,
788
800
  curl_easy_setopt(curl, CURLOPT_FOLLOWLOCATION, 1); //重定向一次
801
+
802
+ curl_easy_setopt(curl, CURLOPT_SSL_VERIFYPEER, 1L);
803
+ curl_easy_setopt(curl, CURLOPT_SSL_VERIFYHOST, 2L);
804
+ curl_easy_setopt(curl, CURLOPT_CAINFO, pCaPath);
789
805
  CURLcode res = curl_easy_perform(curl); // start curl
790
806
 
791
807
  curl_easy_cleanup(curl); // cleanup
@@ -831,7 +847,6 @@ MUInt8* ASK::processFileUrl(const char* url, int& picWidth, int& picHeight) {
831
847
  int hScore = Height % 2;
832
848
  cv::Mat dest;
833
849
  if (wScore != 0 || hScore != 0) {
834
- //cout << "processFileUrl ou:" <<endl;
835
850
  Width -= wScore;
836
851
  Height -= hScore;
837
852
  cv::Mat dst;
@@ -847,7 +862,6 @@ MUInt8* ASK::processFileUrl(const char* url, int& picWidth, int& picHeight) {
847
862
 
848
863
  dst.release();
849
864
  } else {
850
- //cout << "processFileUrl ji:" <<endl;
851
865
  if (depth != 0) { //bit数仅支持8
852
866
  cv::Mat mid;
853
867
  modifyImageFormat(mid, src, channel);
@@ -909,39 +923,6 @@ MUInt8* ASK::processFileUrl(const char* url, int& picWidth, int& picHeight) {
909
923
  // ColorSpaceConversion(Width, Height, ASVL_PAF_NV21, imageData, offscreen);
910
924
  // }
911
925
 
912
- // void ASK::processFileUrl(const char* url, MUInt8* imageData, ASVLOFFSCREEN& offscreen) {
913
- // cv::Mat src = curlImg(url);
914
- // int Width = src.cols;
915
- // int Height = src.rows;
916
- // cout << "Width:" << Width << ",Height:"<<Height<<endl;
917
- // int wScore = Width % 4;
918
- // int hScore = Height % 2;
919
- // cv::Mat dest;
920
- // if (wScore != 0 || hScore != 0) {
921
- // Width -= wScore;
922
- // Height -= hScore;
923
- // cv::Mat dst;
924
- // cv::resize(src, dst, cv::Size(Width, Height));
925
- // src.release();
926
- // //src = dst;
927
- // cvtColor(dst, dest, COLOR_BGR2YUV_I420);
928
- // dst.release();
929
- // } else {
930
- // cvtColor(src, dest, COLOR_BGR2YUV_I420);
931
- // }
932
-
933
- // int len = Height*Width*3/2;
934
- // imageData = (MUInt8*)malloc(len);
935
- // memset(imageData, 0, len);
936
- // memcpy(imageData, dest.data, len);
937
- // src.release();
938
- // dest.release();
939
- // ColorSpaceConversion(Width, Height, ASVL_PAF_NV21, imageData, offscreen);
940
- // }
941
-
942
-
943
-
944
-
945
926
 
946
927
 
947
928
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "hzt_asc",
3
- "version": "1.1.2",
3
+ "version": "1.1.4",
4
4
  "main": "index.js",
5
5
  "description": "hzt_asc_v3.",
6
6
  "author": {