├── CameraBlur ├── .gitignore ├── app │ ├── .gitignore │ ├── build.gradle │ ├── proguard-rules.pro │ └── src │ │ └── main │ │ ├── AndroidManifest.xml │ │ ├── assets │ │ └── frozen_inference_graph.pb │ │ ├── java │ │ └── com │ │ │ └── anondev │ │ │ └── gaurav │ │ │ └── camerablur │ │ │ ├── Dbhandler.java │ │ │ ├── DeeplabProcessor.java │ │ │ ├── FixAppBarLayoutBehavior.java │ │ │ ├── FocusIndicatorView.java │ │ │ ├── ImageUtils.java │ │ │ ├── MainActivity.java │ │ │ ├── OpenCamera.java │ │ │ ├── PortraitBlurService.java │ │ │ ├── SlideShowDialogFragment.java │ │ │ ├── ZoomOutPageTransformer.java │ │ │ └── entry.java │ │ └── res │ │ ├── drawable-v24 │ │ ├── ic_launcher_foreground.xml │ │ └── ic_menu_camera.xml │ │ ├── drawable │ │ ├── circle.xml │ │ ├── focus_indicator.xml │ │ ├── ic_check_black_24dp.xml │ │ ├── ic_clear_black_24dp.xml │ │ ├── ic_flash_on_black_24dp.xml │ │ ├── ic_launcher_background.xml │ │ └── item_bg_menu.xml │ │ ├── layout │ │ ├── activity_main.xml │ │ ├── app_bar_main.xml │ │ ├── camera.xml │ │ ├── fragment_image_slider.xml │ │ ├── full_screen_image.xml │ │ ├── grid_item.xml │ │ └── list_layout.xml │ │ ├── mipmap-anydpi-v26 │ │ ├── ic_launcher.xml │ │ └── ic_launcher_round.xml │ │ ├── mipmap-hdpi │ │ ├── ic_launcher.png │ │ └── ic_launcher_round.png │ │ ├── mipmap-mdpi │ │ ├── ic_launcher.png │ │ └── ic_launcher_round.png │ │ ├── mipmap-xhdpi │ │ ├── ic_launcher.png │ │ └── ic_launcher_round.png │ │ ├── mipmap-xxhdpi │ │ ├── ic_launcher.png │ │ └── ic_launcher_round.png │ │ ├── mipmap-xxxhdpi │ │ ├── ic_launcher.png │ │ └── ic_launcher_round.png │ │ └── values │ │ ├── colors.xml │ │ ├── dimens.xml │ │ ├── strings.xml │ │ └── styles.xml ├── build.gradle ├── gradle.properties ├── gradle │ └── wrapper │ │ ├── gradle-wrapper.jar │ │ └── gradle-wrapper.properties ├── gradlew ├── gradlew.bat └── settings.gradle ├── InputSize 1025px └── frozen_inference_graph.pb ├── InputSize 1537px └── frozen_inference_graph.pb ├── InputSize 513px └── frozen_inference_graph.pb ├── LICENSE ├── README.md ├── SampleImages ├── Blurred1.jpg ├── Blurred2.jpg ├── Image1.jpg └── Image2.jpeg └── apk ├── InitVersion └── app-debug1537.apk ├── v0.0.2 └── CameraBlur 1025px.apk ├── v0.0.3 └── CameraBlur 1025px.apk └── v1.0.0 └── app-debug.apk /CameraBlur/.gitignore: -------------------------------------------------------------------------------- 1 | *.iml 2 | .gradle 3 | /local.properties 4 | /.idea/libraries 5 | /.idea/modules.xml 6 | /.idea/workspace.xml 7 | .DS_Store 8 | /build 9 | /captures 10 | .externalNativeBuild 11 | -------------------------------------------------------------------------------- /CameraBlur/app/.gitignore: -------------------------------------------------------------------------------- 1 | /build 2 | -------------------------------------------------------------------------------- /CameraBlur/app/build.gradle: -------------------------------------------------------------------------------- 1 | apply plugin: 'com.android.application' 2 | 3 | android { 4 | compileSdkVersion 27 5 | defaultConfig { 6 | applicationId "com.anondev.gaurav.camerablur" 7 | minSdkVersion 21 8 | targetSdkVersion 27 9 | versionCode 1 10 | versionName "1.0" 11 | } 12 | buildTypes { 13 | release { 14 | minifyEnabled false 15 | proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro' 16 | } 17 | } 18 | 19 | 20 | } 21 | 22 | dependencies { 23 | implementation fileTree(include: ['*.jar'], dir: 'libs') 24 | implementation 'com.android.support:appcompat-v7:27.1.0' 25 | implementation 'com.android.support:preference-v7:27.1.0' 26 | implementation 'com.android.support:exifinterface:27.1.0' 27 | implementation 'com.android.support:design:27.1.0' 28 | implementation 'com.android.support:support-compat:27.1.0' 29 | implementation 'com.android.support:support-v4:27.1.0' 30 | implementation 'com.android.support:appcompat-v7:27.1.0' 31 | implementation 'com.github.fafaldo:fab-toolbar:1.2.0' 32 | implementation 'org.tensorflow:tensorflow-android:+' 33 | implementation 'com.github.bumptech.glide:glide:4.7.1' 34 | implementation 'com.davemorrissey.labs:subsampling-scale-image-view:3.9.0' 35 | implementation 'com.github.woxthebox:draglistview:1.6.0' 36 | implementation 'com.github.esafirm.android-image-picker:imagepicker:1.13.1' 37 | } 38 | 39 | allprojects { 40 | repositories { 41 | maven { url "https://jitpack.io" 42 | } 43 | } 44 | } -------------------------------------------------------------------------------- /CameraBlur/app/proguard-rules.pro: -------------------------------------------------------------------------------- 1 | # Add project specific ProGuard rules here. 2 | # You can control the set of applied configuration files using the 3 | # proguardFiles setting in build.gradle. 4 | # 5 | # For more details, see 6 | # http://developer.android.com/guide/developing/tools/proguard.html 7 | 8 | # If your project uses WebView with JS, uncomment the following 9 | # and specify the fully qualified class name to the JavaScript interface 10 | # class: 11 | #-keepclassmembers class fqcn.of.javascript.interface.for.webview { 12 | # public *; 13 | #} 14 | 15 | # Uncomment this to preserve the line number information for 16 | # debugging stack traces. 17 | #-keepattributes SourceFile,LineNumberTable 18 | 19 | # If you keep the line number information, uncomment this to 20 | # hide the original source file name. 21 | #-renamesourcefileattribute SourceFile 22 | -------------------------------------------------------------------------------- /CameraBlur/app/src/main/AndroidManifest.xml: -------------------------------------------------------------------------------- 1 | 2 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 22 | 25 | 26 | 27 | 28 | 29 | 30 | 31 | 35 | 36 | 39 | 40 | 41 | -------------------------------------------------------------------------------- /CameraBlur/app/src/main/assets/frozen_inference_graph.pb: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Gauravv97/CameraBlur/b3b80ad9d8492c76957c3d7c4aa5e9a0cb7bf1f3/CameraBlur/app/src/main/assets/frozen_inference_graph.pb -------------------------------------------------------------------------------- /CameraBlur/app/src/main/java/com/anondev/gaurav/camerablur/Dbhandler.java: -------------------------------------------------------------------------------- 1 | package com.anondev.gaurav.camerablur; 2 | 3 | import android.content.ContentValues; 4 | import android.content.Context; 5 | import android.database.Cursor; 6 | import android.database.sqlite.SQLiteDatabase; 7 | import android.database.sqlite.SQLiteOpenHelper; 8 | 9 | import java.io.File; 10 | 11 | public class Dbhandler extends SQLiteOpenHelper{ 12 | public static final int DATABASE_VERSION=1; 13 | public static final String DATABASE_NAME="indx.db"; 14 | public static final String TABLE_NAME = "entry"; 15 | 16 | public static final String ID="_id"; 17 | 18 | public static final String COLUMN1_NAME_TITLE_TABLE1 = "Path"; 19 | public static final String COLUMN2_NAME_TITLE_TABLE1 = "Map"; 20 | 21 | 22 | 23 | 24 | public Dbhandler(Context context, String name, SQLiteDatabase.CursorFactory factory, int version) { 25 | super(context, DATABASE_NAME, factory, DATABASE_VERSION); 26 | 27 | } 28 | 29 | 30 | @Override 31 | public void onCreate(SQLiteDatabase db) { 32 | String Query= "CREATE TABLE " + TABLE_NAME + " (" + 33 | ID + " INTEGER ," + 34 | COLUMN1_NAME_TITLE_TABLE1 +" TEXT,"+ 35 | COLUMN2_NAME_TITLE_TABLE1 +" TEXT);"; 36 | db.execSQL(Query); 37 | 38 | 39 | } 40 | 41 | 42 | @Override 43 | public void onUpgrade(SQLiteDatabase db, int oldVersion, int newVersion) { 44 | db.execSQL("DROP TABLE IF EXISTS "+TABLE_NAME); 45 | onCreate(db); 46 | } 47 | public void addRow(entry e) 48 | { 49 | int id=rCount(); 50 | SQLiteDatabase db = getWritableDatabase(); 51 | ContentValues x=new ContentValues(); 52 | x.put(ID,id); 53 | x.put(COLUMN1_NAME_TITLE_TABLE1,e.getPath()); 54 | x.put(COLUMN2_NAME_TITLE_TABLE1,e.getMap()); 55 | db.insert(TABLE_NAME,null,x); 56 | 57 | } 58 | public entry getresult(int x){ 59 | 60 | entry e=new entry(); 61 | SQLiteDatabase db = getWritableDatabase(); 62 | String query="SELECT * FROM "+TABLE_NAME+" WHERE "+ID+"="+x+";"; 63 | Cursor c=db.rawQuery(query,null); 64 | c.moveToFirst(); 65 | if(!c.isAfterLast()) 66 | { 67 | if(c.getString(c.getColumnIndex(ID))!=null) 68 | e.set_id(c.getInt(c.getColumnIndex(ID))); 69 | if(c.getString(c.getColumnIndex(COLUMN1_NAME_TITLE_TABLE1))!=null) 70 | e.setPath(c.getString(c.getColumnIndex(COLUMN1_NAME_TITLE_TABLE1))); 71 | if(c.getString(c.getColumnIndex(COLUMN2_NAME_TITLE_TABLE1))!=null) 72 | e.setMap(c.getString(c.getColumnIndex(COLUMN2_NAME_TITLE_TABLE1))); 73 | } 74 | 75 | c.close(); 76 | return e; 77 | } 78 | public int rCount() { 79 | String countQuery = "SELECT * FROM " + TABLE_NAME; 80 | SQLiteDatabase db =getWritableDatabase(); 81 | Cursor cursor = db.rawQuery(countQuery, null); 82 | int cnt = cursor.getCount(); 83 | cursor.close(); 84 | return cnt; 85 | } 86 | public int set_newPath(String image,String BlurredImage){ 87 | SQLiteDatabase db = getWritableDatabase(); 88 | String Query="SELECT * FROM "+TABLE_NAME+" WHERE "+COLUMN1_NAME_TITLE_TABLE1+"='"+image+"'"; 89 | Cursor c=db.rawQuery(Query,null); 90 | c.moveToFirst(); 91 | if(!c.isAfterLast()) 92 | { 93 | 94 | Query = "UPDATE " + TABLE_NAME + " SET " + COLUMN1_NAME_TITLE_TABLE1 + "='" + BlurredImage + "' WHERE " + COLUMN1_NAME_TITLE_TABLE1 + "='" + image + "';"; 95 | db.execSQL(Query); 96 | return c.getInt(c.getColumnIndex(ID)); 97 | } 98 | return -1; 99 | } 100 | 101 | public void move_entry(int from,int to){ 102 | String Query; 103 | SQLiteDatabase db = getWritableDatabase(); 104 | Query="UPDATE "+TABLE_NAME+" SET "+ID+"=-1 WHERE "+ID+"="+from+";"; 105 | db.execSQL(Query); 106 | 107 | Query="UPDATE "+TABLE_NAME+" SET "+ID+"="+ID+"-1 WHERE "+ID+">"+from+";"; 108 | db.execSQL(Query); 109 | 110 | Query="UPDATE "+TABLE_NAME+" SET "+ID+"="+ID+"+1 WHERE "+ID+">"+(to-1)+";"; 111 | db.execSQL(Query); 112 | 113 | Query="UPDATE "+TABLE_NAME+" SET "+ID+"="+to+" WHERE "+ID+"="+(-1)+";"; 114 | db.execSQL(Query); 115 | 116 | } 117 | 118 | 119 | public void DeleteEntry(int i){ 120 | String Query; 121 | SQLiteDatabase db = getWritableDatabase(); 122 | Query="DELETE FROM "+TABLE_NAME+" WHERE "+ID+"="+i+";"; 123 | db.execSQL(Query); 124 | 125 | Query="UPDATE "+TABLE_NAME+" SET "+ID+"="+ID+"-1 WHERE "+ID+">"+i+";"; 126 | db.execSQL(Query); 127 | 128 | } 129 | 130 | } 131 | -------------------------------------------------------------------------------- /CameraBlur/app/src/main/java/com/anondev/gaurav/camerablur/DeeplabProcessor.java: -------------------------------------------------------------------------------- 1 | package com.anondev.gaurav.camerablur; 2 | 3 | import android.content.Context; 4 | import android.graphics.Bitmap; 5 | import android.graphics.Color; 6 | import android.text.TextUtils; 7 | import android.util.Log; 8 | 9 | 10 | import org.tensorflow.Graph; 11 | import org.tensorflow.Operation; 12 | import org.tensorflow.Output; 13 | import org.tensorflow.contrib.android.TensorFlowInferenceInterface; 14 | 15 | import java.io.File; 16 | import java.io.FileInputStream; 17 | import java.io.FileNotFoundException; 18 | import java.io.IOException; 19 | import java.util.Iterator; 20 | 21 | public class DeeplabProcessor { 22 | 23 | private final static String MODEL_FILE = "file:///android_asset/frozen_inference_graph.pb"; 24 | 25 | private final static String INPUT_NAME = "ImageTensor"; 26 | private final static String OUTPUT_NAME = "SemanticPredictions"; 27 | 28 | public final static int INPUT_SIZE = 1025; 29 | 30 | private static TensorFlowInferenceInterface sTFInterface = null; 31 | private static Context mContext; 32 | 33 | public synchronized static boolean initialize(Context context) { 34 | mContext=context; 35 | final File graphPath = new File(MODEL_FILE); 36 | 37 | FileInputStream graphStream; 38 | try { 39 | graphStream = new FileInputStream(graphPath); 40 | } catch (FileNotFoundException e) { 41 | Log.e("Input",e.getMessage()); 42 | 43 | graphStream = null; 44 | } 45 | /* 46 | 47 | if (graphStream == null) { 48 | return false; 49 | } 50 | */ 51 | 52 | 53 | //sTFInterface = new TensorFlowInferenceInterface(graphStream); 54 | sTFInterface=new TensorFlowInferenceInterface(context.getAssets(), MODEL_FILE); 55 | if (sTFInterface == null) { 56 | Log.w("init model failed", 57 | MODEL_FILE); 58 | 59 | return false; 60 | } 61 | 62 | // printGraph(sTFInterface.graph()); 63 | // printOp(sTFInterface.graph(), "ImageTensor"); 64 | 65 | if (graphStream != null) { 66 | try { 67 | graphStream.close(); 68 | } catch (IOException e) { 69 | } 70 | } 71 | 72 | return true; 73 | } 74 | 75 | public synchronized static boolean isInitialized() { 76 | return (sTFInterface != null); 77 | } 78 | 79 | 80 | public synchronized static int[] GetBlurredImage(final Bitmap bitmap) { 81 | if (sTFInterface == null) { 82 | Log.e("tfmodel not init",""); 83 | return null; 84 | } 85 | 86 | if (bitmap == null) { 87 | Log.e("bitmap null ",""); 88 | return null; 89 | } 90 | 91 | final int w = bitmap.getWidth(); 92 | final int h = bitmap.getHeight(); 93 | Log.e("bitmap: "+w+"x"+h,""); 94 | 95 | if (w > INPUT_SIZE || h > INPUT_SIZE) {/* 96 | Log.w("invalid bitmap size: %d x %d [should be: %d x %d]", 97 | w, h, 98 | INPUT_SIZE, INPUT_SIZE);*/ 99 | Log.e("bitmap: "+w+"x"+h,""); 100 | 101 | return null; 102 | } 103 | 104 | int[] mIntValues = new int[w * h]; 105 | byte[] mFlatIntValues = new byte[w * h * 3]; 106 | int[] mOutputs = new int[w * h]; 107 | 108 | bitmap.getPixels(mIntValues, 0, w, 0, 0, w, h); 109 | for (int i = 0; i < mIntValues.length; ++i) { 110 | final int val = mIntValues[i]; 111 | mFlatIntValues[i * 3 + 0] = (byte)((val >> 16) & 0xFF); 112 | mFlatIntValues[i * 3 + 1] = (byte)((val >> 8) & 0xFF); 113 | mFlatIntValues[i * 3 + 2] = (byte)(val & 0xFF); 114 | } 115 | 116 | final long start = System.currentTimeMillis(); 117 | sTFInterface.feed(INPUT_NAME, mFlatIntValues, 1, h, w, 3 ); 118 | sTFInterface.run(new String[] { OUTPUT_NAME }, true); 119 | sTFInterface.fetch(OUTPUT_NAME, mOutputs); 120 | double ar[]=new double[256]; 121 | for (int y = 0; y < h; y++) { 122 | for (int x = 0; x < w; x++) { 123 | if(mOutputs[y * w + x]!=0) 124 | ar[mOutputs[y * w + x]]++; 125 | } 126 | } 127 | for (int y = h/2-10; y < h/2+10; y++) { 128 | for (int x = w/2-10; x < w/2+10; x++) { 129 | ar[mOutputs[y * w + x]]=ar[mOutputs[y * w + x]]*1.04; 130 | } 131 | } 132 | double max=0; 133 | int maxi=0; 134 | for (int i=1;i<256;i++){ 135 | if(max operations = graph.operations(); 168 | if (operations == null) { 169 | return; 170 | } 171 | 172 | Operation op; 173 | Output output; 174 | int num; 175 | while (operations.hasNext()) { 176 | op = operations.next(); 177 | 178 | Logger.debug("op: [%s]", op); 179 | num = op.numOutputs(); 180 | 181 | for (int i = 0; i < num; i++) { 182 | output = op.output(i); 183 | 184 | Logger.debug("%s- [%d]: %s", 185 | (i == num - 1) ? "`" : "|", 186 | i, output); 187 | } 188 | } 189 | }*/ 190 | } 191 | 192 | -------------------------------------------------------------------------------- /CameraBlur/app/src/main/java/com/anondev/gaurav/camerablur/FixAppBarLayoutBehavior.java: -------------------------------------------------------------------------------- 1 | package com.anondev.gaurav.camerablur; 2 | 3 | /** 4 | * Created by Gaurav on 3/6/2018. 5 | */ 6 | 7 | import android.content.Context; 8 | import android.support.design.widget.AppBarLayout; 9 | import android.support.design.widget.CoordinatorLayout; 10 | import android.support.v4.view.ViewCompat; 11 | import android.util.AttributeSet; 12 | import android.view.View; 13 | 14 | /** 15 | * Workaround AppBarLayout.Behavior for https://issuetracker.google.com/66996774 16 | * 17 | * Google has yet not fixded this bug Ugghhhh they said they will fix it in next build and they did ..............NOT 18 | * temp fix until they resolve DaFuq they did with support (item not clicking after scroll in another scroll parent check if last and registe a click instead of scroll stopper 19 | */ 20 | public class FixAppBarLayoutBehavior extends AppBarLayout.Behavior { 21 | 22 | public FixAppBarLayoutBehavior() { 23 | super(); 24 | } 25 | 26 | public FixAppBarLayoutBehavior(Context context, AttributeSet attrs) { 27 | super(context, attrs); 28 | } 29 | 30 | @Override 31 | public void onNestedScroll(CoordinatorLayout coordinatorLayout, AppBarLayout child, View target, 32 | int dxConsumed, int dyConsumed, int dxUnconsumed, int dyUnconsumed, int type) { 33 | super.onNestedScroll(coordinatorLayout, child, target, dxConsumed, dyConsumed, 34 | dxUnconsumed, dyUnconsumed, type); 35 | stopNestedScrollIfNeeded(dyUnconsumed, child, target, type); 36 | } 37 | 38 | @Override 39 | public void onNestedPreScroll(CoordinatorLayout coordinatorLayout, AppBarLayout child, 40 | View target, int dx, int dy, int[] consumed, int type) { 41 | super.onNestedPreScroll(coordinatorLayout, child, target, dx, dy, consumed, type); 42 | stopNestedScrollIfNeeded(dy, child, target, type); 43 | } 44 | 45 | private void stopNestedScrollIfNeeded(int dy, AppBarLayout child, View target, int type) { 46 | if (type == ViewCompat.TYPE_NON_TOUCH) { 47 | final int currOffset = getTopAndBottomOffset(); 48 | if ((dy < 0 && currOffset == 0) 49 | || (dy > 0 && currOffset == -child.getTotalScrollRange())) { 50 | ViewCompat.stopNestedScroll(target, ViewCompat.TYPE_NON_TOUCH); 51 | } 52 | } 53 | } 54 | } -------------------------------------------------------------------------------- /CameraBlur/app/src/main/java/com/anondev/gaurav/camerablur/FocusIndicatorView.java: -------------------------------------------------------------------------------- 1 | package com.anondev.gaurav.camerablur; 2 | 3 | import android.content.Context; 4 | import android.graphics.Point; 5 | import android.util.AttributeSet; 6 | import android.view.View; 7 | 8 | import com.anondev.gaurav.camerablur.R; 9 | 10 | /** 11 | * Created by Gaurav on 3/3/2018. 12 | */ 13 | public class FocusIndicatorView extends View { 14 | 15 | private Point mLocationPoint; 16 | 17 | public FocusIndicatorView(Context context, AttributeSet attrs) { 18 | super(context, attrs); 19 | } 20 | 21 | private void setDrawable(int resid) { 22 | this.setBackgroundResource(resid); 23 | } 24 | 25 | public void showStart() { 26 | setDrawable(R.drawable.focus_indicator); 27 | } 28 | 29 | public void clear() { 30 | setBackgroundDrawable(null); 31 | } 32 | 33 | } -------------------------------------------------------------------------------- /CameraBlur/app/src/main/java/com/anondev/gaurav/camerablur/ImageUtils.java: -------------------------------------------------------------------------------- 1 | /* Copyright 2015 The TensorFlow Authors. All Rights Reserved. 2 | 3 | Licensed under the Apache License, Version 2.0 (the "License"); 4 | you may not use this file except in compliance with the License. 5 | You may obtain a copy of the License at 6 | 7 | http://www.apache.org/licenses/LICENSE-2.0 8 | 9 | Unless required by applicable law or agreed to in writing, software 10 | distributed under the License is distributed on an "AS IS" BASIS, 11 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | See the License for the specific language governing permissions and 13 | limitations under the License. 14 | ==============================================================================*/ 15 | 16 | package com.anondev.gaurav.camerablur; 17 | 18 | import android.content.Context; 19 | import android.graphics.Bitmap; 20 | import android.graphics.BitmapFactory; 21 | import android.graphics.Canvas; 22 | import android.graphics.Rect; 23 | import android.renderscript.Allocation; 24 | import android.renderscript.Element; 25 | import android.renderscript.RenderScript; 26 | import android.renderscript.ScriptIntrinsicBlur; 27 | import android.text.TextUtils; 28 | import android.util.Log; 29 | 30 | import java.io.File; 31 | import java.io.FileInputStream; 32 | 33 | /** 34 | * Utility class for manipulating images. 35 | **/ 36 | public class ImageUtils { 37 | 38 | public static Bitmap tfResizeBilinear(Bitmap bitmap, int w, int h) { 39 | if (bitmap == null) { 40 | return null; 41 | } 42 | 43 | Bitmap resized = Bitmap.createBitmap(w, h, 44 | Bitmap.Config.ARGB_8888); 45 | 46 | final Canvas canvas = new Canvas(resized); 47 | canvas.drawBitmap(bitmap, 48 | new Rect(0, 0, bitmap.getWidth(), bitmap.getHeight()), 49 | new Rect(0, 0, w, h), 50 | null); 51 | 52 | return resized; 53 | } 54 | public static Bitmap decodeBitmapFromFile(String filePath, 55 | int reqWidth, 56 | int reqHeight) { 57 | if (TextUtils.isEmpty(filePath)) { 58 | return null; 59 | } 60 | 61 | // First decode with inJustDecodeBounds=true to check dimensions 62 | final BitmapFactory.Options options = new BitmapFactory.Options(); 63 | options.inJustDecodeBounds = true; 64 | BitmapFactory.decodeFile(filePath, options); 65 | 66 | // Calculate inSampleSize 67 | options.inSampleSize = calculateInSampleSize(options, reqWidth, reqHeight); 68 | 69 | // Decode bitmap with inSampleSize set 70 | options.inJustDecodeBounds = false; 71 | return BitmapFactory.decodeFile(filePath, options); 72 | } 73 | public static int calculateInSampleSize(BitmapFactory.Options options, int reqWidth, int reqHeight) { 74 | final int height = options.outHeight; 75 | final int width = options.outWidth; 76 | int inSampleSize = 1; 77 | 78 | if (height > reqHeight || width > reqWidth) { 79 | final int heightRatio = Math.round((float) height / (float) reqHeight); 80 | final int widthRatio = Math.round((float) width / (float) reqWidth); 81 | inSampleSize = heightRatio < widthRatio ? heightRatio : widthRatio; 82 | } 83 | final float totalPixels = width * height; 84 | final float totalReqPixelsCap = reqWidth * reqHeight * 2; 85 | 86 | while (totalPixels / (inSampleSize * inSampleSize) > totalReqPixelsCap) { 87 | inSampleSize++; 88 | } 89 | 90 | return inSampleSize; 91 | } 92 | public static Bitmap fastblur(Bitmap sentBitmap, int radius) { 93 | 94 | //sentBitmap = Bitmap.createScaledBitmap(sentBitmap, width, height, false); 95 | 96 | Bitmap bitmap = sentBitmap.copy(sentBitmap.getConfig(), true); 97 | 98 | if (radius < 1) { 99 | return (null); 100 | } 101 | 102 | int w = bitmap.getWidth(); 103 | int h = bitmap.getHeight(); 104 | 105 | int[] pix = new int[w * h]; 106 | bitmap.getPixels(pix, 0, w, 0, 0, w, h); 107 | 108 | int wm = w - 1; 109 | int hm = h - 1; 110 | int wh = w * h; 111 | int div = radius + radius + 1; 112 | 113 | int r[] = new int[wh]; 114 | int g[] = new int[wh]; 115 | int b[] = new int[wh]; 116 | int rsum, gsum, bsum, x, y, i, p, yp, yi, yw; 117 | int vmin[] = new int[Math.max(w, h)]; 118 | 119 | int divsum = (div + 1) >> 1; 120 | divsum *= divsum; 121 | int dv[] = new int[256 * divsum]; 122 | for (i = 0; i < 256 * divsum; i++) { 123 | dv[i] = (i / divsum); 124 | } 125 | 126 | yw = yi = 0; 127 | 128 | int[][] stack = new int[div][3]; 129 | int stackpointer; 130 | int stackstart; 131 | int[] sir; 132 | int rbs; 133 | int r1 = radius + 1; 134 | int routsum, goutsum, boutsum; 135 | int rinsum, ginsum, binsum; 136 | 137 | for (y = 0; y < h; y++) { 138 | rinsum = ginsum = binsum = routsum = goutsum = boutsum = rsum = gsum = bsum = 0; 139 | for (i = -radius; i <= radius; i++) { 140 | p = pix[yi + Math.min(wm, Math.max(i, 0))]; 141 | sir = stack[i + radius]; 142 | sir[0] = (p & 0xff0000) >> 16; 143 | sir[1] = (p & 0x00ff00) >> 8; 144 | sir[2] = (p & 0x0000ff); 145 | rbs = r1 - Math.abs(i); 146 | rsum += sir[0] * rbs; 147 | gsum += sir[1] * rbs; 148 | bsum += sir[2] * rbs; 149 | if (i > 0) { 150 | rinsum += sir[0]; 151 | ginsum += sir[1]; 152 | binsum += sir[2]; 153 | } else { 154 | routsum += sir[0]; 155 | goutsum += sir[1]; 156 | boutsum += sir[2]; 157 | } 158 | } 159 | stackpointer = radius; 160 | 161 | for (x = 0; x < w; x++) { 162 | 163 | r[yi] = dv[rsum]; 164 | g[yi] = dv[gsum]; 165 | b[yi] = dv[bsum]; 166 | 167 | rsum -= routsum; 168 | gsum -= goutsum; 169 | bsum -= boutsum; 170 | 171 | stackstart = stackpointer - radius + div; 172 | sir = stack[stackstart % div]; 173 | 174 | routsum -= sir[0]; 175 | goutsum -= sir[1]; 176 | boutsum -= sir[2]; 177 | 178 | if (y == 0) { 179 | vmin[x] = Math.min(x + radius + 1, wm); 180 | } 181 | p = pix[yw + vmin[x]]; 182 | 183 | sir[0] = (p & 0xff0000) >> 16; 184 | sir[1] = (p & 0x00ff00) >> 8; 185 | sir[2] = (p & 0x0000ff); 186 | 187 | rinsum += sir[0]; 188 | ginsum += sir[1]; 189 | binsum += sir[2]; 190 | 191 | rsum += rinsum; 192 | gsum += ginsum; 193 | bsum += binsum; 194 | 195 | stackpointer = (stackpointer + 1) % div; 196 | sir = stack[(stackpointer) % div]; 197 | 198 | routsum += sir[0]; 199 | goutsum += sir[1]; 200 | boutsum += sir[2]; 201 | 202 | rinsum -= sir[0]; 203 | ginsum -= sir[1]; 204 | binsum -= sir[2]; 205 | 206 | yi++; 207 | } 208 | yw += w; 209 | } 210 | for (x = 0; x < w; x++) { 211 | rinsum = ginsum = binsum = routsum = goutsum = boutsum = rsum = gsum = bsum = 0; 212 | yp = -radius * w; 213 | for (i = -radius; i <= radius; i++) { 214 | yi = Math.max(0, yp) + x; 215 | 216 | sir = stack[i + radius]; 217 | 218 | sir[0] = r[yi]; 219 | sir[1] = g[yi]; 220 | sir[2] = b[yi]; 221 | 222 | rbs = r1 - Math.abs(i); 223 | 224 | rsum += r[yi] * rbs; 225 | gsum += g[yi] * rbs; 226 | bsum += b[yi] * rbs; 227 | 228 | if (i > 0) { 229 | rinsum += sir[0]; 230 | ginsum += sir[1]; 231 | binsum += sir[2]; 232 | } else { 233 | routsum += sir[0]; 234 | goutsum += sir[1]; 235 | boutsum += sir[2]; 236 | } 237 | 238 | if (i < hm) { 239 | yp += w; 240 | } 241 | } 242 | yi = x; 243 | stackpointer = radius; 244 | for (y = 0; y < h; y++) { 245 | // Preserve alpha channel: ( 0xff000000 & pix[yi] ) 246 | pix[yi] = ( 0xff000000 & pix[yi] ) | ( dv[rsum] << 16 ) | ( dv[gsum] << 8 ) | dv[bsum]; 247 | 248 | rsum -= routsum; 249 | gsum -= goutsum; 250 | bsum -= boutsum; 251 | 252 | stackstart = stackpointer - radius + div; 253 | sir = stack[stackstart % div]; 254 | 255 | routsum -= sir[0]; 256 | goutsum -= sir[1]; 257 | boutsum -= sir[2]; 258 | 259 | if (x == 0) { 260 | vmin[y] = Math.min(y + r1, hm) * w; 261 | } 262 | p = x + vmin[y]; 263 | 264 | sir[0] = r[p]; 265 | sir[1] = g[p]; 266 | sir[2] = b[p]; 267 | 268 | rinsum += sir[0]; 269 | ginsum += sir[1]; 270 | binsum += sir[2]; 271 | 272 | rsum += rinsum; 273 | gsum += ginsum; 274 | bsum += binsum; 275 | 276 | stackpointer = (stackpointer + 1) % div; 277 | sir = stack[stackpointer]; 278 | 279 | routsum += sir[0]; 280 | goutsum += sir[1]; 281 | boutsum += sir[2]; 282 | 283 | rinsum -= sir[0]; 284 | ginsum -= sir[1]; 285 | binsum -= sir[2]; 286 | 287 | yi += w; 288 | } 289 | } 290 | 291 | bitmap.setPixels(pix, 0, w, 0, 0, w, h); 292 | 293 | return (bitmap); 294 | } 295 | public static Bitmap RenderBlur(Context context, Bitmap image, int BLUR_RADIUS) { 296 | Bitmap outputBitmap = Bitmap.createBitmap(image); 297 | 298 | RenderScript rs = RenderScript.create(context); 299 | ScriptIntrinsicBlur theIntrinsic = ScriptIntrinsicBlur.create(rs, Element.U8_4(rs)); 300 | Allocation tmpIn = Allocation.createFromBitmap(rs, image); 301 | Allocation tmpOut = Allocation.createFromBitmap(rs, outputBitmap); 302 | theIntrinsic.setRadius(BLUR_RADIUS); 303 | theIntrinsic.setInput(tmpIn); 304 | theIntrinsic.forEach(tmpOut); 305 | tmpOut.copyTo(outputBitmap); 306 | 307 | return outputBitmap; 308 | } 309 | static int[][] dilate(int[][] image, int k){ 310 | image = RadialDist(image); 311 | for (int i=0; i0) image[i][j] = Math.min(image[i][j], image[i-1][j]+1); 351 | // or one more than the pixel to the west 352 | if (j>0) image[i][j] = Math.min(image[i][j], image[i][j-1]+1); 353 | } 354 | } 355 | } 356 | // traverse from bottom right to top left 357 | for (int i=image.length-1; i>=0; i--){ 358 | for (int j=image[i].length-1; j>=0; j--){ 359 | // either what we had on the first pass 360 | // or one more than the pixel to the south 361 | if (i+1 { 55 | 56 | @Override 57 | protected Boolean doInBackground(Void... voids) { 58 | boolean ret=true; 59 | if(!DeeplabProcessor.isInitialized()) 60 | ret = DeeplabProcessor.initialize(MainActivity.this); 61 | 62 | return ret; 63 | } 64 | 65 | } 66 | Toolbar toolbar; 67 | private ActionBarDrawerToggle toggle; 68 | IntentFilter statusIntentFilter = new IntentFilter( 69 | "PotraitFinished"); 70 | private MyResponseReceiver responseReceiver = 71 | new MyResponseReceiver(); 72 | private DragListView mDragListView; 73 | private GridItemAdapter mDragAdapter; 74 | private ArrayList> mItemList; 75 | 76 | private ArrayList multiSelectList; 77 | private Dbhandler dbhandler; 78 | private int ID; 79 | FragmentManager fragmentManager; 80 | SlideShowDialogFragment newFragment; 81 | private int Request_for_Points=111,Request_for_images=12321; 82 | private int spanCount=2; 83 | private boolean mIsRearrangeOn=false,mIsDragging=false; 84 | @Override 85 | protected void onCreate(Bundle savedInstanceState) { 86 | super.onCreate(savedInstanceState); 87 | setContentView(R.layout.activity_main); 88 | new InitializeModelAsyncTask().execute();//init The Processor 89 | mDragListView=findViewById(R.id.drag_list_view); 90 | mDragListView.getRecyclerView().setVerticalScrollBarEnabled(true); 91 | mDragListView.setPadding(0,12,0,0); 92 | mDragListView.setDragListListener(new DragListView.DragListListenerAdapter() { 93 | @Override 94 | public void onItemDragStarted(int position) { 95 | mIsDragging=true; 96 | } 97 | 98 | @Override 99 | public void onItemDragEnded(int fromPosition, int toPosition) { 100 | if (fromPosition != toPosition) { 101 | dbhandler.move_entry(fromPosition,toPosition); 102 | } 103 | mIsDragging=false; 104 | mDragAdapter.notifyDataSetChanged(); 105 | } 106 | }); 107 | toolbar = (Toolbar) findViewById(R.id.toolbar); 108 | setSupportActionBar(toolbar); 109 | getSupportActionBar().setDisplayHomeAsUpEnabled(false); 110 | getSupportActionBar().setDisplayShowHomeEnabled(false); 111 | 112 | dbhandler=new Dbhandler(this,null,null,1); 113 | 114 | fragmentManager=getSupportFragmentManager(); 115 | newFragment = SlideShowDialogFragment.newInstance(); 116 | SetUpGridView(); 117 | FloatingActionButton fab=findViewById(R.id.fab); 118 | fab.setOnClickListener(new View.OnClickListener() { 119 | @Override 120 | public void onClick(View view) { 121 | //Show PopUp with choice camera or storage 122 | check_permissions(); 123 | 124 | } 125 | }); 126 | 127 | } 128 | private void check_permissions(){ 129 | if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) { 130 | askPermission(); 131 | 132 | } else { 133 | ShowPopUp(); 134 | // write your logic here 135 | } 136 | } 137 | void ShowPopUp(){ 138 | CharSequence Choice[] = new CharSequence[] {"From storage", "From Camera"}; 139 | 140 | AlertDialog.Builder builder = new AlertDialog.Builder(this); 141 | builder.setTitle("From"); 142 | builder.setItems(Choice, new DialogInterface.OnClickListener() { 143 | @Override 144 | public void onClick(DialogInterface dialog, int which) { 145 | // the user clicked on colors[which] 146 | if(which==0){ 147 | ImagePicker.create(MainActivity.this) 148 | .returnMode(ReturnMode.NONE) 149 | .folderMode(true) 150 | .toolbarFolderTitle("Folder") 151 | .toolbarImageTitle("Tap to select") 152 | .showCamera(false) 153 | .single() 154 | .theme(R.style.ImagePickerTheme) 155 | .enableLog(false) 156 | .start(); 157 | }else if(which==1){ 158 | Intent intent=new Intent(MainActivity.this,OpenCamera.class); 159 | intent.putExtra("option",OpenCamera.Req_for_Image); 160 | startActivityForResult(intent,OpenCamera.Req_for_Image); 161 | } 162 | } 163 | }); 164 | builder.show(); 165 | } 166 | private void SetUpGridView(){ 167 | 168 | spanCount=2; 169 | if(Resources.getSystem().getDisplayMetrics().widthPixels>Resources.getSystem().getDisplayMetrics().heightPixels) 170 | { 171 | spanCount=3; 172 | } 173 | 174 | 175 | mDragListView.getRecyclerView().setClipToPadding(false); 176 | mDragListView.getRecyclerView().setPadding(8,0,8,8); 177 | mDragListView.setLayoutManager(new GridLayoutManager(this,spanCount)); 178 | ItemOffsetDecoration itemDecoration = new ItemOffsetDecoration(MainActivity.this, R.dimen.item_offset); 179 | mDragListView.getRecyclerView().addItemDecoration(itemDecoration); 180 | mDragListView.setCanDragHorizontally(true); 181 | mDragListView.setDragEnabled(false); 182 | getSupportActionBar().setDisplayShowTitleEnabled(true); 183 | getSupportActionBar().setTitle(getResources().getString(R.string.app_name)); 184 | mItemList=new ArrayList<>(dbhandler.rCount()); 185 | for (int i=0;i(i,dbhandler.getresult(i).path)); 187 | } 188 | mDragAdapter=new GridItemAdapter(mItemList,R.layout.grid_item,R.id.grid_item_layout,true,MainActivity.this); 189 | mDragListView.setAdapter(mDragAdapter,false); 190 | CheckIfListisEmpty(); 191 | } 192 | private void UpdateList(){ 193 | 194 | mItemList=new ArrayList<>(dbhandler.rCount()); 195 | for (int i=0;i(i,dbhandler.getresult(i).path)); 197 | } 198 | mDragAdapter=new GridItemAdapter(mItemList,R.layout.grid_item,R.id.grid_item_layout,true,MainActivity.this); 199 | mDragListView.setAdapter(mDragAdapter,false); 200 | mDragAdapter.notifyDataSetChanged(); 201 | getSupportActionBar().setTitle(getResources().getString(R.string.app_name)); 202 | CheckIfListisEmpty(); 203 | } 204 | private void CheckIfListisEmpty(){ 205 | if(mDragListView.getAdapter().getItemCount()>0){ 206 | mDragListView.setVisibility(View.VISIBLE); 207 | ((TextView)findViewById(R.id.empty_view)).setVisibility(View.GONE); 208 | }else { 209 | mDragListView.setVisibility(View.GONE); 210 | ((TextView)findViewById(R.id.empty_view)).setVisibility(View.VISIBLE); 211 | } 212 | } 213 | 214 | 215 | public void multi_select(int position) { 216 | if(multiSelectList.contains(position)){ 217 | multiSelectList.remove(Integer.valueOf(position)); 218 | }else { 219 | multiSelectList.add(position); 220 | } 221 | invalidateOptionsMenu(); 222 | getSupportActionBar().setTitle(multiSelectList.size() + "/" + dbhandler.rCount()); 223 | mDragAdapter.notifyDataSetChanged(); 224 | } 225 | 226 | @Override 227 | protected void onActivityResult(int requestCode, int resultCode, Intent data) { 228 | super.onActivityResult(requestCode, resultCode, data); 229 | if(requestCode==OpenCamera.Req_for_Image&&resultCode==RESULT_OK){ 230 | final Context context = getBaseContext(); 231 | Intent intent = new Intent(context, PortraitBlurService.class); 232 | intent.putExtra("path",data.getStringExtra("path")); 233 | startService(intent); 234 | UpdateList(); 235 | } 236 | if (ImagePicker.shouldHandle(requestCode, resultCode, data)) { 237 | // Get a list of picked images 238 | Image image = ImagePicker.getFirstImageOrNull(data); 239 | String srcPath=image.getPath(); 240 | 241 | 242 | final Context context = getBaseContext(); 243 | Intent intent = new Intent(context, PortraitBlurService.class); 244 | intent.putExtra("path",srcPath); 245 | startService(intent); 246 | UpdateList(); 247 | 248 | 249 | return; 250 | 251 | } 252 | } 253 | 254 | public void SetMultiToolbar(){ 255 | multiSelectList=new ArrayList<>(); 256 | getSupportActionBar().setDisplayHomeAsUpEnabled(true); 257 | getSupportActionBar().setTitle(0+"/"+dbhandler.rCount()); 258 | invalidateOptionsMenu(); 259 | } 260 | public void StartFragment(int position){ 261 | try { 262 | newFragment.onDestroy(); 263 | }catch (Exception e){ 264 | } 265 | //getSupportActionBar().hide(); 266 | newFragment=SlideShowDialogFragment.newInstance(); 267 | FragmentTransaction ft=fragmentManager.beginTransaction(); 268 | Bundle bundle=new Bundle(); 269 | String paths[]=new String[dbhandler.rCount()]; 270 | for(int i=0;i,GridItemAdapter.ViewHolder> { 301 | private int mLayoutId; 302 | private int mGrabHandleId; 303 | private boolean mDragOnLongPress; 304 | private int viewHeight; 305 | public boolean mIsMultiSelect=false; 306 | private Context mContext; 307 | GridItemAdapter(ArrayList> list, int layoutId, int grabHandleId, boolean dragOnLongPress, Context context){ 308 | mContext=context; 309 | mLayoutId = layoutId; 310 | mGrabHandleId = grabHandleId; 311 | mDragOnLongPress = dragOnLongPress; 312 | mContext=context; 313 | setItemList(list); 314 | } 315 | @Override 316 | public ViewHolder onCreateViewHolder(ViewGroup parent, int viewType) { 317 | View view = LayoutInflater.from(parent.getContext()).inflate(mLayoutId, parent, false); 318 | if(parent.getMeasuredHeight()>parent.getMeasuredWidth()) { 319 | viewHeight =(int)((parent.getMeasuredWidth()/spanCount)*4*1.0/3); 320 | } 321 | else viewHeight =(int)((parent.getMeasuredWidth()/spanCount)*4*1.0/3); 322 | return new ViewHolder(view); 323 | } 324 | 325 | @Override 326 | public void onBindViewHolder(final ViewHolder holder, int position) { 327 | super.onBindViewHolder(holder, position); 328 | 329 | holder.mFrameLayout.getLayoutParams().height=viewHeight; 330 | holder.mImageView.setScaleType(ImageView.ScaleType.FIT_CENTER); 331 | if(mIsMultiSelect) 332 | { 333 | holder.mCheckBox.setVisibility(View.VISIBLE); 334 | if(multiSelectList.contains(position)) 335 | holder.mCheckBox.setChecked(true); 336 | else holder.mCheckBox.setChecked(false); 337 | }else { 338 | holder.mCheckBox.setVisibility(View.GONE); 339 | } 340 | holder.mTextView.setText(""+(position+1)); 341 | holder.mTextView.setWidth(holder.mFrameLayout.getWidth()); 342 | Glide.with(mContext).load(dbhandler.getresult(position).path).apply(RequestOptions.bitmapTransform(new com.bumptech.glide.load.resource.bitmap.CenterCrop() )).into(holder.mImageView); 343 | 344 | } 345 | 346 | @Override 347 | public long getUniqueItemId(int position) { 348 | return getItemList().get(position).first; 349 | } 350 | 351 | class ViewHolder extends DragItemAdapter.ViewHolder { 352 | ImageView mImageView; 353 | TextView mTextView; 354 | FrameLayout mFrameLayout; 355 | CheckBox mCheckBox; 356 | ViewHolder(final View itemView) { 357 | super(itemView, mGrabHandleId, mDragOnLongPress); 358 | mFrameLayout=(FrameLayout)itemView.findViewById(R.id.grid_item_layout); 359 | mImageView=(ImageView)itemView.findViewById(R.id.grid_item_imageView); 360 | mTextView=(TextView)itemView.findViewById(R.id.grid_item_textView); 361 | mCheckBox=(CheckBox)itemView.findViewById(R.id.grid_item_checkbox); 362 | mCheckBox.setVisibility(View.GONE); 363 | } 364 | 365 | @Override 366 | public void onItemClicked(View view) { 367 | 368 | //start fragment from its position 369 | if(mIsMultiSelect){ 370 | mCheckBox.setVisibility(View.VISIBLE); 371 | multi_select(getAdapterPosition()); 372 | }else{ 373 | StartFragment(getAdapterPosition()); 374 | //call fragment 375 | } 376 | 377 | } 378 | 379 | @Override 380 | public boolean onItemLongClicked(View view) { 381 | //start multiselect toolbar function 382 | super.onItemLongClicked(view); 383 | if(!mIsMultiSelect) { 384 | mIsMultiSelect = true; 385 | SetMultiToolbar(); 386 | } 387 | multi_select(getAdapterPosition()); 388 | return true; 389 | } 390 | } 391 | } 392 | class ItemOffsetDecoration extends RecyclerView.ItemDecoration { 393 | 394 | private int mItemOffset; 395 | 396 | public ItemOffsetDecoration(int itemOffset) { 397 | mItemOffset = itemOffset; 398 | } 399 | 400 | public ItemOffsetDecoration(Context context,int itemOffsetId) { 401 | this(context.getResources().getDimensionPixelSize(itemOffsetId)); 402 | } 403 | 404 | @Override 405 | public void getItemOffsets(Rect outRect, View view, RecyclerView parent, 406 | RecyclerView.State state) { 407 | super.getItemOffsets(outRect, view, parent, state); 408 | outRect.set(mItemOffset, mItemOffset, mItemOffset, mItemOffset); 409 | } 410 | } 411 | void copyFile(File sourceFile, File destFile) throws IOException { 412 | if (!sourceFile.exists()) { 413 | return; 414 | } 415 | 416 | FileChannel source = null; 417 | FileChannel destination = null; 418 | source = new FileInputStream(sourceFile).getChannel(); 419 | destination = new FileOutputStream(destFile).getChannel(); 420 | if (destination != null && source != null) { 421 | destination.transferFrom(source, 0, source.size()); 422 | } 423 | if (source != null) { 424 | source.close(); 425 | } 426 | if (destination != null) { 427 | destination.close(); 428 | } 429 | 430 | 431 | } 432 | @Override 433 | protected void onPause() { 434 | super.onPause(); 435 | LocalBroadcastManager.getInstance(this).unregisterReceiver(this.responseReceiver); 436 | } 437 | @Override 438 | protected void onResume() { 439 | super.onResume(); 440 | LocalBroadcastManager.getInstance(this).registerReceiver(responseReceiver, statusIntentFilter ); 441 | mDragAdapter.notifyDataSetChanged(); 442 | if(newFragment!=null && newFragment.getDialog()!=null 443 | && newFragment.getDialog().isShowing()){ 444 | String paths[]=new String[dbhandler.rCount()]; 445 | for(int i=0;i= Build.VERSION_CODES.M) 488 | requestPermissions( 489 | new String[]{Manifest.permission 490 | .READ_EXTERNAL_STORAGE, Manifest.permission.CAMERA}, 491 | PERMISSIONS_MULTIPLE_REQUEST); 492 | } 493 | }).show(); 494 | } else { 495 | if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) 496 | requestPermissions( 497 | new String[]{Manifest.permission 498 | .READ_EXTERNAL_STORAGE, Manifest.permission.CAMERA}, 499 | PERMISSIONS_MULTIPLE_REQUEST); 500 | } 501 | } else { 502 | ShowPopUp(); 503 | // write your logic code if permission already granted 504 | } 505 | } 506 | @Override 507 | public void onRequestPermissionsResult(int requestCode, 508 | @NonNull String[] permissions, @NonNull int[] grantResults) { 509 | 510 | switch (requestCode) { 511 | case PERMISSIONS_MULTIPLE_REQUEST: 512 | if (grantResults.length > 0) { 513 | boolean cameraPermission = grantResults[1] == PackageManager.PERMISSION_GRANTED; 514 | boolean readExternalFile = grantResults[0] == PackageManager.PERMISSION_GRANTED; 515 | 516 | if(cameraPermission && readExternalFile) 517 | { 518 | ShowPopUp(); 519 | // write your logic here 520 | } else { 521 | Snackbar.make(this.findViewById(android.R.id.content), 522 | "Please Grant Permissions to enable Camera", 523 | Snackbar.LENGTH_INDEFINITE).setAction("ENABLE", 524 | new View.OnClickListener() { 525 | @Override 526 | public void onClick(View v) { 527 | if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) 528 | requestPermissions( 529 | new String[]{Manifest.permission 530 | .READ_EXTERNAL_STORAGE, Manifest.permission.CAMERA}, 531 | PERMISSIONS_MULTIPLE_REQUEST); 532 | } 533 | }).show(); 534 | } 535 | } 536 | break; 537 | } 538 | } 539 | } 540 | -------------------------------------------------------------------------------- /CameraBlur/app/src/main/java/com/anondev/gaurav/camerablur/OpenCamera.java: -------------------------------------------------------------------------------- 1 | 2 | 3 | package com.anondev.gaurav.camerablur; 4 | 5 | import android.animation.Animator; 6 | import android.animation.AnimatorListenerAdapter; 7 | import android.content.Context; 8 | import android.content.Intent; 9 | import android.content.SharedPreferences; 10 | import android.content.pm.PackageManager; 11 | import android.content.res.Resources; 12 | import android.graphics.Bitmap; 13 | import android.graphics.Matrix; 14 | import android.graphics.PointF; 15 | import android.graphics.Rect; 16 | import android.graphics.RectF; 17 | import android.hardware.Camera; 18 | import android.hardware.Camera.Size; 19 | import android.media.AudioManager; 20 | import android.media.MediaPlayer; 21 | import android.net.Uri; 22 | import android.os.Bundle; 23 | 24 | import android.os.Handler; 25 | import android.preference.PreferenceManager; 26 | import android.support.design.widget.FloatingActionButton; 27 | import android.support.v4.app.FragmentTransaction; 28 | import android.support.v7.app.AppCompatActivity; 29 | 30 | import android.util.Log; 31 | import android.view.Display; 32 | import android.view.GestureDetector; 33 | import android.view.MotionEvent; 34 | import android.view.SurfaceHolder; 35 | import android.view.SurfaceView; 36 | import android.view.View; 37 | import android.view.ViewGroup; 38 | import android.view.WindowManager; 39 | import android.view.animation.Animation; 40 | import android.widget.Button; 41 | 42 | import android.widget.ImageButton; 43 | import android.widget.ImageView; 44 | import android.widget.RelativeLayout; 45 | import android.widget.Toast; 46 | 47 | import com.github.fafaldo.fabtoolbar.widget.FABToolbarLayout; 48 | 49 | 50 | import java.io.File; 51 | import java.io.FileNotFoundException; 52 | import java.io.FileOutputStream; 53 | import java.io.IOException; 54 | import java.util.ArrayList; 55 | import java.util.Collections; 56 | import java.util.HashMap; 57 | import java.util.List; 58 | import java.util.Map; 59 | import java.util.Vector; 60 | 61 | 62 | public class OpenCamera extends AppCompatActivity implements SurfaceHolder.Callback,Camera.PictureCallback, Camera.PreviewCallback{ 63 | private MediaPlayer _shootMP = null; 64 | SurfaceView mSurfaceView; 65 | private SurfaceHolder mSurfaceHolder; 66 | private List mSupportedPreviewSizes; 67 | ImageButton capture; 68 | Camera mCamera; 69 | private boolean attemptToFocus = false; 70 | private FABToolbarLayout fabToolbarLayout; 71 | SharedPreferences mSharedPref; 72 | Boolean mFocused; 73 | Boolean mFlashMode; 74 | Boolean mBugRotate; 75 | float mDist; 76 | private Matrix matrix; 77 | private static final int REQ_FOR_SAVING=5; 78 | private int Request_for_Points=111; 79 | public static int Req_for_Marker=2,Req_for_Image=1; 80 | 81 | 82 | int total; 83 | Boolean safeToTakePicture; 84 | Boolean tmove; 85 | private OpenCamera mthis; 86 | FloatingActionButton fabToolbarButton; 87 | //public ImageProperties imagePropertiess[]; 88 | SlideShowDialogFragment newFragment = SlideShowDialogFragment.newInstance(); 89 | private FocusIndicatorView mFocusIndicaor; 90 | private int option; 91 | 92 | 93 | 94 | @Override 95 | protected void onCreate(Bundle savedInstanceState) { 96 | 97 | super.onCreate(savedInstanceState); 98 | mthis=this; 99 | setContentView(R.layout.camera); 100 | matrix= new Matrix(); 101 | getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN, 102 | WindowManager.LayoutParams.FLAG_FULLSCREEN); 103 | init(); 104 | 105 | 106 | 107 | } 108 | 109 | 110 | private void init(){ 111 | 112 | total=0; 113 | mSharedPref = PreferenceManager.getDefaultSharedPreferences(this); 114 | mFlashMode=false; 115 | tmove=true; 116 | capture=findViewById(R.id.Capture_Image); 117 | 118 | turnCameraOn(); 119 | fabToolbarLayout=(FABToolbarLayout) findViewById(R.id.fabtoolbar); 120 | fabToolbarButton = (FloatingActionButton) findViewById(R.id.fabtoolbar_fab); 121 | fabToolbarButton.setOnClickListener(new View.OnClickListener() { 122 | @Override 123 | public void onClick(View v) { 124 | fabToolbarLayout.show(); 125 | } 126 | }); 127 | final ImageView flashModeButton = (ImageView) findViewById(R.id.flash_button); 128 | flashModeButton.setOnClickListener(new View.OnClickListener() { 129 | 130 | @Override 131 | public void onClick(View v) { 132 | mFlashMode = setFlash(!mFlashMode); 133 | ((ImageView)v).setColorFilter(mFlashMode ? 0xFFFFFFFF : 0x00000000); 134 | 135 | } 136 | }); 137 | final ImageView hideButton = (ImageView) findViewById(R.id.hide_button); 138 | hideButton.setOnClickListener(new View.OnClickListener() { 139 | 140 | @Override 141 | public void onClick(View v) { 142 | fabToolbarLayout.hide(); 143 | } 144 | }); 145 | 146 | 147 | mFocusIndicaor=findViewById(R.id.af_indicator); 148 | mFocusIndicaor.showStart(); 149 | mFocusIndicaor.setVisibility(View.GONE); 150 | 151 | 152 | } 153 | public void turnCameraOn() { 154 | 155 | mSurfaceView = findViewById(R.id.surfaceView); 156 | mSurfaceHolder = mSurfaceView.getHolder(); 157 | mSurfaceHolder.addCallback(this); 158 | mSurfaceHolder.setType(SurfaceHolder.SURFACE_TYPE_PUSH_BUFFERS); 159 | mSurfaceView.setVisibility(SurfaceView.VISIBLE); 160 | final GestureDetector gestureDetector=new GestureDetector(OpenCamera.this,new GestureDetector.SimpleOnGestureListener(){ 161 | 162 | @Override 163 | public boolean onSingleTapConfirmed(MotionEvent e) { 164 | return true; 165 | } 166 | }); 167 | mSurfaceView.setOnTouchListener(new View.OnTouchListener() { 168 | @Override 169 | public boolean onTouch(View view, MotionEvent event) { 170 | Camera.Parameters params = mCamera.getParameters(); 171 | int action = event.getAction(); 172 | if (action == MotionEvent.ACTION_DOWN) { 173 | mDist = event.getY(); 174 | } 175 | if (action == MotionEvent.ACTION_UP) { 176 | 177 | if (tmove) { 178 | handleFocus(event, params); 179 | } else tmove = true; 180 | return true; 181 | } 182 | 183 | if (action == MotionEvent.ACTION_MOVE) { 184 | if (mDist!=event.getY()&¶ms.isZoomSupported()) { 185 | mCamera.cancelAutoFocus(); 186 | handleZoom(event, params); 187 | tmove = false; 188 | } 189 | return true; 190 | } 191 | // handle single touch events 192 | return true; 193 | } 194 | 195 | }); 196 | capture.setOnClickListener(new View.OnClickListener() { 197 | @Override 198 | public void onClick(View view) { 199 | requestPicture(); 200 | } 201 | }); 202 | 203 | } 204 | @Override 205 | protected void onActivityResult(int requestCode, int resultCode, Intent data) { 206 | 207 | } 208 | 209 | 210 | 211 | 212 | private void handleZoom(MotionEvent event, Camera.Parameters params) { 213 | int maxZoom = params.getMaxZoom(); 214 | int zoom = params.getZoom(); 215 | float newDist = event.getY(); 216 | if (newDist < mDist) { 217 | // zoom in 218 | if (zoom < maxZoom) 219 | zoom+=2; 220 | } else if (newDist > mDist) { 221 | // zoom out 222 | if (zoom > 0) 223 | zoom-=2; 224 | } 225 | mDist = newDist; 226 | params.setZoom(zoom); 227 | mCamera.setParameters(params); 228 | attemptToFocus=false; 229 | safeToTakePicture=true; 230 | 231 | } 232 | 233 | public void handleFocus(MotionEvent event, Camera.Parameters parameters) { 234 | attemptToFocus=true; 235 | safeToTakePicture = false; 236 | 237 | mCamera.cancelAutoFocus(); 238 | try { 239 | mFocusIndicaor.animate().cancel(); 240 | mFocusIndicaor.animate().setListener(null); 241 | }catch (Exception e){ 242 | 243 | } 244 | 245 | mFocusIndicaor.clearAnimation(); 246 | mFocusIndicaor.setVisibility(View.VISIBLE); 247 | mFocusIndicaor.setAlpha(1); 248 | 249 | 250 | RelativeLayout.LayoutParams lp = new RelativeLayout.LayoutParams( 251 | RelativeLayout.LayoutParams.WRAP_CONTENT, 252 | RelativeLayout.LayoutParams.WRAP_CONTENT); 253 | lp.setMargins(((int)event.getX() - 25),((int) event.getY() - 25), 0, 0); 254 | mFocusIndicaor.setTranslationX(event.getX() - 25); 255 | mFocusIndicaor.setTranslationY(event.getY()-25); 256 | mFocusIndicaor.animate().alpha(0.0f).setDuration(5000).setListener(new AnimatorListenerAdapter() { 257 | @Override 258 | public void onAnimationEnd(Animator animation) { 259 | super.onAnimationEnd(animation); 260 | mFocusIndicaor.setVisibility(View.GONE); 261 | } 262 | }); 263 | Rect focusRect = calculateTapArea(mSurfaceView,event.getX(), event.getY(), 1f); 264 | Rect meteringRect = calculateTapArea(mSurfaceView,event.getX(), event.getY(), 1.5f); 265 | // Toast.makeText(OpenCamera.this,event.getX()+" "+event.getY()+","+mSurfaceView.getWidth()+" "+mSurfaceView.getHeight(),Toast.LENGTH_SHORT).show(); 266 | 267 | 268 | // check if parameters are set (handle RuntimeException: getParameters failed (empty parameters)) 269 | if (parameters != null) { 270 | if(parameters.getSupportedFocusModes().contains(Camera.Parameters.FOCUS_MODE_AUTO)) 271 | parameters.setFocusMode(Camera.Parameters.FOCUS_MODE_AUTO); 272 | List areas=new ArrayList<>(); 273 | areas.add(new Camera.Area(focusRect, 1000)); 274 | parameters.setFocusAreas(areas); 275 | 276 | if (parameters.getMaxNumMeteringAreas()>0) { 277 | areas=new ArrayList<>(); 278 | areas.add(new Camera.Area(meteringRect, 1000)); 279 | parameters.setMeteringAreas(areas); 280 | } 281 | 282 | try { 283 | mCamera.setParameters(parameters); 284 | 285 | } catch (Exception e) { 286 | 287 | } 288 | } 289 | mCamera.autoFocus(new Camera.AutoFocusCallback() { 290 | @Override 291 | public void onAutoFocus(boolean b, Camera camera) { 292 | attemptToFocus=false; 293 | safeToTakePicture=true; 294 | } 295 | }); 296 | mCamera.setAutoFocusMoveCallback(new Camera.AutoFocusMoveCallback() { 297 | @Override 298 | public void onAutoFocusMoving(boolean b, Camera camera) { 299 | 300 | } 301 | }); 302 | 303 | } 304 | public Rect calculateTapArea(View v, float x1, float y1, float coefficient) { 305 | float x =mSurfaceView.getWidth()-(mSurfaceView.getHeight()-y1)*mSurfaceView.getWidth()/mSurfaceView.getHeight() ; 306 | float y =mSurfaceView.getHeight()- x1* mSurfaceView.getHeight()/ mSurfaceView.getWidth(); 307 | 308 | float focusAreaSize = 50; 309 | 310 | int areaSize = Float.valueOf(focusAreaSize * coefficient).intValue(); 311 | int centerX = (int) (x / v.getWidth() * 2000 - 1000); 312 | int centerY = (int) (y / v.getHeight() * 2000 - 1000); 313 | 314 | int left = clamp(centerX - areaSize / 2, -1000, 1000); 315 | int right = clamp(left + areaSize, -1000, 1000); 316 | int top = clamp(centerY - areaSize / 2, -1000, 1000); 317 | int bottom = clamp(top + areaSize, -1000, 1000); 318 | 319 | 320 | return new Rect(left, top, right, bottom); 321 | } 322 | private int clamp(int x, int min, int max) { 323 | if (x > max) { 324 | return max; 325 | } 326 | if (x < min) { 327 | return min; 328 | } 329 | return x; 330 | } 331 | public List getResolutionList() { 332 | return mCamera.getParameters().getSupportedPreviewSizes(); 333 | 334 | } 335 | 336 | public List getPictureResolutionList() { 337 | return mCamera.getParameters().getSupportedPictureSizes(); 338 | } 339 | public Size getMaxPreviewResolution() { 340 | int maxWidth=0; 341 | Size curRes=null; 342 | 343 | mCamera.lock(); 344 | 345 | for ( Size r: getResolutionList() ) { 346 | if (r.width>maxWidth) { 347 | maxWidth=r.width; 348 | curRes=r; 349 | } 350 | } 351 | 352 | return curRes; 353 | } 354 | public Size getMaxPictureResolution(float previewRatio) { 355 | int maxPixels=0; 356 | int ratioMaxPixels=0; 357 | Size currentMaxRes=null; 358 | Size ratioCurrentMaxRes=null; 359 | for ( Size r: getPictureResolutionList() ) { 360 | if(option==Req_for_Marker){ 361 | if(r.width<=800||r.height<=800){ 362 | float pictureRatio = (float) r.width / r.height; 363 | int resolutionPixels = r.width * r.height; 364 | 365 | if (resolutionPixels>ratioMaxPixels && pictureRatio == previewRatio) { 366 | ratioMaxPixels=resolutionPixels; 367 | ratioCurrentMaxRes=r; 368 | } 369 | 370 | if (resolutionPixels>maxPixels) { 371 | maxPixels=resolutionPixels; 372 | currentMaxRes=r; 373 | } 374 | } 375 | 376 | }else{ 377 | float pictureRatio = (float) r.width / r.height; 378 | int resolutionPixels = r.width * r.height; 379 | 380 | if (resolutionPixels>ratioMaxPixels && pictureRatio == previewRatio) { 381 | ratioMaxPixels=resolutionPixels; 382 | ratioCurrentMaxRes=r; 383 | } 384 | 385 | if (resolutionPixels>maxPixels) { 386 | maxPixels=resolutionPixels; 387 | currentMaxRes=r; 388 | }} 389 | } 390 | 391 | boolean matchAspect = mSharedPref.getBoolean("match_aspect", true); 392 | 393 | if (ratioCurrentMaxRes!=null && matchAspect) { 394 | return ratioCurrentMaxRes; 395 | } 396 | 397 | return currentMaxRes; 398 | } 399 | private int findBestCamera() { 400 | int cameraId = -1; 401 | //Search for the back facing camera 402 | //get the number of cameras 403 | int numberOfCameras = Camera.getNumberOfCameras(); 404 | //for every camera check 405 | for (int i = 0; i < numberOfCameras; i++) { 406 | Camera.CameraInfo info = new Camera.CameraInfo(); 407 | Camera.getCameraInfo(i, info); 408 | if (info.facing == Camera.CameraInfo.CAMERA_FACING_BACK) { 409 | cameraId = i; 410 | break; 411 | } 412 | cameraId = i; 413 | } 414 | return cameraId; 415 | } 416 | 417 | 418 | 419 | @Override 420 | public void surfaceCreated(SurfaceHolder surfaceHolder) { 421 | 422 | try { 423 | int cameraId = findBestCamera(); 424 | mCamera = Camera.open(cameraId); 425 | } 426 | 427 | catch (RuntimeException e) { 428 | return; 429 | } 430 | 431 | Camera.Parameters param; 432 | param = mCamera.getParameters(); 433 | 434 | Size pSize = getMaxPreviewResolution(); 435 | param.setPreviewSize(pSize.width, pSize.height); 436 | 437 | float previewRatio = (float) pSize.width / pSize.height; 438 | 439 | Display display = getWindowManager().getDefaultDisplay(); 440 | android.graphics.Point size = new android.graphics.Point(); 441 | display.getRealSize(size); 442 | 443 | int displayWidth = Math.min(size.y, size.x); 444 | int displayHeight = Math.max(size.y, size.x); 445 | 446 | float displayRatio = (float) displayHeight / displayWidth; 447 | 448 | int previewHeight = displayHeight; 449 | 450 | if ( displayRatio > previewRatio ) { 451 | ViewGroup.LayoutParams surfaceParams = mSurfaceView.getLayoutParams(); 452 | previewHeight = (int) ( (float) size.y/displayRatio*previewRatio); 453 | surfaceParams.height = previewHeight; 454 | mSurfaceView.setLayoutParams(surfaceParams); 455 | 456 | 457 | } 458 | 459 | int hotAreaWidth = displayWidth / 4; 460 | int hotAreaHeight = previewHeight / 2 - hotAreaWidth; 461 | 462 | Size maxRes = getMaxPictureResolution(previewRatio); 463 | if ( maxRes != null) { 464 | param.setPictureSize(maxRes.width, maxRes.height); 465 | } 466 | 467 | PackageManager pm = getPackageManager(); 468 | if (pm.hasSystemFeature(PackageManager.FEATURE_CAMERA_AUTOFOCUS)) { 469 | param.setFocusMode(Camera.Parameters.FOCUS_MODE_CONTINUOUS_PICTURE); 470 | 471 | } else { 472 | mFocused = true; 473 | 474 | } 475 | if (pm.hasSystemFeature(PackageManager.FEATURE_CAMERA_FLASH)) { 476 | param.setFlashMode(mFlashMode ? Camera.Parameters.FLASH_MODE_ON : Camera.Parameters.FLASH_MODE_OFF); 477 | } 478 | mSupportedPreviewSizes=getResolutionList(); 479 | param.setRotation(90); 480 | param.setJpegQuality(75); 481 | mCamera.setParameters(param); 482 | 483 | mBugRotate = mSharedPref.getBoolean("bug_rotate", false); 484 | 485 | if (mBugRotate) { 486 | mCamera.setDisplayOrientation(270); 487 | } else { 488 | mCamera.setDisplayOrientation(90); 489 | } 490 | try { 491 | mCamera.setAutoFocusMoveCallback(new Camera.AutoFocusMoveCallback() { 492 | @Override 493 | public void onAutoFocusMoving(boolean start, Camera camera) { 494 | mFocused = !start; 495 | 496 | } 497 | }); 498 | } catch (Exception e) { 499 | } 500 | 501 | // some devices doesn't call the AutoFocusMoveCallback - fake the 502 | // focus to true at the start 503 | 504 | mFocused = true; 505 | safeToTakePicture = true; 506 | } 507 | 508 | 509 | 510 | @Override 511 | public void surfaceChanged(SurfaceHolder surfaceHolder, int i, int width, int height) { 512 | refreshCamera(); 513 | Matrix matrix = new Matrix(); 514 | 515 | matrix.postScale(width / 2000f, height / 2000f); 516 | matrix.postTranslate(width / 2f, height / 2f); 517 | matrix.invert(this.matrix); 518 | } 519 | private void refreshCamera() { 520 | 521 | try { 522 | 523 | mCamera.stopPreview(); 524 | } 525 | 526 | catch (Exception e) { 527 | } 528 | 529 | try { 530 | mCamera.setPreviewDisplay(mSurfaceHolder); 531 | mCamera.startPreview(); 532 | mCamera.setPreviewCallbackWithBuffer(this); 533 | } 534 | catch (Exception e) { 535 | } 536 | safeToTakePicture=true; 537 | attemptToFocus=false; 538 | } 539 | @Override 540 | public void surfaceDestroyed(SurfaceHolder surfaceHolder) { 541 | if (mCamera != null) { 542 | mCamera.stopPreview(); 543 | mCamera.setPreviewCallback(null); 544 | mCamera.release(); 545 | mCamera = null; 546 | } 547 | 548 | } 549 | @Override 550 | public void onPreviewFrame(byte[] data, Camera camera) { 551 | 552 | } 553 | 554 | public boolean requestPicture() { 555 | 556 | if (safeToTakePicture&&!(newFragment!=null && newFragment.getDialog()!=null 557 | && newFragment.getDialog().isShowing())) { 558 | if(!safeToTakePicture) 559 | return true; 560 | safeToTakePicture = false; 561 | mCamera.cancelAutoFocus(); 562 | mCamera.takePicture(null,null,mthis); 563 | return true; 564 | } 565 | return false; 566 | } 567 | 568 | @Override 569 | public void onPictureTaken(byte[] bytes, Camera camera) { 570 | shootSound(); 571 | String path; 572 | Size pictureSize = camera.getParameters().getPictureSize(); 573 | path=Save(); 574 | 575 | FileOutputStream fos = null; 576 | File file=new File(path); 577 | try { 578 | 579 | fos = new FileOutputStream(file); 580 | // Writes bytes from the specified byte array to this file output stream 581 | try { 582 | fos.write(bytes); 583 | }catch (IOException e){} 584 | } 585 | catch (FileNotFoundException e) {} 586 | bytes=null; 587 | int width=pictureSize.width,height=pictureSize.height; 588 | /*Intent intent=new Intent(); 589 | intent.putExtra("path",path); 590 | intent.putExtra("height",height); 591 | intent.putExtra("width",width); 592 | setResult(RESULT_OK,intent); 593 | finish();*/ 594 | String paths[]=new String[1]; 595 | paths[0]=path; 596 | StartFragment(paths,1,1); 597 | refreshCamera(); 598 | safeToTakePicture = true; 599 | } 600 | public String Save(){ 601 | try {File image = File.createTempFile( 602 | "Orig", /* prefix */ 603 | ".jpg", /* suffix */ 604 | getExternalFilesDir("Pictures") /* directory */ 605 | ); 606 | return image.getAbsolutePath(); 607 | } catch (IOException ex) { 608 | // Error occurred while creating the File 609 | } 610 | return null; 611 | } 612 | 613 | 614 | private void shootSound() 615 | { 616 | AudioManager meng = (AudioManager) getSystemService(Context.AUDIO_SERVICE); 617 | int volume = meng.getStreamVolume(AudioManager.STREAM_NOTIFICATION); 618 | 619 | if (volume != 0) 620 | { 621 | if (_shootMP == null) { 622 | _shootMP = MediaPlayer.create(this, Uri.parse("file:///system/media/audio/ui/camera_click.ogg")); 623 | } 624 | if (_shootMP != null) { 625 | _shootMP.start(); 626 | } 627 | } 628 | } 629 | 630 | public void results_from_camera(String path) 631 | {newFragment.onStop(); 632 | Intent intent=new Intent(); 633 | intent.putExtra("path",path); 634 | setResult(RESULT_OK,intent); 635 | finish(); 636 | 637 | } 638 | public boolean setFlash(boolean stateFlash) { 639 | PackageManager pm = getPackageManager(); 640 | if (pm.hasSystemFeature(PackageManager.FEATURE_CAMERA_FLASH)) { 641 | Camera.Parameters par = mCamera.getParameters(); 642 | if(par.getSupportedFlashModes().contains(Camera.Parameters.FLASH_MODE_ON)) 643 | { 644 | par.setFlashMode(stateFlash ? Camera.Parameters.FLASH_MODE_ON : Camera.Parameters.FLASH_MODE_OFF); 645 | mCamera.setParameters(par); 646 | }else { 647 | par.setFlashMode(stateFlash ? Camera.Parameters.FLASH_MODE_TORCH : Camera.Parameters.FLASH_MODE_OFF); 648 | mCamera.setParameters(par); 649 | } 650 | return stateFlash; 651 | } 652 | return false; 653 | } 654 | 655 | public void StartFragment(String[] path,int position,int total){ 656 | FragmentTransaction ft=getSupportFragmentManager().beginTransaction(); 657 | Bundle bundle=new Bundle(); 658 | bundle.putStringArray("path",path); 659 | bundle.putInt("position",position); 660 | bundle.putInt("total",total); 661 | newFragment.setArguments(bundle); 662 | newFragment.show(ft, "slideshow"); 663 | } 664 | public void tost(String x){ 665 | Toast.makeText(this,x,Toast.LENGTH_SHORT).show(); 666 | } 667 | 668 | } 669 | -------------------------------------------------------------------------------- /CameraBlur/app/src/main/java/com/anondev/gaurav/camerablur/PortraitBlurService.java: -------------------------------------------------------------------------------- 1 | package com.anondev.gaurav.camerablur; 2 | 3 | import android.app.IntentService; 4 | import android.app.Notification; 5 | import android.app.NotificationChannel; 6 | import android.app.NotificationManager; 7 | import android.content.Context; 8 | import android.content.Intent; 9 | import android.graphics.Bitmap; 10 | import android.graphics.Color; 11 | import android.os.Build; 12 | import android.support.v4.content.LocalBroadcastManager; 13 | import android.util.Log; 14 | 15 | import java.io.File; 16 | import java.io.FileOutputStream; 17 | import java.io.IOException; 18 | import java.nio.ByteBuffer; 19 | 20 | 21 | public class PortraitBlurService extends IntentService { 22 | private static int FOREGROUND_ID=1337; 23 | String image_path; 24 | public PortraitBlurService() { 25 | super("PortraitBlurService"); 26 | } 27 | 28 | @Override 29 | protected void onHandleIntent(Intent intent) { 30 | image_path=(String)intent.getExtras().get("path"); 31 | Dbhandler dbhandler=new Dbhandler(this,null,null,1); 32 | Notification notification; 33 | String CHANNEL_ID = "com.anondev.gaurav.camerablur.PortraitBlurService"; 34 | String CHANNEL_NAME = "Channel One"; 35 | NotificationChannel notificationChannel = null; 36 | NotificationManager notificationManager=(NotificationManager) getSystemService(Context.NOTIFICATION_SERVICE); 37 | 38 | if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) { 39 | notificationChannel = new NotificationChannel(CHANNEL_ID, 40 | CHANNEL_NAME, NotificationManager.IMPORTANCE_HIGH); 41 | notificationChannel.enableLights(true); 42 | notificationChannel.setLightColor(Color.RED); 43 | notificationChannel.setShowBadge(true); 44 | notificationChannel.setLockscreenVisibility(Notification.VISIBILITY_PUBLIC); 45 | notificationManager.createNotificationChannel(notificationChannel); 46 | notification = new Notification.Builder(getApplicationContext(), CHANNEL_ID) 47 | .setContentTitle("Processing Image") 48 | .setContentText("Processing..") 49 | .setSmallIcon(android.R.drawable.stat_notify_sync). 50 | setTicker("Processing I..").build(); 51 | }else { 52 | notification = new Notification.Builder(this) 53 | .setContentTitle("Processing Image") 54 | .setContentText("Processing..") 55 | .setSmallIcon(android.R.drawable.stat_notify_sync). 56 | setTicker("Processing I..").build(); 57 | } 58 | 59 | startForeground(FOREGROUND_ID,notification); 60 | if(!DeeplabProcessor.isInitialized()) 61 | DeeplabProcessor.initialize(getBaseContext()); 62 | Bitmap bitmap=ImageUtils.decodeBitmapFromFile(image_path,DeeplabProcessor.INPUT_SIZE,DeeplabProcessor.INPUT_SIZE); 63 | if(bitmap==null) 64 | Log.e("PotraitBlur","Null Bitmap"); 65 | final int w = bitmap.getWidth(); 66 | final int h = bitmap.getHeight(); 67 | float resizeRatio = (float) DeeplabProcessor.INPUT_SIZE / Math.max(bitmap.getWidth(), bitmap.getHeight()); 68 | int rw = Math.round(w * resizeRatio); 69 | int rh = Math.round(h * resizeRatio); 70 | 71 | bitmap = ImageUtils.tfResizeBilinear(bitmap, rw, rh); 72 | int ar[]=DeeplabProcessor.GetBlurredImage(bitmap); 73 | bitmap=getBitmap(ar,bitmap,7,4); 74 | 75 | 76 | FileOutputStream out = null; 77 | 78 | if(bitmap!=null) 79 | try { 80 | entry e=new entry(); 81 | File dst = File.createTempFile( 82 | "Blurred", /* prefix */ 83 | ".jpg", /* suffix */ 84 | getExternalFilesDir("Pictures") /* directory */ 85 | ); 86 | out = new FileOutputStream(dst); 87 | bitmap.compress(Bitmap.CompressFormat.JPEG, 100, out); 88 | e.setPath(dst.getPath()); 89 | dst = File.createTempFile( 90 | "SegMap", /* prefix */ 91 | ".mp", /* suffix */ 92 | getExternalFilesDir("Map") /* directory */ 93 | ); 94 | out = new FileOutputStream(dst); 95 | ByteBuffer byteBuffer = ByteBuffer.allocate(ar.length * 4); 96 | byteBuffer.asIntBuffer().put(ar); 97 | out.write(byteBuffer.array()); 98 | e.setMap(dst.getPath()); 99 | dbhandler.addRow(e); 100 | Intent localIntent = new Intent("PotraitFinished"); 101 | // Broadcasts the Intent to receivers in this app. 102 | LocalBroadcastManager.getInstance(this).sendBroadcast(localIntent); 103 | 104 | } catch (Exception e) { 105 | e.printStackTrace(); 106 | } finally { 107 | try { 108 | if (out != null) { 109 | out.close(); 110 | } 111 | } catch (IOException e) { 112 | e.printStackTrace(); 113 | } 114 | } 115 | else Log.e("PotraitBlur","Null Bitmap"); 116 | stopForeground(true); 117 | } 118 | public Bitmap getBitmap(int mOutputs[],Bitmap bitmap,int bRad,int eRad){ 119 | final int w = bitmap.getWidth(); 120 | final int h = bitmap.getHeight(); 121 | Bitmap output = Bitmap.createBitmap(w, h, Bitmap.Config.ARGB_8888); 122 | Bitmap blur=ImageUtils.RenderBlur(PortraitBlurService.this,bitmap,bRad); 123 | Bitmap softBlur=ImageUtils.RenderBlur(PortraitBlurService.this, bitmap,eRad); 124 | 125 | int imgMatrixEroded[][]=new int[w][h]; 126 | int imgMatrixDilated[][]=new int[w][h]; 127 | for (int y = 0; y < h; y++) { 128 | for (int x = 0; x < w; x++) { 129 | imgMatrixEroded[x][y]=imgMatrixDilated[x][y]=mOutputs[y * w + x]; 130 | } 131 | } 132 | imgMatrixDilated=ImageUtils.dilate(imgMatrixDilated,1); 133 | imgMatrixEroded=ImageUtils.erode(imgMatrixEroded,2); 134 | for (int y = 0; y < h; y++) { 135 | for (int x = 0; x < w; x++) { 136 | output.setPixel(x, y,imgMatrixDilated[x][y]==1 ? (imgMatrixEroded[x][y]==1?bitmap.getPixel(x,y):softBlur.getPixel(x,y)):blur.getPixel(x,y)); 137 | } 138 | } 139 | return output; 140 | } 141 | 142 | 143 | } 144 | -------------------------------------------------------------------------------- /CameraBlur/app/src/main/java/com/anondev/gaurav/camerablur/SlideShowDialogFragment.java: -------------------------------------------------------------------------------- 1 | package com.anondev.gaurav.camerablur; 2 | 3 | /** 4 | * Created by Gaurav on 10/15/2017. 5 | */ 6 | 7 | import android.app.Activity; 8 | import android.content.Context; 9 | import android.content.DialogInterface; 10 | import android.content.Intent; 11 | import android.graphics.Color; 12 | import android.graphics.PointF; 13 | import android.graphics.drawable.Drawable; 14 | import android.net.Uri; 15 | import android.os.Bundle;/* 16 | import android.support.design.internal.NavigationMenuView; 17 | import android.support.design.widget.NavigationView;*/ 18 | import android.support.v4.app.DialogFragment; 19 | import android.support.v4.view.PagerAdapter; 20 | import android.support.v4.view.ViewPager; 21 | import android.support.v7.app.AppCompatActivity; 22 | import android.support.v7.view.menu.MenuBuilder; 23 | import android.support.v7.widget.Toolbar; 24 | import android.util.Log; 25 | import android.view.LayoutInflater; 26 | import android.view.Menu; 27 | import android.view.MenuInflater; 28 | import android.view.MenuItem; 29 | import android.view.View; 30 | import android.view.ViewGroup; 31 | import android.widget.Button; 32 | import android.widget.ImageButton; 33 | import android.widget.ImageView; 34 | import android.widget.TextView; 35 | import android.widget.Toast; 36 | 37 | import com.bumptech.glide.Glide; 38 | import com.bumptech.glide.TransitionOptions; 39 | import com.bumptech.glide.load.engine.DiskCacheStrategy; 40 | import com.bumptech.glide.request.RequestOptions; 41 | import com.bumptech.glide.request.transition.DrawableCrossFadeFactory; 42 | import com.bumptech.glide.request.transition.Transition; 43 | import com.bumptech.glide.request.transition.TransitionFactory; 44 | import com.bumptech.glide.request.transition.ViewAnimationFactory; 45 | import com.davemorrissey.labs.subscaleview.ImageSource; 46 | import com.davemorrissey.labs.subscaleview.SubsamplingScaleImageView; 47 | 48 | 49 | 50 | import java.io.File; 51 | import java.util.ArrayList; 52 | import java.util.HashMap; 53 | import java.util.Map; 54 | 55 | 56 | import static android.app.Activity.RESULT_OK; 57 | 58 | public class SlideShowDialogFragment extends DialogFragment { 59 | private String TAG = SlideShowDialogFragment.class.getSimpleName(); 60 | private String[] images; 61 | private int size; 62 | private ViewPager viewPager; 63 | public MyViewPagerAdapter myViewPagerAdapter; 64 | private int selectedPosition = 0; 65 | public int currentPosition=0; 66 | ImageButton save; 67 | Toolbar toolbar; 68 | 69 | @Override 70 | public void onCancel(DialogInterface dialog) { 71 | super.onCancel(dialog); 72 | } 73 | 74 | static SlideShowDialogFragment newInstance() { 75 | SlideShowDialogFragment f = new SlideShowDialogFragment(); 76 | return f; 77 | } 78 | @Override 79 | public View onCreateView(LayoutInflater inflater, ViewGroup container,Bundle savedInstanceState) { 80 | View v = inflater.inflate(R.layout.fragment_image_slider, container, false); 81 | viewPager = (ViewPager) v.findViewById(R.id.viewpager); 82 | setHasOptionsMenu(true); 83 | toolbar=(Toolbar)v.findViewById(R.id.slider_toolbar); 84 | save=v.findViewById(R.id.save_Item); 85 | setToolbar(); 86 | //((AppCompatActivity)getActivity()).setSupportActionBar(toolbar); 87 | images=getArguments().getStringArray("path"); 88 | selectedPosition = getArguments().getInt("position"); 89 | size=getArguments().getInt("total"); 90 | myViewPagerAdapter = new MyViewPagerAdapter(); 91 | viewPager.setPageTransformer(true,new ZoomOutPageTransformer()); 92 | viewPager.setAdapter(myViewPagerAdapter); 93 | viewPager.addOnPageChangeListener(viewPagerPageChangeListener); 94 | setCurrentItem(selectedPosition); 95 | 96 | return v; 97 | } 98 | private void setToolbar(){ 99 | if(getActivity().getClass()==MainActivity.class) 100 | save.setVisibility(View.GONE); 101 | save.setOnClickListener(new View.OnClickListener() { 102 | @Override 103 | public void onClick(View view) { 104 | if (getActivity().getClass() == OpenCamera.class) { 105 | ((OpenCamera)getActivity()).results_from_camera(images[0]);} 106 | } 107 | }); 108 | toolbar.setTitle(R.string.app_name); 109 | } 110 | 111 | /* @Override 112 | public void onResume() { 113 | super.onResume(); 114 | // ((AppCompatActivity)getActivity()).getSupportActionBar().hide(); 115 | } 116 | 117 | @Override 118 | public void onStop() { 119 | super.onStop(); 120 | { 121 | if( getActivity().getClass()==MainActivity.class) 122 | { 123 | ((AppCompatActivity) getActivity()).getSupportActionBar().show(); 124 | ((MainActivity)getActivity()).setSupportActionBar(((MainActivity)getActivity()).toolbar); 125 | ((MainActivity)getActivity()).resetToolbar(); 126 | } 127 | } 128 | } 129 | 130 | */ 131 | 132 | 133 | 134 | private void setCurrentItem(final int position) { 135 | 136 | viewPager.setCurrentItem(position, false); 137 | displayMetaInfo(selectedPosition); 138 | } 139 | 140 | // page change listener 141 | ViewPager.OnPageChangeListener viewPagerPageChangeListener = new ViewPager.OnPageChangeListener() { 142 | 143 | @Override 144 | public void onPageSelected(int position) { 145 | displayMetaInfo(position); 146 | currentPosition=position; 147 | } 148 | @Override 149 | public void onPageScrolled(int arg0, float arg1, int arg2) { 150 | } 151 | @Override 152 | public void onPageScrollStateChanged(int arg0) { 153 | } 154 | }; 155 | 156 | private void displayMetaInfo(int position) { 157 | 158 | 159 | } 160 | 161 | 162 | @Override 163 | public void onCreate(Bundle savedInstanceState) { 164 | super.onCreate(savedInstanceState); 165 | setStyle(DialogFragment.STYLE_NORMAL, android.R.style.Theme_Black_NoTitleBar_Fullscreen); 166 | } 167 | public void Update(String[] newPath){ 168 | images=newPath; 169 | myViewPagerAdapter.notifyDataSetChanged(); 170 | } 171 | 172 | // adapter 173 | public class MyViewPagerAdapter extends PagerAdapter { 174 | 175 | private LayoutInflater layoutInflater; 176 | 177 | public MyViewPagerAdapter() { 178 | } 179 | @Override 180 | public Object instantiateItem(ViewGroup container, int position) { 181 | layoutInflater = (LayoutInflater) getActivity().getSystemService(Context.LAYOUT_INFLATER_SERVICE); 182 | View view = layoutInflater.inflate(R.layout.full_screen_image, container, false); 183 | SubsamplingScaleImageView imageViewPreview = (SubsamplingScaleImageView) view.findViewById(R.id.imgDisplay); 184 | 185 | imageViewPreview.setMinimumScaleType(SubsamplingScaleImageView.SCALE_TYPE_CUSTOM); 186 | imageViewPreview.setMinimumTileDpi(200); 187 | 188 | imageViewPreview.setImage(ImageSource.uri(images[position])); 189 | 190 | imageViewPreview.setOnClickListener(new View.OnClickListener() { 191 | @Override 192 | public void onClick(View view) { 193 | toggle_bar(); 194 | } 195 | }); 196 | imageViewPreview.setTag(position); 197 | view.setTag(position); 198 | container.addView(view); 199 | return view; 200 | } 201 | void toggle_bar(){ 202 | 203 | if(toolbar.getVisibility()==View.VISIBLE) 204 | toolbar.setVisibility(View.GONE); 205 | else toolbar.setVisibility(View.VISIBLE); 206 | } 207 | 208 | 209 | @Override 210 | public int getCount() { 211 | return size; 212 | } 213 | 214 | @Override 215 | public boolean isViewFromObject(View view, Object obj) { 216 | return view == ((View) obj); 217 | } 218 | 219 | @Override 220 | public int getItemPosition(Object object) { 221 | return POSITION_NONE; 222 | } 223 | 224 | @Override 225 | public void destroyItem(ViewGroup container, int position, Object object) { 226 | container.removeView((View) object); 227 | } 228 | } 229 | 230 | 231 | } -------------------------------------------------------------------------------- /CameraBlur/app/src/main/java/com/anondev/gaurav/camerablur/ZoomOutPageTransformer.java: -------------------------------------------------------------------------------- 1 | package com.anondev.gaurav.camerablur; 2 | 3 | import android.support.v4.view.ViewPager; 4 | import android.view.View; 5 | 6 | /** 7 | * Created by Gaurav on 10/16/2017. 8 | */ 9 | 10 | public class ZoomOutPageTransformer implements ViewPager.PageTransformer { 11 | private static final float MIN_SCALE = 0.85f; 12 | private static final float MIN_ALPHA = 0.5f; 13 | 14 | public void transformPage(View view, float position) { 15 | int pageWidth = view.getWidth(); 16 | int pageHeight = view.getHeight(); 17 | 18 | if (position < -1) { // [-Infinity,-1) 19 | // This page is way off-screen to the left. 20 | view.setAlpha(0); 21 | 22 | } else if (position <= 1) { // [-1,1] 23 | // Modify the default slide transition to shrink the page as well 24 | float scaleFactor = Math.max(MIN_SCALE, 1 - Math.abs(position)); 25 | float vertMargin = pageHeight * (1 - scaleFactor) / 2; 26 | float horzMargin = pageWidth * (1 - scaleFactor) / 2; 27 | if (position < 0) { 28 | view.setTranslationX(horzMargin - vertMargin / 2); 29 | } else { 30 | view.setTranslationX(-horzMargin + vertMargin / 2); 31 | } 32 | 33 | // Scale the page down (between MIN_SCALE and 1) 34 | view.setScaleX(scaleFactor); 35 | view.setScaleY(scaleFactor); 36 | 37 | // Fade the page relative to its size. 38 | view.setAlpha(MIN_ALPHA + 39 | (scaleFactor - MIN_SCALE) / 40 | (1 - MIN_SCALE) * (1 - MIN_ALPHA)); 41 | 42 | } else { // (1,+Infinity] 43 | // This page is way off-screen to the right. 44 | view.setAlpha(0); 45 | } 46 | } 47 | } -------------------------------------------------------------------------------- /CameraBlur/app/src/main/java/com/anondev/gaurav/camerablur/entry.java: -------------------------------------------------------------------------------- 1 | package com.anondev.gaurav.camerablur; 2 | 3 | import java.io.Serializable; 4 | 5 | public class entry implements Serializable { 6 | int _id; 7 | String path,map; 8 | 9 | public int get_id() { 10 | return _id; 11 | } 12 | 13 | public void set_id(int _id) { 14 | this._id = _id; 15 | } 16 | 17 | public String getPath() { 18 | return path; 19 | } 20 | 21 | public void setPath(String path) { 22 | this.path = path; 23 | } 24 | 25 | public String getMap() { 26 | return map; 27 | } 28 | 29 | public void setMap(String map) { 30 | this.map = map; 31 | } 32 | } 33 | -------------------------------------------------------------------------------- /CameraBlur/app/src/main/res/drawable-v24/ic_launcher_foreground.xml: -------------------------------------------------------------------------------- 1 | 7 | 12 | 13 | 19 | 22 | 25 | 26 | 27 | 28 | 34 | 35 | -------------------------------------------------------------------------------- /CameraBlur/app/src/main/res/drawable-v24/ic_menu_camera.xml: -------------------------------------------------------------------------------- 1 | 6 | 9 | 12 | 13 | -------------------------------------------------------------------------------- /CameraBlur/app/src/main/res/drawable/circle.xml: -------------------------------------------------------------------------------- 1 | 2 | 4 | 5 | 6 | 7 | 10 | 11 | 14 | 15 | -------------------------------------------------------------------------------- /CameraBlur/app/src/main/res/drawable/focus_indicator.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 7 | -------------------------------------------------------------------------------- /CameraBlur/app/src/main/res/drawable/ic_check_black_24dp.xml: -------------------------------------------------------------------------------- 1 | 6 | 9 | 10 | -------------------------------------------------------------------------------- /CameraBlur/app/src/main/res/drawable/ic_clear_black_24dp.xml: -------------------------------------------------------------------------------- 1 | 6 | 9 | 10 | -------------------------------------------------------------------------------- /CameraBlur/app/src/main/res/drawable/ic_flash_on_black_24dp.xml: -------------------------------------------------------------------------------- 1 | 6 | 9 | 10 | -------------------------------------------------------------------------------- /CameraBlur/app/src/main/res/drawable/ic_launcher_background.xml: -------------------------------------------------------------------------------- 1 | 2 | 7 | 10 | 15 | 20 | 25 | 30 | 35 | 40 | 45 | 50 | 55 | 60 | 65 | 70 | 75 | 80 | 85 | 90 | 95 | 100 | 105 | 110 | 115 | 120 | 125 | 130 | 135 | 140 | 145 | 150 | 155 | 160 | 165 | 170 | 171 | -------------------------------------------------------------------------------- /CameraBlur/app/src/main/res/drawable/item_bg_menu.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | -------------------------------------------------------------------------------- /CameraBlur/app/src/main/res/layout/activity_main.xml: -------------------------------------------------------------------------------- 1 | 2 | 8 | 9 | 13 | 21 | -------------------------------------------------------------------------------- /CameraBlur/app/src/main/res/layout/app_bar_main.xml: -------------------------------------------------------------------------------- 1 | 2 | 8 | 9 | 15 | 16 | 23 | 24 | 25 | 26 | 27 | 28 | 34 | 35 | 36 | -------------------------------------------------------------------------------- /CameraBlur/app/src/main/res/layout/camera.xml: -------------------------------------------------------------------------------- 1 | 8 | 9 | 15 | 21 | 22 | 27 | 28 | 40 | 41 | 42 | 48 | 49 | 61 | 62 | 63 | 64 | 70 | 71 | 79 | 80 | 87 | 88 | 95 | 96 | 97 | 98 | 99 | 100 | 101 | 102 | 103 | 110 | 111 | 112 | 113 | 114 | 115 | 116 | 117 | 118 | 119 | 131 | 132 | 133 | 134 | 135 | 136 | 137 | 138 | 139 | 140 | 141 | 142 | 143 | 144 | -------------------------------------------------------------------------------- /CameraBlur/app/src/main/res/layout/fragment_image_slider.xml: -------------------------------------------------------------------------------- 1 | 2 | 6 | 7 | 12 | 13 | 20 | 31 | 32 | 33 | 34 | 35 | 36 | 37 | 38 | 39 | 40 | -------------------------------------------------------------------------------- /CameraBlur/app/src/main/res/layout/full_screen_image.xml: -------------------------------------------------------------------------------- 1 | 2 | 9 | 14 | 15 | 16 | 25 | 26 | 27 | 28 | 29 | -------------------------------------------------------------------------------- /CameraBlur/app/src/main/res/layout/grid_item.xml: -------------------------------------------------------------------------------- 1 | 2 | 8 | 9 | 14 | 20 | 21 | 31 | 32 | -------------------------------------------------------------------------------- /CameraBlur/app/src/main/res/layout/list_layout.xml: -------------------------------------------------------------------------------- 1 | 2 | 8 | 9 | 10 | 12 | 16 | 17 | 22 | 23 | 24 | 29 | 39 | 40 | 41 | 42 | 43 | 44 | 45 | -------------------------------------------------------------------------------- /CameraBlur/app/src/main/res/mipmap-anydpi-v26/ic_launcher.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | -------------------------------------------------------------------------------- /CameraBlur/app/src/main/res/mipmap-anydpi-v26/ic_launcher_round.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | -------------------------------------------------------------------------------- /CameraBlur/app/src/main/res/mipmap-hdpi/ic_launcher.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Gauravv97/CameraBlur/b3b80ad9d8492c76957c3d7c4aa5e9a0cb7bf1f3/CameraBlur/app/src/main/res/mipmap-hdpi/ic_launcher.png -------------------------------------------------------------------------------- /CameraBlur/app/src/main/res/mipmap-hdpi/ic_launcher_round.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Gauravv97/CameraBlur/b3b80ad9d8492c76957c3d7c4aa5e9a0cb7bf1f3/CameraBlur/app/src/main/res/mipmap-hdpi/ic_launcher_round.png -------------------------------------------------------------------------------- /CameraBlur/app/src/main/res/mipmap-mdpi/ic_launcher.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Gauravv97/CameraBlur/b3b80ad9d8492c76957c3d7c4aa5e9a0cb7bf1f3/CameraBlur/app/src/main/res/mipmap-mdpi/ic_launcher.png -------------------------------------------------------------------------------- /CameraBlur/app/src/main/res/mipmap-mdpi/ic_launcher_round.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Gauravv97/CameraBlur/b3b80ad9d8492c76957c3d7c4aa5e9a0cb7bf1f3/CameraBlur/app/src/main/res/mipmap-mdpi/ic_launcher_round.png -------------------------------------------------------------------------------- /CameraBlur/app/src/main/res/mipmap-xhdpi/ic_launcher.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Gauravv97/CameraBlur/b3b80ad9d8492c76957c3d7c4aa5e9a0cb7bf1f3/CameraBlur/app/src/main/res/mipmap-xhdpi/ic_launcher.png -------------------------------------------------------------------------------- /CameraBlur/app/src/main/res/mipmap-xhdpi/ic_launcher_round.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Gauravv97/CameraBlur/b3b80ad9d8492c76957c3d7c4aa5e9a0cb7bf1f3/CameraBlur/app/src/main/res/mipmap-xhdpi/ic_launcher_round.png -------------------------------------------------------------------------------- /CameraBlur/app/src/main/res/mipmap-xxhdpi/ic_launcher.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Gauravv97/CameraBlur/b3b80ad9d8492c76957c3d7c4aa5e9a0cb7bf1f3/CameraBlur/app/src/main/res/mipmap-xxhdpi/ic_launcher.png -------------------------------------------------------------------------------- /CameraBlur/app/src/main/res/mipmap-xxhdpi/ic_launcher_round.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Gauravv97/CameraBlur/b3b80ad9d8492c76957c3d7c4aa5e9a0cb7bf1f3/CameraBlur/app/src/main/res/mipmap-xxhdpi/ic_launcher_round.png -------------------------------------------------------------------------------- /CameraBlur/app/src/main/res/mipmap-xxxhdpi/ic_launcher.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Gauravv97/CameraBlur/b3b80ad9d8492c76957c3d7c4aa5e9a0cb7bf1f3/CameraBlur/app/src/main/res/mipmap-xxxhdpi/ic_launcher.png -------------------------------------------------------------------------------- /CameraBlur/app/src/main/res/mipmap-xxxhdpi/ic_launcher_round.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Gauravv97/CameraBlur/b3b80ad9d8492c76957c3d7c4aa5e9a0cb7bf1f3/CameraBlur/app/src/main/res/mipmap-xxxhdpi/ic_launcher_round.png -------------------------------------------------------------------------------- /CameraBlur/app/src/main/res/values/colors.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | @android:color/holo_green_dark 4 | @android:color/holo_green_dark 5 | #FF4081 6 | #ff59a9ff 7 | #ffff900d 8 | #ffc4c2bc 9 | #000000 10 | #ffffff 11 | #ff59a9ff 12 | #90e5f8ff 13 | #AACCCCCC 14 | #82000000 15 | #82000000 16 | #00000000 17 | 18 | -------------------------------------------------------------------------------- /CameraBlur/app/src/main/res/values/dimens.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 16dp 4 | 160dp 5 | 6 | 16dp 7 | 16dp 8 | 16dp 9 | 4dp 10 | 16dp 11 | 32dp 12 | 2dp 13 | 14 | 15dp 15 | 96dp 16 | 17 | -------------------------------------------------------------------------------- /CameraBlur/app/src/main/res/values/strings.xml: -------------------------------------------------------------------------------- 1 | 2 | CameraBlur 3 | 4 | -------------------------------------------------------------------------------- /CameraBlur/app/src/main/res/values/styles.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 12 | 18 | 23 | 27 | 30 | 31 | 35 | 36 | 42 | 47 | 48 | 52 | 57 | 58 | 59 | -------------------------------------------------------------------------------- /CameraBlur/build.gradle: -------------------------------------------------------------------------------- 1 | // Top-level build file where you can add configuration options common to all sub-projects/modules. 2 | 3 | buildscript { 4 | 5 | repositories { 6 | google() 7 | jcenter() 8 | } 9 | dependencies { 10 | classpath 'com.android.tools.build:gradle:3.1.3' 11 | 12 | 13 | // NOTE: Do not place your application dependencies here; they belong 14 | // in the individual module build.gradle files 15 | } 16 | } 17 | 18 | allprojects { 19 | repositories { 20 | google() 21 | jcenter() 22 | } 23 | } 24 | 25 | task clean(type: Delete) { 26 | delete rootProject.buildDir 27 | } 28 | -------------------------------------------------------------------------------- /CameraBlur/gradle.properties: -------------------------------------------------------------------------------- 1 | # Project-wide Gradle settings. 2 | # IDE (e.g. Android Studio) users: 3 | # Gradle settings configured through the IDE *will override* 4 | # any settings specified in this file. 5 | # For more details on how to configure your build environment visit 6 | # http://www.gradle.org/docs/current/userguide/build_environment.html 7 | # Specifies the JVM arguments used for the daemon process. 8 | # The setting is particularly useful for tweaking memory settings. 9 | org.gradle.jvmargs=-Xmx1536m 10 | # When configured, Gradle will run in incubating parallel mode. 11 | # This option should only be used with decoupled projects. More details, visit 12 | # http://www.gradle.org/docs/current/userguide/multi_project_builds.html#sec:decoupled_projects 13 | # org.gradle.parallel=true 14 | -------------------------------------------------------------------------------- /CameraBlur/gradle/wrapper/gradle-wrapper.jar: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Gauravv97/CameraBlur/b3b80ad9d8492c76957c3d7c4aa5e9a0cb7bf1f3/CameraBlur/gradle/wrapper/gradle-wrapper.jar -------------------------------------------------------------------------------- /CameraBlur/gradle/wrapper/gradle-wrapper.properties: -------------------------------------------------------------------------------- 1 | #Fri Jun 22 22:16:14 IST 2018 2 | distributionBase=GRADLE_USER_HOME 3 | distributionPath=wrapper/dists 4 | zipStoreBase=GRADLE_USER_HOME 5 | zipStorePath=wrapper/dists 6 | distributionUrl=https\://services.gradle.org/distributions/gradle-4.4-all.zip 7 | -------------------------------------------------------------------------------- /CameraBlur/gradlew: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env sh 2 | 3 | ############################################################################## 4 | ## 5 | ## Gradle start up script for UN*X 6 | ## 7 | ############################################################################## 8 | 9 | # Attempt to set APP_HOME 10 | # Resolve links: $0 may be a link 11 | PRG="$0" 12 | # Need this for relative symlinks. 13 | while [ -h "$PRG" ] ; do 14 | ls=`ls -ld "$PRG"` 15 | link=`expr "$ls" : '.*-> \(.*\)$'` 16 | if expr "$link" : '/.*' > /dev/null; then 17 | PRG="$link" 18 | else 19 | PRG=`dirname "$PRG"`"/$link" 20 | fi 21 | done 22 | SAVED="`pwd`" 23 | cd "`dirname \"$PRG\"`/" >/dev/null 24 | APP_HOME="`pwd -P`" 25 | cd "$SAVED" >/dev/null 26 | 27 | APP_NAME="Gradle" 28 | APP_BASE_NAME=`basename "$0"` 29 | 30 | # Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script. 31 | DEFAULT_JVM_OPTS="" 32 | 33 | # Use the maximum available, or set MAX_FD != -1 to use that value. 34 | MAX_FD="maximum" 35 | 36 | warn () { 37 | echo "$*" 38 | } 39 | 40 | die () { 41 | echo 42 | echo "$*" 43 | echo 44 | exit 1 45 | } 46 | 47 | # OS specific support (must be 'true' or 'false'). 48 | cygwin=false 49 | msys=false 50 | darwin=false 51 | nonstop=false 52 | case "`uname`" in 53 | CYGWIN* ) 54 | cygwin=true 55 | ;; 56 | Darwin* ) 57 | darwin=true 58 | ;; 59 | MINGW* ) 60 | msys=true 61 | ;; 62 | NONSTOP* ) 63 | nonstop=true 64 | ;; 65 | esac 66 | 67 | CLASSPATH=$APP_HOME/gradle/wrapper/gradle-wrapper.jar 68 | 69 | # Determine the Java command to use to start the JVM. 70 | if [ -n "$JAVA_HOME" ] ; then 71 | if [ -x "$JAVA_HOME/jre/sh/java" ] ; then 72 | # IBM's JDK on AIX uses strange locations for the executables 73 | JAVACMD="$JAVA_HOME/jre/sh/java" 74 | else 75 | JAVACMD="$JAVA_HOME/bin/java" 76 | fi 77 | if [ ! -x "$JAVACMD" ] ; then 78 | die "ERROR: JAVA_HOME is set to an invalid directory: $JAVA_HOME 79 | 80 | Please set the JAVA_HOME variable in your environment to match the 81 | location of your Java installation." 82 | fi 83 | else 84 | JAVACMD="java" 85 | which java >/dev/null 2>&1 || die "ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH. 86 | 87 | Please set the JAVA_HOME variable in your environment to match the 88 | location of your Java installation." 89 | fi 90 | 91 | # Increase the maximum file descriptors if we can. 92 | if [ "$cygwin" = "false" -a "$darwin" = "false" -a "$nonstop" = "false" ] ; then 93 | MAX_FD_LIMIT=`ulimit -H -n` 94 | if [ $? -eq 0 ] ; then 95 | if [ "$MAX_FD" = "maximum" -o "$MAX_FD" = "max" ] ; then 96 | MAX_FD="$MAX_FD_LIMIT" 97 | fi 98 | ulimit -n $MAX_FD 99 | if [ $? -ne 0 ] ; then 100 | warn "Could not set maximum file descriptor limit: $MAX_FD" 101 | fi 102 | else 103 | warn "Could not query maximum file descriptor limit: $MAX_FD_LIMIT" 104 | fi 105 | fi 106 | 107 | # For Darwin, add options to specify how the application appears in the dock 108 | if $darwin; then 109 | GRADLE_OPTS="$GRADLE_OPTS \"-Xdock:name=$APP_NAME\" \"-Xdock:icon=$APP_HOME/media/gradle.icns\"" 110 | fi 111 | 112 | # For Cygwin, switch paths to Windows format before running java 113 | if $cygwin ; then 114 | APP_HOME=`cygpath --path --mixed "$APP_HOME"` 115 | CLASSPATH=`cygpath --path --mixed "$CLASSPATH"` 116 | JAVACMD=`cygpath --unix "$JAVACMD"` 117 | 118 | # We build the pattern for arguments to be converted via cygpath 119 | ROOTDIRSRAW=`find -L / -maxdepth 1 -mindepth 1 -type d 2>/dev/null` 120 | SEP="" 121 | for dir in $ROOTDIRSRAW ; do 122 | ROOTDIRS="$ROOTDIRS$SEP$dir" 123 | SEP="|" 124 | done 125 | OURCYGPATTERN="(^($ROOTDIRS))" 126 | # Add a user-defined pattern to the cygpath arguments 127 | if [ "$GRADLE_CYGPATTERN" != "" ] ; then 128 | OURCYGPATTERN="$OURCYGPATTERN|($GRADLE_CYGPATTERN)" 129 | fi 130 | # Now convert the arguments - kludge to limit ourselves to /bin/sh 131 | i=0 132 | for arg in "$@" ; do 133 | CHECK=`echo "$arg"|egrep -c "$OURCYGPATTERN" -` 134 | CHECK2=`echo "$arg"|egrep -c "^-"` ### Determine if an option 135 | 136 | if [ $CHECK -ne 0 ] && [ $CHECK2 -eq 0 ] ; then ### Added a condition 137 | eval `echo args$i`=`cygpath --path --ignore --mixed "$arg"` 138 | else 139 | eval `echo args$i`="\"$arg\"" 140 | fi 141 | i=$((i+1)) 142 | done 143 | case $i in 144 | (0) set -- ;; 145 | (1) set -- "$args0" ;; 146 | (2) set -- "$args0" "$args1" ;; 147 | (3) set -- "$args0" "$args1" "$args2" ;; 148 | (4) set -- "$args0" "$args1" "$args2" "$args3" ;; 149 | (5) set -- "$args0" "$args1" "$args2" "$args3" "$args4" ;; 150 | (6) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" ;; 151 | (7) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" ;; 152 | (8) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" "$args7" ;; 153 | (9) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" "$args7" "$args8" ;; 154 | esac 155 | fi 156 | 157 | # Escape application args 158 | save () { 159 | for i do printf %s\\n "$i" | sed "s/'/'\\\\''/g;1s/^/'/;\$s/\$/' \\\\/" ; done 160 | echo " " 161 | } 162 | APP_ARGS=$(save "$@") 163 | 164 | # Collect all arguments for the java command, following the shell quoting and substitution rules 165 | eval set -- $DEFAULT_JVM_OPTS $JAVA_OPTS $GRADLE_OPTS "\"-Dorg.gradle.appname=$APP_BASE_NAME\"" -classpath "\"$CLASSPATH\"" org.gradle.wrapper.GradleWrapperMain "$APP_ARGS" 166 | 167 | # by default we should be in the correct project dir, but when run from Finder on Mac, the cwd is wrong 168 | if [ "$(uname)" = "Darwin" ] && [ "$HOME" = "$PWD" ]; then 169 | cd "$(dirname "$0")" 170 | fi 171 | 172 | exec "$JAVACMD" "$@" 173 | -------------------------------------------------------------------------------- /CameraBlur/gradlew.bat: -------------------------------------------------------------------------------- 1 | @if "%DEBUG%" == "" @echo off 2 | @rem ########################################################################## 3 | @rem 4 | @rem Gradle startup script for Windows 5 | @rem 6 | @rem ########################################################################## 7 | 8 | @rem Set local scope for the variables with windows NT shell 9 | if "%OS%"=="Windows_NT" setlocal 10 | 11 | set DIRNAME=%~dp0 12 | if "%DIRNAME%" == "" set DIRNAME=. 13 | set APP_BASE_NAME=%~n0 14 | set APP_HOME=%DIRNAME% 15 | 16 | @rem Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script. 17 | set DEFAULT_JVM_OPTS= 18 | 19 | @rem Find java.exe 20 | if defined JAVA_HOME goto findJavaFromJavaHome 21 | 22 | set JAVA_EXE=java.exe 23 | %JAVA_EXE% -version >NUL 2>&1 24 | if "%ERRORLEVEL%" == "0" goto init 25 | 26 | echo. 27 | echo ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH. 28 | echo. 29 | echo Please set the JAVA_HOME variable in your environment to match the 30 | echo location of your Java installation. 31 | 32 | goto fail 33 | 34 | :findJavaFromJavaHome 35 | set JAVA_HOME=%JAVA_HOME:"=% 36 | set JAVA_EXE=%JAVA_HOME%/bin/java.exe 37 | 38 | if exist "%JAVA_EXE%" goto init 39 | 40 | echo. 41 | echo ERROR: JAVA_HOME is set to an invalid directory: %JAVA_HOME% 42 | echo. 43 | echo Please set the JAVA_HOME variable in your environment to match the 44 | echo location of your Java installation. 45 | 46 | goto fail 47 | 48 | :init 49 | @rem Get command-line arguments, handling Windows variants 50 | 51 | if not "%OS%" == "Windows_NT" goto win9xME_args 52 | 53 | :win9xME_args 54 | @rem Slurp the command line arguments. 55 | set CMD_LINE_ARGS= 56 | set _SKIP=2 57 | 58 | :win9xME_args_slurp 59 | if "x%~1" == "x" goto execute 60 | 61 | set CMD_LINE_ARGS=%* 62 | 63 | :execute 64 | @rem Setup the command line 65 | 66 | set CLASSPATH=%APP_HOME%\gradle\wrapper\gradle-wrapper.jar 67 | 68 | @rem Execute Gradle 69 | "%JAVA_EXE%" %DEFAULT_JVM_OPTS% %JAVA_OPTS% %GRADLE_OPTS% "-Dorg.gradle.appname=%APP_BASE_NAME%" -classpath "%CLASSPATH%" org.gradle.wrapper.GradleWrapperMain %CMD_LINE_ARGS% 70 | 71 | :end 72 | @rem End local scope for the variables with windows NT shell 73 | if "%ERRORLEVEL%"=="0" goto mainEnd 74 | 75 | :fail 76 | rem Set variable GRADLE_EXIT_CONSOLE if you need the _script_ return code instead of 77 | rem the _cmd.exe /c_ return code! 78 | if not "" == "%GRADLE_EXIT_CONSOLE%" exit 1 79 | exit /b 1 80 | 81 | :mainEnd 82 | if "%OS%"=="Windows_NT" endlocal 83 | 84 | :omega 85 | -------------------------------------------------------------------------------- /CameraBlur/settings.gradle: -------------------------------------------------------------------------------- 1 | include ':app' 2 | -------------------------------------------------------------------------------- /InputSize 1025px/frozen_inference_graph.pb: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Gauravv97/CameraBlur/b3b80ad9d8492c76957c3d7c4aa5e9a0cb7bf1f3/InputSize 1025px/frozen_inference_graph.pb -------------------------------------------------------------------------------- /InputSize 1537px/frozen_inference_graph.pb: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Gauravv97/CameraBlur/b3b80ad9d8492c76957c3d7c4aa5e9a0cb7bf1f3/InputSize 1537px/frozen_inference_graph.pb -------------------------------------------------------------------------------- /InputSize 513px/frozen_inference_graph.pb: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Gauravv97/CameraBlur/b3b80ad9d8492c76957c3d7c4aa5e9a0cb7bf1f3/InputSize 513px/frozen_inference_graph.pb -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | Apache License 2 | Version 2.0, January 2004 3 | http://www.apache.org/licenses/ 4 | 5 | TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION 6 | 7 | 1. Definitions. 8 | 9 | "License" shall mean the terms and conditions for use, reproduction, 10 | and distribution as defined by Sections 1 through 9 of this document. 11 | 12 | "Licensor" shall mean the copyright owner or entity authorized by 13 | the copyright owner that is granting the License. 14 | 15 | "Legal Entity" shall mean the union of the acting entity and all 16 | other entities that control, are controlled by, or are under common 17 | control with that entity. For the purposes of this definition, 18 | "control" means (i) the power, direct or indirect, to cause the 19 | direction or management of such entity, whether by contract or 20 | otherwise, or (ii) ownership of fifty percent (50%) or more of the 21 | outstanding shares, or (iii) beneficial ownership of such entity. 22 | 23 | "You" (or "Your") shall mean an individual or Legal Entity 24 | exercising permissions granted by this License. 25 | 26 | "Source" form shall mean the preferred form for making modifications, 27 | including but not limited to software source code, documentation 28 | source, and configuration files. 29 | 30 | "Object" form shall mean any form resulting from mechanical 31 | transformation or translation of a Source form, including but 32 | not limited to compiled object code, generated documentation, 33 | and conversions to other media types. 34 | 35 | "Work" shall mean the work of authorship, whether in Source or 36 | Object form, made available under the License, as indicated by a 37 | copyright notice that is included in or attached to the work 38 | (an example is provided in the Appendix below). 39 | 40 | "Derivative Works" shall mean any work, whether in Source or Object 41 | form, that is based on (or derived from) the Work and for which the 42 | editorial revisions, annotations, elaborations, or other modifications 43 | represent, as a whole, an original work of authorship. For the purposes 44 | of this License, Derivative Works shall not include works that remain 45 | separable from, or merely link (or bind by name) to the interfaces of, 46 | the Work and Derivative Works thereof. 47 | 48 | "Contribution" shall mean any work of authorship, including 49 | the original version of the Work and any modifications or additions 50 | to that Work or Derivative Works thereof, that is intentionally 51 | submitted to Licensor for inclusion in the Work by the copyright owner 52 | or by an individual or Legal Entity authorized to submit on behalf of 53 | the copyright owner. For the purposes of this definition, "submitted" 54 | means any form of electronic, verbal, or written communication sent 55 | to the Licensor or its representatives, including but not limited to 56 | communication on electronic mailing lists, source code control systems, 57 | and issue tracking systems that are managed by, or on behalf of, the 58 | Licensor for the purpose of discussing and improving the Work, but 59 | excluding communication that is conspicuously marked or otherwise 60 | designated in writing by the copyright owner as "Not a Contribution." 61 | 62 | "Contributor" shall mean Licensor and any individual or Legal Entity 63 | on behalf of whom a Contribution has been received by Licensor and 64 | subsequently incorporated within the Work. 65 | 66 | 2. Grant of Copyright License. Subject to the terms and conditions of 67 | this License, each Contributor hereby grants to You a perpetual, 68 | worldwide, non-exclusive, no-charge, royalty-free, irrevocable 69 | copyright license to reproduce, prepare Derivative Works of, 70 | publicly display, publicly perform, sublicense, and distribute the 71 | Work and such Derivative Works in Source or Object form. 72 | 73 | 3. Grant of Patent License. Subject to the terms and conditions of 74 | this License, each Contributor hereby grants to You a perpetual, 75 | worldwide, non-exclusive, no-charge, royalty-free, irrevocable 76 | (except as stated in this section) patent license to make, have made, 77 | use, offer to sell, sell, import, and otherwise transfer the Work, 78 | where such license applies only to those patent claims licensable 79 | by such Contributor that are necessarily infringed by their 80 | Contribution(s) alone or by combination of their Contribution(s) 81 | with the Work to which such Contribution(s) was submitted. If You 82 | institute patent litigation against any entity (including a 83 | cross-claim or counterclaim in a lawsuit) alleging that the Work 84 | or a Contribution incorporated within the Work constitutes direct 85 | or contributory patent infringement, then any patent licenses 86 | granted to You under this License for that Work shall terminate 87 | as of the date such litigation is filed. 88 | 89 | 4. Redistribution. You may reproduce and distribute copies of the 90 | Work or Derivative Works thereof in any medium, with or without 91 | modifications, and in Source or Object form, provided that You 92 | meet the following conditions: 93 | 94 | (a) You must give any other recipients of the Work or 95 | Derivative Works a copy of this License; and 96 | 97 | (b) You must cause any modified files to carry prominent notices 98 | stating that You changed the files; and 99 | 100 | (c) You must retain, in the Source form of any Derivative Works 101 | that You distribute, all copyright, patent, trademark, and 102 | attribution notices from the Source form of the Work, 103 | excluding those notices that do not pertain to any part of 104 | the Derivative Works; and 105 | 106 | (d) If the Work includes a "NOTICE" text file as part of its 107 | distribution, then any Derivative Works that You distribute must 108 | include a readable copy of the attribution notices contained 109 | within such NOTICE file, excluding those notices that do not 110 | pertain to any part of the Derivative Works, in at least one 111 | of the following places: within a NOTICE text file distributed 112 | as part of the Derivative Works; within the Source form or 113 | documentation, if provided along with the Derivative Works; or, 114 | within a display generated by the Derivative Works, if and 115 | wherever such third-party notices normally appear. The contents 116 | of the NOTICE file are for informational purposes only and 117 | do not modify the License. You may add Your own attribution 118 | notices within Derivative Works that You distribute, alongside 119 | or as an addendum to the NOTICE text from the Work, provided 120 | that such additional attribution notices cannot be construed 121 | as modifying the License. 122 | 123 | You may add Your own copyright statement to Your modifications and 124 | may provide additional or different license terms and conditions 125 | for use, reproduction, or distribution of Your modifications, or 126 | for any such Derivative Works as a whole, provided Your use, 127 | reproduction, and distribution of the Work otherwise complies with 128 | the conditions stated in this License. 129 | 130 | 5. Submission of Contributions. Unless You explicitly state otherwise, 131 | any Contribution intentionally submitted for inclusion in the Work 132 | by You to the Licensor shall be under the terms and conditions of 133 | this License, without any additional terms or conditions. 134 | Notwithstanding the above, nothing herein shall supersede or modify 135 | the terms of any separate license agreement you may have executed 136 | with Licensor regarding such Contributions. 137 | 138 | 6. Trademarks. This License does not grant permission to use the trade 139 | names, trademarks, service marks, or product names of the Licensor, 140 | except as required for reasonable and customary use in describing the 141 | origin of the Work and reproducing the content of the NOTICE file. 142 | 143 | 7. Disclaimer of Warranty. Unless required by applicable law or 144 | agreed to in writing, Licensor provides the Work (and each 145 | Contributor provides its Contributions) on an "AS IS" BASIS, 146 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or 147 | implied, including, without limitation, any warranties or conditions 148 | of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A 149 | PARTICULAR PURPOSE. You are solely responsible for determining the 150 | appropriateness of using or redistributing the Work and assume any 151 | risks associated with Your exercise of permissions under this License. 152 | 153 | 8. Limitation of Liability. In no event and under no legal theory, 154 | whether in tort (including negligence), contract, or otherwise, 155 | unless required by applicable law (such as deliberate and grossly 156 | negligent acts) or agreed to in writing, shall any Contributor be 157 | liable to You for damages, including any direct, indirect, special, 158 | incidental, or consequential damages of any character arising as a 159 | result of this License or out of the use or inability to use the 160 | Work (including but not limited to damages for loss of goodwill, 161 | work stoppage, computer failure or malfunction, or any and all 162 | other commercial damages or losses), even if such Contributor 163 | has been advised of the possibility of such damages. 164 | 165 | 9. Accepting Warranty or Additional Liability. While redistributing 166 | the Work or Derivative Works thereof, You may choose to offer, 167 | and charge a fee for, acceptance of support, warranty, indemnity, 168 | or other liability obligations and/or rights consistent with this 169 | License. However, in accepting such obligations, You may act only 170 | on Your own behalf and on Your sole responsibility, not on behalf 171 | of any other Contributor, and only if You agree to indemnify, 172 | defend, and hold each Contributor harmless for any liability 173 | incurred by, or claims asserted against, such Contributor by reason 174 | of your accepting any such warranty or additional liability. 175 | 176 | END OF TERMS AND CONDITIONS 177 | 178 | APPENDIX: How to apply the Apache License to your work. 179 | 180 | To apply the Apache License to your work, attach the following 181 | boilerplate notice, with the fields enclosed by brackets "[]" 182 | replaced with your own identifying information. (Don't include 183 | the brackets!) The text should be enclosed in the appropriate 184 | comment syntax for the file format. We also recommend that a 185 | file or class name and description of purpose be included on the 186 | same "printed page" as the copyright notice for easier 187 | identification within third-party archives. 188 | 189 | Copyright [yyyy] [name of copyright owner] 190 | 191 | Licensed under the Apache License, Version 2.0 (the "License"); 192 | you may not use this file except in compliance with the License. 193 | You may obtain a copy of the License at 194 | 195 | http://www.apache.org/licenses/LICENSE-2.0 196 | 197 | Unless required by applicable law or agreed to in writing, software 198 | distributed under the License is distributed on an "AS IS" BASIS, 199 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 200 | See the License for the specific language governing permissions and 201 | limitations under the License. -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | CameraBlur:Portrait mode using DeeplabV3+ Semantic Image Segmentation 2 | ===================================================================== 3 | A simple android app to implement Portrait mode using a single sensor like in Pixel 2 (well not exactly exactly like Pixel 2's). This app allows you to either click image from your phone or select an image from storage and apply the blur. This app can run on ARM32 bit `ARM v7A` as well as ARM64 `ARMv8-A`. 4 | 5 | ## Downloads 6 | 7 | Download apk from [here](https://github.com/Gauravv97/CameraBlur/raw/master/apk/v1.0.0/app-debug.apk) 8 | 9 | 10 | ## Some Samples 11 | 12 |

13 |
14 |
15 | 16 |

17 | 18 | 19 | ## Features 20 | 21 | * Select image from storage or click them using camera 22 | * Blur a variety of subjects (most centered subject will be selected rest will be background). 23 | * SoftBlur around edges 24 | 25 | ## For developers 26 | 27 | I have 3 pre-trained models of different crop sizes `Default 1025 px`. You can use any one of them but with increased crop size the processing time also increases (by a lot), so use them as per your requirement. Crop size is the size of the image that the input image will be resized to and sent for processing. The output dimensions are always less than crop size. 28 | 29 | For using 1537 px: Copy `InputSize 1537px\frozen_inference_graph.pb`and paste it in `CameraBlur\app\src\main\assets\`. 30 | 31 | Then change 32 | `CameraBlur\app\src\main\java\com\anondev\gaurav\camerablur\DeeplabProcessor.java`line 28 33 | 34 | From 35 | 36 | public final static int INPUT_SIZE = 1025; 37 | 38 | to 39 | 40 | public final static int INPUT_SIZE = 1537; 41 | 42 | ## Changelog 43 | 44 | v0.0.2 Added SoftBlur around edges 45 | 46 | v0.0.3 Implemented blur using [Android RenderScript](https://developer.android.com/guide/topics/renderscript/compute) 47 | 48 | 49 | v1.0.0 Exported MobilenetV2 model with depth multiplier=0.5([mobilenetv2_dm05_coco_voc_trainaug](http://download.tensorflow.org/models/deeplabv3_mnv2_dm05_pascal_trainaug_2018_10_01.tar.gz) ). Accuracy is slightly reduced but performance gain is extremely high. 50 | 51 | 52 | ## Attributions/Thanks/External code 53 | 54 | This application wouldn't have been possible without the great material produced by the community. I would like to give special thanks to the authors of essential parts I've got on the internet and used in the code.: 55 | 56 | - DeepLabv3+: 57 | ``` 58 | @article{deeplabv3plus2018, 59 | title={Encoder-Decoder with Atrous Separable Convolution for Semantic Image Segmentation}, 60 | author={Liang-Chieh Chen and Yukun Zhu and George Papandreou and Florian Schroff and Hartwig Adam}, 61 | journal={arXiv:1802.02611}, 62 | year={2018} 63 | } 64 | ``` 65 | 66 | - MobileNetv2: 67 | 68 | ``` 69 | @inproceedings{mobilenetv22018, 70 | title={Inverted Residuals and Linear Bottlenecks: Mobile Networks for Classification, Detection and Segmentation}, 71 | author={Mark Sandler and Andrew Howard and Menglong Zhu and Andrey Zhmoginov and Liang-Chieh Chen}, 72 | booktitle={CVPR}, 73 | year={2018} 74 | } 75 | ``` 76 | 77 | 78 | 79 | * [Tensorflow's deeplab](https://github.com/tensorflow/models/tree/master/research/deeplab) 80 | * A special thanks to [dailystudio for implementing mobilenet model on TFMobile](https://github.com/dailystudio/ml/tree/master/deeplab) without his help this project wouldn't have been sucessful. Also Without the advice given by [Liang-Chieh Chen](https://github.com/aquariusjay), we couldn't have successfully exported the model to mobile devices. 81 | 82 | 83 | ## Photo Credits 84 | 85 | * Marcus Pinho, [Pexels](https://www.pexels.com/photo/woman-wearing-red-and-black-feather-hat-923345/) 86 | 87 | * Sonnie Hiles, [unsplash](https://unsplash.com/photos/10wjs03JJv8) 88 | 89 | ## About 90 | 91 | Copyright 2018 Gaurav Chaudhari, and licensed under the Apache License, Version 2.0. No attribution is necessary but it's very much appreciated. Star this project if you like it! 92 | 93 | 94 | -------------------------------------------------------------------------------- /SampleImages/Blurred1.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Gauravv97/CameraBlur/b3b80ad9d8492c76957c3d7c4aa5e9a0cb7bf1f3/SampleImages/Blurred1.jpg -------------------------------------------------------------------------------- /SampleImages/Blurred2.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Gauravv97/CameraBlur/b3b80ad9d8492c76957c3d7c4aa5e9a0cb7bf1f3/SampleImages/Blurred2.jpg -------------------------------------------------------------------------------- /SampleImages/Image1.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Gauravv97/CameraBlur/b3b80ad9d8492c76957c3d7c4aa5e9a0cb7bf1f3/SampleImages/Image1.jpg -------------------------------------------------------------------------------- /SampleImages/Image2.jpeg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Gauravv97/CameraBlur/b3b80ad9d8492c76957c3d7c4aa5e9a0cb7bf1f3/SampleImages/Image2.jpeg -------------------------------------------------------------------------------- /apk/InitVersion/app-debug1537.apk: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Gauravv97/CameraBlur/b3b80ad9d8492c76957c3d7c4aa5e9a0cb7bf1f3/apk/InitVersion/app-debug1537.apk -------------------------------------------------------------------------------- /apk/v0.0.2/CameraBlur 1025px.apk: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Gauravv97/CameraBlur/b3b80ad9d8492c76957c3d7c4aa5e9a0cb7bf1f3/apk/v0.0.2/CameraBlur 1025px.apk -------------------------------------------------------------------------------- /apk/v0.0.3/CameraBlur 1025px.apk: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Gauravv97/CameraBlur/b3b80ad9d8492c76957c3d7c4aa5e9a0cb7bf1f3/apk/v0.0.3/CameraBlur 1025px.apk -------------------------------------------------------------------------------- /apk/v1.0.0/app-debug.apk: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Gauravv97/CameraBlur/b3b80ad9d8492c76957c3d7c4aa5e9a0cb7bf1f3/apk/v1.0.0/app-debug.apk --------------------------------------------------------------------------------