I am using the frames that I receive from a USB camera (Using the UVCCamera library) and I apply a blur effect using RenderScript. The frame format is NV21. The blur effect created by RenderScript works very nicely. However, when I want to apply other effects using Zomato Filters, I get a flickering result, although the effects are applied.

And then in the onFrame method, I get the frames from USB camera and apply filters according to seekbar values:

    private final IFrameCallback mIFrameCallback = new IFrameCallback() {
        @Override
        public void onFrame(final ByteBuffer frame) {
            frame.clear();
            synchronized (bitmap) {
//                bitmap.copyPixelsFromBuffer(frame);


                byte[] bytes = new byte[frame.remaining()];
                frame.get(bytes);
                MainActivity.this.allocationYUV.copyFrom(bytes);
                MainActivity.this.ApplyEffect = false;
                if (!MainActivity.this.ApplyEffect) {
                    MainActivity.this.intrinsicYuvToRGB.setInput(MainActivity.this.allocationYUV);
                    MainActivity.this.intrinsicYuvToRGB.forEach(MainActivity.this.allocationBlur);
                    MainActivity.this.intrinsicBlur.forEach(MainActivity.this.allocationBlur, MainActivity.this.allocationOut);                   

                }
                MainActivity.this.allocationOut.syncAll(128);

                //Here, apply the three other effects
                int brightness = mSeekbar1.getProgress();
                int contrast = mSeekbar2.getProgress();
                int saturation = mSeekbar3.getProgress();

                //The following checks are done to prevent unnecessary image processing
                Filter myFilter = new Filter();
                if(brightness != 0) {
                        BrightnessSubfilter bs = new BrightnessSubfilter(brightness * 32);
                        bs.setTag("brightness");
                        myFilter.addSubFilter(bs);
                }
                else { //If 0, then remove the filter altogether
                    myFilter.removeSubFilterWithTag("brightness");
                }
                if(contrast != 0) {
                        ContrastSubfilter cs = new ContrastSubfilter(contrast * 32);
                        cs.setTag("contrast");
                        myFilter.addSubFilter(cs);
                        mContrastChanged = false;
                }
                else {
                    myFilter.removeSubFilterWithTag("contrast");
                }

                if(saturation != 0) {
                        SaturationSubfilter ss = new SaturationSubfilter(saturation * 32);
                        ss.setTag("saturation");
                        myFilter.addSubFilter(ss);
                        mSaturationChanged = false;
                }
                else {
                    myFilter.removeSubFilterWithTag("saturation");
                }
                mOutBitmap = myFilter.processFilter(bitmap);

                mImageView.post(mUpdateImageTask);

            }
        }
    };

    private final Runnable mUpdateImageTask = new Runnable() {
        @Override
        public void run() {
            synchronized (bitmap) {
                mImageView.setImageBitmap(mOutBitmap);
            }
        }
    };

I think the RenderScript allocations for blurring is pretty typical, so I didn't add those to save space and reduce complexity.

enter image description here

Your Answer

 

By clicking "Post Your Answer", you acknowledge that you have read our updated terms of service, privacy policy and cookie policy, and that your continued use of the website is subject to these policies.

Browse other questions tagged or ask your own question.