image processing - android camera2 process each frame and display its preview -
i use https://github.com/googlesamples/android-camera2basic, try modify in way access each frame before drawn on surfaceview. understood, should add additional surface (imagereader.getsurface()), , read frame in callback:
private final imagereader.onimageavailablelistener monimageavailablelistener = new imagereader.onimageavailablelistener() { @override public void onimageavailable(imagereader reader) { log.d("img", "onimageavailable"); mbackgroundhandler.post(new imagesaver(reader.acquirenextimage(), mfile)); } };
the problem callback gets called when image capture user , not on eacg frame sent preview screen camera.
here tried add:
private void createcamerapreviewsession() { try { surfacetexture texture = mtextureview.getsurfacetexture(); assert texture != null; // configure size of default buffer size of camera preview want. texture.setdefaultbuffersize(mpreviewsize.getwidth(), mpreviewsize.getheight()); // output surface need start preview. surface surface = new surface(texture); // set capturerequest.builder output surface. mpreviewrequestbuilder = mcameradevice.createcapturerequest(cameradevice.template_preview); mpreviewrequestbuilder.addtarget(surface); // here, create cameracapturesession camera preview. mcameradevice.createcapturesession(arrays.aslist(surface, mimagereader.getsurface()), new cameracapturesession.statecallback() { @override public void onconfigured(cameracapturesession cameracapturesession) { // camera closed if (null == mcameradevice) { return; } // when session ready, start displaying preview. mcapturesession = cameracapturesession; try { // auto focus should continuous camera preview. mpreviewrequestbuilder.set(capturerequest.control_af_mode, capturerequest.control_af_mode_continuous_picture); // flash automatically enabled when necessary. mpreviewrequestbuilder.set(capturerequest.control_ae_mode, capturerequest.control_ae_mode_on_auto_flash); // finally, start displaying camera preview. mpreviewrequest = mpreviewrequestbuilder.build(); mcapturesession.setrepeatingrequest(mpreviewrequest, mcapturecallback, mbackgroundhandler); //mpreviewrequestbuilder.addtarget(mimagereader.getsurface()); } catch (cameraaccessexception e) { e.printstacktrace(); } } @override public void onconfigurefailed(cameracapturesession cameracapturesession) { showtoast("failed"); } }, null ); /**todo added capturing aeach frame*/ // capturerequest.builder use take picture. final capturerequest.builder capturebuilder = mcameradevice.createcapturerequest(cameradevice.template_still_capture); capturebuilder.addtarget(mimagereader.getsurface()); // use same ae , af modes preview. capturebuilder.set(capturerequest.control_af_mode, capturerequest.control_af_mode_continuous_picture); capturebuilder.set(capturerequest.control_ae_mode, capturerequest.control_ae_mode_on_auto_flash); /**end added capture each frame*/ } catch (cameraaccessexception e) { e.printstacktrace(); } }
instead of creating new instance of capturerequest.builder, add imagereader's surface mpreviewrequestbuilder's output target.
Comments
Post a Comment