Facedetection using Android opencv-Java -


i want detect face using android opencv. no face detected in image. testing have tried code in pc , working. why not working on android? opencv version 2.4.9. thank you.

private void my_opencv() throws ioexception     {         // todo auto-generated method stub           utils.bitmaptomat(bitmap, image);         log.d("mytag","open_cv2");         //imgproc.cvtcolor(image, grayscaleimage, imgproc.color_rgba2rgb);            file cascadedir = getdir("cascade", context.mode_private);         file mcascadefile = new file(cascadedir, "lbpcascade_frontalface.xml");         // load cascade classifier                      cascadeclassifier  facedetector = new cascadeclassifier(mcascadefile.getabsolutepath());         /**/         // detect faces in image.         // matofrect special container class rect.         matofrect facedetections = new matofrect();         facedetector.detectmultiscale(image, facedetections);         log.d("mytag","open_cv3");         rect rectcrop = null;          // draw bounding box around each face.         (rect rect : facedetections.toarray())         {             core.rectangle(image, new point(rect.x, rect.y), new point(rect.x + rect.width, rect.y + rect.height), new                       scalar(255, 0, 0));             // crop face             rectcrop = new rect(rect.x, rect.y, rect.width, rect.height);                 core.puttext(image, "edited me", new point(rect.x,rect.y),                     core.font_hershey_plain, 1.0 ,new  scalar(0,255,255));         }           // use classifier detect faces        // save visualized detection.         string format = new simpledateformat("yyyymmddhhmmss",                java.util.locale.getdefault()).format(new date());           bitmap bmp = null;         try {             bmp = bitmap.createbitmap(image.cols(), image.rows(), bitmap.config.argb_8888);             utils.mattobitmap(image, bmp);              bytearrayoutputstream bytes = new bytearrayoutputstream();             bmp.compress(bitmap.compressformat.jpeg, 100, bytes);             file f = new file( environment.getexternalstoragepublicdirectory(environment.directory_dcim) + file.separator + format+".jpg");              log.d("mytag","$$$$$$$$$$"+ environment.getexternalstoragepublicdirectory(environment.directory_dcim));             f.createnewfile();             fileoutputstream fo = new fileoutputstream(f);             fo.write(bytes.tobytearray());             fo.close();          } catch (cvexception e) {             log.d(tag, e.getmessage());         }       } 

solved code:

private void my_opencv() throws ioexception     {         // todo auto-generated method stub          utils.bitmaptomat(bitmap, image);         log.d("mytag","open_cv2");         //imgproc.cvtcolor(image, grayscaleimage, imgproc.color_rgba2rgb);          // load cascade file application resources         inputstream = getresources().openrawresource(                 r.raw.lbpcascade_frontalface);          file cascadedir = getdir("cascade", context.mode_private);         file mcascadefile = new file(cascadedir,                 "lbpcascade_frontalface.xml");         fileoutputstream os = new fileoutputstream(mcascadefile);          byte[] buffer = new byte[4096];         int bytesread;         while ((bytesread = is.read(buffer)) != -1)          {             os.write(buffer, 0, bytesread);         }         is.close();         os.close();           cascadeclassifier  facedetector = new cascadeclassifier(mcascadefile.getabsolutepath());         //must add line         //facedetector.load( mcascadefile.getabsolutepath() );         /**/         // detect faces in image.         // matofrect special container class rect.         matofrect facedetections = new matofrect();         facedetector.detectmultiscale(image, facedetections);         log.d("mytag","open_cv3");         rect rectcrop = null;          rect[] rect = facedetections.toarray();         // draw bounding box around each face. //      ( rect rect : facedetections.toarray() )         ( int = 0; < rect.length; i++ )         {             core.rectangle(image, new point(rect[i].x, rect[i].y), new point(rect[i].x + rect[i].width, rect[i].y + rect[i].height), new                          scalar(255, 0, 0));             // crop face             //rectcrop = new rect(rect.x, rect.y, rect.width, rect.height);                 core.puttext(image, "edited me", new point(rect[i].x,rect[i].y),                     core.font_hershey_plain, 1.0 ,new  scalar(0,255,255));         }           // use classifier detect faces        // save visualized detection.         string format = new simpledateformat("yyyymmddhhmmss",                java.util.locale.getdefault()).format(new date());           bitmap bmp = null;         try {             bmp = bitmap.createbitmap(image.cols(), image.rows(), bitmap.config.argb_8888);             utils.mattobitmap(image, bmp);              bytearrayoutputstream bytes = new bytearrayoutputstream();             bmp.compress(bitmap.compressformat.jpeg, 100, bytes);             file f = new file( environment.getexternalstoragepublicdirectory(environment.directory_dcim) + file.separator + format+".jpg");              log.d("mytag","$$$$$$$$$$"+ environment.getexternalstoragepublicdirectory(environment.directory_dcim));             f.createnewfile();             fileoutputstream fo = new fileoutputstream(f);             fo.write(bytes.tobytearray());             fo.close();          }          catch (cvexception e)          {             log.d(tag, e.getmessage());         }       } 

face detected in pc opencv

2 face detected in android opencv


Comments

Popular posts from this blog

php - Auto increment employee ID -

php - isset function not working properly -

firebird - Error "invalid transaction handle (expecting explicit transaction start)" executing script from Delphi -