-2

Please suggest me How to apply photo effects/filters on Run time in android Camera? with out using JNI , OpenGl and open CV. I need to apply effects only through Java code.

BenMorel
  • 34,448
  • 50
  • 182
  • 322
Srinoid
  • 11
  • 1
  • 5

2 Answers2

1

Step 1. Convert frame from NV21 to format supported by some image processing library. You can read how to do it here or here

Step 2. Use image processing library to perform filtering. For example you can use ImageJ. You can read about how to use ImageJ here or here or here.

Community
  • 1
  • 1
Ivan Mushketyk
  • 8,107
  • 7
  • 50
  • 67
0

Check out the Image Processing to apply various effects on Image. It provides various effects to be applied on Image after capturing.

Suppose i want to apply contrast effect on image then i will use the below method:

public static Bitmap createContrast(Bitmap src, double value) {
    // image size
    int width = src.getWidth();
    int height = src.getHeight();
    // create output bitmap
    Bitmap bmOut = Bitmap.createBitmap(width, height, src.getConfig());
    // color information
    int A, R, G, B;
    int pixel;
    // get contrast value
    double contrast = Math.pow((100 + value) / 100, 2);
        // scan through all pixels
    for(int x = 0; x < width; ++x) {
        for(int y = 0; y < height; ++y) {
            // get pixel color
            pixel = src.getPixel(x, y);
            A = Color.alpha(pixel);
            // apply filter contrast for every channel R, G, B
            R = Color.red(pixel);
            R = (int)(((((R / 255.0) - 0.5) * contrast) + 0.5) * 255.0);
            if(R < 0) { R = 0; }
            else if(R > 255) { R = 255; }
            G = Color.red(pixel);
            G = (int)(((((G / 255.0) - 0.5) * contrast) + 0.5) * 255.0);
            if(G < 0) { G = 0; }
            else if(G > 255) { G = 255; }
            B = Color.red(pixel);
            B = (int)(((((B / 255.0) - 0.5) * contrast) + 0.5) * 255.0);
            if(B < 0) { B = 0; }
            else if(B > 255) { B = 255; }
             // set new pixel color to output bitmap
            bmOut.setPixel(x, y, Color.argb(A, R, G, B));
        }
    }
    // return final image
    return bmOut;
}

Use above method as:

    BitMap bmp =BitmapFactory.decodeByteArray(byteArray, 0, byteArray.length); //Here you can define your image and convert it into Bitmap.
      bmp = createContrast(bm,75);
  mImageView.setImageBitmap(bmp);
GrIsHu
  • 29,068
  • 10
  • 64
  • 102
  • Thanks for your suggestion, I want to apply affects at run time only not after capturing Image. – Srinoid Oct 08 '13 at 07:06
  • Yes you can do that using the codes which are provided in the link. After capturing you can set image in `ImageView` and apply the effects on it by creating method for different effects which are available in the given link. – GrIsHu Oct 08 '13 at 07:08
  • AFAIK You can not apply effects run time on Image. You have to capture image first then and then you will be able to apply effects. – GrIsHu Oct 08 '13 at 07:15
  • @GrlsHu we can do it by using JNI and open CV. but Srinoid is asking how to do by using Java – android_dev Oct 08 '13 at 07:21
  • @android_dev Yes i know we can do it using JNI and openCV but Srinoid asking without using this libraries that is why i have provided this solution. – GrIsHu Oct 08 '13 at 07:23
  • How can i apply those effects while running the camera. – Srinoid Oct 08 '13 at 07:25