audio - Front camera face detect (Android Studio) -


well heard there camera class on android studio.

what im trying im trying make app turns on camera when pressed on , front camera , when detects face self says "you great today!" want record own voice , put own voice.

so if can guide me how that, amazing! researched everywhere!

i've downloaded made face detect interface. works need add voice it.

  1. open app
  2. waits until face detected
  3. says "you today"

thats want! can give me advice or atleast give me steps how it?

im noob take easy when explaining

simply use face detection libraries of native android (and not opencv or more complex) , app starts, keeps track of face. can put if statement check if face recognized , if vocal message has been playes.

if(recognized_faces != 0 && message_already_played == false){     //play message } 

this piece of code (an activity) takes photograms frontal camera , analyze them. code painted canvas on photograms , shows them sequentially (like video stream) "miaimmagine2". if don't want it, not show miaimmagine2 , show video camera layer. i've erased many parts of code unnecessary you, there lot of code erased or adjusted. can nice you. here code:

package mawashi.alex.driveawake;  import android.annotation.suppresslint; import android.app.activity; import android.content.context; import android.content.intent; import android.graphics.bitmap; import android.graphics.bitmapfactory; import android.graphics.canvas; import android.graphics.color; import android.graphics.imageformat; import android.graphics.matrix; import android.graphics.paint; import android.graphics.pointf; import android.graphics.rect; import android.graphics.yuvimage; import android.hardware.camera; import android.hardware.camera.errorcallback; import android.hardware.camera.previewcallback; import android.hardware.camera.size; import android.media.audiomanager; import android.media.facedetector; import android.media.mediametadataretriever; import android.media.mediaplayer; import android.net.uri; import android.os.bundle; import android.util.log; import android.view.surfaceholder; import android.view.surfaceholder.callback; import android.view.surfaceview; import android.view.view; import android.view.window; import android.widget.framelayout; import android.widget.imageview; import android.widget.textview; import android.widget.toast;  import java.io.bytearrayoutputstream; import java.io.file; import java.io.fileinputstream; import java.io.ioexception; import java.lang.reflect.method; import java.util.list;  @suppresslint("newapi") public class awakeactivity extends activity {     surfaceview mvideocaptureview;      camera mcamera;      public bitmap mfacebitmap;     public textview testo;     public bitmap mface2bitmap;     public imageview miaimmagine2;     private mediaplayer player;     public surfaceview msurfaceview;     public surfaceholder msurfaceholder;     private static final int max_faces = 1;     int mfacewidth;     int mfaceheight;     int cameratype = 1; // front     int frame_sec = 1000000;     byte[] callbackbuffer;     previewcallback cb;     public framelayout preview;     bitmap bmp;     bitmap b;     mediametadataretriever mediametadataretriever=null;     bitmap bmframe = null;     facedetector.face[] faces;     activity activity;     context mcontext;     int index_sleep = 0;     int consec = 0;     boolean sleep = false;     public float  scala = 1;     public int offset = 0;     int m = 1;     int colore = color.gray;     private mediaplayer player2;      @override     public void oncreate(bundle savedinstancestate) {         super.oncreate(savedinstancestate);         this.requestwindowfeature(window.feature_no_title);         setcontentview(r.layout.detection);         mvideocaptureview = (surfaceview) findviewbyid(r.id.surface);         miaimmagine2 = (imageview) findviewbyid(r.id.imageview2);         testo = (textview) findviewbyid(r.id.textview1);         surfaceholder videocaptureviewholder = mvideocaptureview.getholder();         videocaptureviewholder.settype(surfaceholder.surface_type_push_buffers);         setvolumecontrolstream(audiomanager.stream_music);         player = mediaplayer.create(this, r.raw.you_look_good);         videocaptureviewholder.addcallback(new callback() {             public void surfacedestroyed(surfaceholder holder) {         }          public void surfacecreated(surfaceholder holder) {             startvideo();         }          public void surfacechanged(surfaceholder holder, int format, int width, int height) {}         });     }      ////////////////////////////////////////////////////////////////////////////////////////     //************buttons***************************************************************        //rotate image of 90 degrees      protected void setdisplayorientation(camera mcamera, int angle){         method downpolymorphic;         try{             downpolymorphic = mcamera.getclass().getmethod("setdisplayorientation", new class[] { int.class });             if (downpolymorphic != null)                 downpolymorphic.invoke(mcamera, new object[] { angle });         }catch (exception e1){  }     }      /////////////////////////////////////////////////////////////////////////////////////////////     //******************************************************************************************      @override     public void onpause(){         super.onpause();         player.pause();     }      //**************************************************************************************     //*******************************startvideo*********************************************     @suppresslint("newapi")     private void startvideo() {         surfaceholder videocaptureviewholder = null;         try {             mcamera = camera.open(1);         } catch (runtimeexception e) {             log.e("cameratest", "camera open filed");             return;         }         mcamera.seterrorcallback(new errorcallback() {             public void onerror(int error, camera camera) {             }         });         camera.parameters parameters = mcamera.getparameters();         list<camera.size> previewsizes = parameters.getsupportedpreviewsizes();         camera.size cs = previewsizes.get(0);         parameters.setpreviewsize(cs.width,cs.height);           setdisplayorientation(mcamera, 90);         mcamera.setparameters(parameters);         if (null != mvideocaptureview)             videocaptureviewholder = mvideocaptureview.getholder();         try {             mcamera.setpreviewdisplay(videocaptureviewholder);         } catch (throwable t) {         }         log.v("cameratest","camera previewframerate = "+mcamera.getparameters().getpreviewframerate());         size previewsize=mcamera.getparameters().getpreviewsize();         int databuffersize=(int)(previewsize.height*previewsize.width* (imageformat.getbitsperpixel(mcamera.getparameters().getpreviewformat())/8.0));         mcamera.addcallbackbuffer(new byte[databuffersize]);         mcamera.setpreviewcallbackwithbuffer(new camera.previewcallback() {             private long timestamp=0;             public synchronized void onpreviewframe(byte[] data, camera camera) {                 size previewsize=camera.getparameters().getpreviewsize();                 yuvimage yuvimage= new yuvimage(data,imageformat.nv21, previewsize.width, previewsize.height, null);                 bytearrayoutputstream baos = new bytearrayoutputstream();                 yuvimage.compresstojpeg(new rect(0, 0, previewsize.width, previewsize.height),80, baos);                 byte jpgdata[]=baos.tobytearray();                 bmp = bitmapfactory.decodebytearray(jpgdata, 0, jpgdata.length);                 bitmap bmp2 = bitmap.createbitmap(bmp.getwidth(), bmp.getheight(), bitmap.config.rgb_565);                 canvas canvas=new canvas(bmp2);                    paint paint=new paint();                 paint.setcolor(color.red);                 paint.setstyle(paint.style.stroke);                 paint.setstrokewidth(2);                 matrix matrix = new matrix();                 matrix.setrotate(270,bmp.getwidth()/2,bmp.getheight()/2);                 canvas.drawbitmap(bmp, matrix, paint);                    faces = new facedetector.face[max_faces];                 int mfacewidth = bmp2.getwidth();                 int mfaceheight = bmp2.getheight();                 pointf midpoint = new pointf();      //inizializza punto di coordinate float                 facedetector detector = new facedetector(mfacewidth, mfaceheight,max_faces);                 int facesfound = detector.findfaces(bmp2, faces); //bmp                  if(facesfound > 0 && message_started==false){                     faces[0].getmidpoint(midpoint);                     float eyedistance = faces[0].eyesdistance();                     float confidence = faces[0].confidence();                     player.start(); //play of "you today!"                     message_started = true;                 }                 miaimmagine2.setimagebitmap(bmp2);                 //+++++++++++++++++++++parte finale++++++++++++++++++++++++++++++++++++++++                 try{                     camera.addcallbackbuffer(data);                 }catch (exception e) {                     log.e("cameratest", "addcallbackbuffer error");                     return;                 }                 return;             }         });         try {             mcamera.startpreview();         } catch (throwable e) {             mcamera.release();             mcamera = null;             return;         }      }     //*************************************startvideo_end***************************************     ////////////////////////////////////////////////////////////////////////////////////////////     //*************************************stopvideo********************************************       private void stopvideo() {         if(null==mcamera)             return;         try {             mcamera.stoppreview();             mcamera.setpreviewdisplay(null);             mcamera.setpreviewcallbackwithbuffer(null);             mcamera.release();         } catch (ioexception e) {             e.printstacktrace();             return;         }         mcamera = null;     }     //**********************************stopvideo_end********************************************     //////////////////////////////////////////////////////////////////////////////////////////////     //**********************************finish***************************************************     public void finish(){         stopvideo();         super.finish();     };     //**********************************finish_end***********************************************       } 

Comments

Popular posts from this blog

aws api gateway - SerializationException in posting new Records via Dynamodb Proxy Service in API -

asp.net - Problems sending emails from forum -