Skip to content
Advertisement

How to set color effect on document(image) using OpenCV(java)

currently, I’m working on a document scanner project who captures and filter document with different effects and color but I’m a beginner to work with OpenCV.

but, now I understand how medianBlurFilter , gaussianBlurFilter , cannyFilter and bilateralFilter works.

just I am starting to do this type of filter with the use of OpenCV but I can’t understand how to achieve this.

Input :

enter image description here

How to achieve this?:

enter image description here

enter image description here

Advertisement

Answer

//bitmap is a normal document image

        Bitmap newB = Bitmap.createBitmap(bitmap.getWidth(), bitmap.getHeight(), Bitmap.Config.ARGB_8888);
        Canvas canvas = new Canvas(newB);
        canvas.drawColor(Color.argb(sp,255, 0, 0));

        Mat src = new Mat();
        Utils.bitmapToMat(bitmap, src);

        Mat dst = new Mat();
        Utils.bitmapToMat(newB, dst);

        Core.addWeighted(src, 1f, dst, 0.5f, 0.5, dst);


//bitmapNew is a filtered document image

        Bitmap bitmapNew = Bitmap.createBitmap(bitmap.getWidth(), bitmap.getHeight(), Bitmap.Config.ARGB_8888);
        Utils.matToBitmap(dst, bitmapNew);
User contributions licensed under: CC BY-SA
1 People found this is helpful
Advertisement