0

I'm using opencv in android unsing JNI c++ and i want to detect image and save detected face in android sdcard using function provide by opencv in c++ imwrite() but when i compile all thing succeded but when i excute app imwrite doesn't work it return false even though i use permission in manifest file (WRITE_EXTERNAL_STORAGE and READ_EXTERNAL_STORAGE) . i'm sorry about any mistakes in english because it not my original language. help please and vote up please because this project is very important to me

this is the code :

String human_cascade_name = "/storage/extSdCard/OpenCV/haarcascade_fullbody.xml";
CascadeClassifier human_cascade;

//-- 1. Load the cascades
      if( !human_cascade.load( human_cascade_name ) ){
      printf("--(!)Error loading\n");
       return;
        }
std::vector<Rect> humans;
     Mat frame_gray;

     cvtColor( frame, frame_gray, CV_BGR2GRAY );
     equalizeHist( frame_gray, frame_gray );

     //-- Detect faces
     human_cascade.detectMultiScale( frame_gray, humans, 1.1, 2, 0|CV_HAAR_SCALE_IMAGE, Size(30, 30) );
     stringstream ss;
     static int count=0;


     for(int i=0;i<humans.size();i++){


     //__android_log_print(ANDROID_LOG_DEBUG, "LOG_TAG", "hhhhhhhhhhhhhhhh : %d ",humans[i].y);

     Point center( humans[i].x + humans[i].width*0.5, humans[i].y + humans[i].height*0.5 );
     ellipse( frame, center, Size( 2, 2), 0, 0, 360, Scalar( 255, 0, 255 ), 4, 8, 0 );

     rectangle(frame,Point(humans[i].x,humans[i].y),Point(humans[i].x+humans[i].width,humans[i].y+humans[i].height), Scalar(0,255,0));

       }
       count+=1;
       ss << count;
       vector<int> compression_params;
       compression_params.push_back(CV_IMWRITE_PNG_COMPRESSION);
       compression_params.push_back(9);
       if(imwrite("/storage/extSdCard/OpenCV/User1.jpg", frame)){
       __android_log_print(ANDROID_LOG_DEBUG, "LOG_TAG", "yes");

       }else{
       __android_log_print(ANDROID_LOG_DEBUG, "LOG_TAG", "no");

       };


      }
  • This doesn’t appear to have anything to do with JNI. I suggest you debug it as a straight C++ application first; it might simplify things. – prl Apr 25 '19 at 03:57
  • Possible duplicate: https://stackoverflow.com/questions/22369168 – prl Apr 25 '19 at 04:01
  • Another possible duplicate (although it appears you have already checked for this): https://stackoverflow.com/questions/15291504 – prl Apr 25 '19 at 04:04

1 Answers1

0

You see the path to sdcard as /storage/extSdCard in adb shell or in your file transfer program on PC, but your Android app does not have access through this path. It should use the getExternalStorageDirectory() API, as demonstrated here.

Alex Cohn
  • 56,089
  • 9
  • 113
  • 307