Skip to content

Commit

Permalink
add expirmental support for http://equalais.media.mit.edu/
Browse files Browse the repository at this point in the history
equalais modifies images to make them difficult for AI/ML to read
  • Loading branch information
n8fr8 committed Apr 20, 2018
1 parent 68134cb commit 5d24233
Show file tree
Hide file tree
Showing 16 changed files with 244 additions and 64 deletions.
73 changes: 34 additions & 39 deletions app/app.iml
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
<?xml version="1.0" encoding="UTF-8"?>
<module external.linked.project.id=":app" external.linked.project.path="$MODULE_DIR$" external.root.project.path="$MODULE_DIR$/.." external.system.id="GRADLE" external.system.module.group="ObscuraCam3" external.system.module.version="unspecified" type="JAVA_MODULE" version="4">
<module external.linked.project.id=":app" external.linked.project.path="$MODULE_DIR$" external.root.project.path="$MODULE_DIR$/.." external.system.id="GRADLE" type="JAVA_MODULE" version="4">
<component name="FacetManager">
<facet type="android-gradle" name="Android-Gradle">
<configuration>
Expand Down Expand Up @@ -27,7 +27,7 @@
</configuration>
</facet>
</component>
<component name="NewModuleRootManager" LANGUAGE_LEVEL="JDK_1_7">
<component name="NewModuleRootManager" LANGUAGE_LEVEL="JDK_1_8">
<output url="file://$MODULE_DIR$/build/intermediates/classes/debug" />
<output-test url="file://$MODULE_DIR$/build/intermediates/classes/test/debug" />
<exclude-output />
Expand Down Expand Up @@ -97,60 +97,55 @@
<sourceFolder url="file://$MODULE_DIR$/src/test/shaders" isTestSource="true" />
<excludeFolder url="file://$MODULE_DIR$/build/intermediates/assets" />
<excludeFolder url="file://$MODULE_DIR$/build/intermediates/blame" />
<excludeFolder url="file://$MODULE_DIR$/build/intermediates/builds" />
<excludeFolder url="file://$MODULE_DIR$/build/intermediates/check-manifest" />
<excludeFolder url="file://$MODULE_DIR$/build/intermediates/classes" />
<excludeFolder url="file://$MODULE_DIR$/build/intermediates/classes-jar" />
<excludeFolder url="file://$MODULE_DIR$/build/intermediates/incremental" />
<excludeFolder url="file://$MODULE_DIR$/build/intermediates/incremental-classes" />
<excludeFolder url="file://$MODULE_DIR$/build/intermediates/incremental-runtime-classes" />
<excludeFolder url="file://$MODULE_DIR$/build/intermediates/incremental-safeguard" />
<excludeFolder url="file://$MODULE_DIR$/build/intermediates/incremental-verifier" />
<excludeFolder url="file://$MODULE_DIR$/build/intermediates/instant-run-resources" />
<excludeFolder url="file://$MODULE_DIR$/build/intermediates/instant-run-support" />
<excludeFolder url="file://$MODULE_DIR$/build/intermediates/javaPrecompile" />
<excludeFolder url="file://$MODULE_DIR$/build/intermediates/jniLibs" />
<excludeFolder url="file://$MODULE_DIR$/build/intermediates/lint" />
<excludeFolder url="file://$MODULE_DIR$/build/intermediates/manifests" />
<excludeFolder url="file://$MODULE_DIR$/build/intermediates/ndkBuild" />
<excludeFolder url="file://$MODULE_DIR$/build/intermediates/pre-dexed" />
<excludeFolder url="file://$MODULE_DIR$/build/intermediates/prebuild" />
<excludeFolder url="file://$MODULE_DIR$/build/intermediates/reload-dex" />
<excludeFolder url="file://$MODULE_DIR$/build/intermediates/processing-tools" />
<excludeFolder url="file://$MODULE_DIR$/build/intermediates/res" />
<excludeFolder url="file://$MODULE_DIR$/build/intermediates/restart-dex" />
<excludeFolder url="file://$MODULE_DIR$/build/intermediates/rs" />
<excludeFolder url="file://$MODULE_DIR$/build/intermediates/shaders" />
<excludeFolder url="file://$MODULE_DIR$/build/intermediates/split-apk" />
<excludeFolder url="file://$MODULE_DIR$/build/intermediates/splits-support" />
<excludeFolder url="file://$MODULE_DIR$/build/intermediates/symbols" />
<excludeFolder url="file://$MODULE_DIR$/build/intermediates/tmp" />
<excludeFolder url="file://$MODULE_DIR$/build/intermediates/transforms" />
<excludeFolder url="file://$MODULE_DIR$/build/outputs" />
<excludeFolder url="file://$MODULE_DIR$/build/reports" />
<excludeFolder url="file://$MODULE_DIR$/build/tmp" />
</content>
<orderEntry type="jdk" jdkName="Android API 25 Platform" jdkType="Android SDK" />
<orderEntry type="jdk" jdkName="Android API 27 Platform" jdkType="Android SDK" />
<orderEntry type="sourceFolder" forTests="false" />
<orderEntry type="library" name="com.google.guava:guava:22.0@jar" level="project" />
<orderEntry type="library" name="com.android.support:animated-vector-drawable-25.4.0" level="project" />
<orderEntry type="library" name="org.codehaus.mojo:animal-sniffer-annotations:1.14@jar" level="project" />
<orderEntry type="library" name="com.android.support:design-25.4.0" level="project" />
<orderEntry type="library" name="com.android.support:transition-25.4.0" level="project" />
<orderEntry type="library" name="com.writingminds:FFmpegAndroid-0.3.2" level="project" />
<orderEntry type="library" name="com.android.support:support-core-ui-25.4.0" level="project" />
<orderEntry type="library" name="com.android.support:appcompat-v7-25.4.0" level="project" />
<orderEntry type="library" name="com.android.support:support-compat-25.4.0" level="project" />
<orderEntry type="library" name="commons-codec:commons-codec:1.9@jar" level="project" />
<orderEntry type="library" name="com.google.code.findbugs:jsr305:1.3.9@jar" level="project" />
<orderEntry type="library" name="com.google.errorprone:error_prone_annotations:2.0.18@jar" level="project" />
<orderEntry type="library" name="com.android.support:support-annotations:25.4.0@jar" level="project" />
<orderEntry type="library" name="com.android.support:support-core-utils-25.4.0" level="project" />
<orderEntry type="library" name="com.google.j2objc:j2objc-annotations:1.1@jar" level="project" />
<orderEntry type="library" name="com.android.support:support-v4-25.4.0" level="project" />
<orderEntry type="library" name="com.android.support:support-vector-drawable-25.4.0" level="project" />
<orderEntry type="library" name="com.squareup.picasso:picasso-2.6.0-SNAPSHOT" level="project" />
<orderEntry type="library" name="com.android.support:support-fragment-25.4.0" level="project" />
<orderEntry type="library" name="com.android.support:recyclerview-v7-25.4.0" level="project" />
<orderEntry type="library" name="com.android.support:support-media-compat-25.4.0" level="project" />
<orderEntry type="library" name="Gradle: com.android.support:transition-27.1.1" level="project" />
<orderEntry type="library" name="Gradle: com.android.support:support-v4-27.1.1" level="project" />
<orderEntry type="library" name="Gradle: android.arch.lifecycle:common:1.1.0@jar" level="project" />
<orderEntry type="library" name="Gradle: com.android.support:support-annotations:27.1.1@jar" level="project" />
<orderEntry type="library" name="Gradle: com.android.support:animated-vector-drawable-27.1.1" level="project" />
<orderEntry type="library" name="Gradle: com.android.support:support-compat-27.1.1" level="project" />
<orderEntry type="library" name="Gradle: com.google.code.findbugs:jsr305:1.3.9@jar" level="project" />
<orderEntry type="library" name="Gradle: android.arch.lifecycle:viewmodel-1.1.0" level="project" />
<orderEntry type="library" name="Gradle: org.codehaus.mojo:animal-sniffer-annotations:1.14@jar" level="project" />
<orderEntry type="library" name="Gradle: com.android.support:recyclerview-v7-27.1.1" level="project" />
<orderEntry type="library" name="Gradle: com.android.support:support-vector-drawable-27.1.1" level="project" />
<orderEntry type="library" name="Gradle: com.android.support:support-media-compat-27.1.1" level="project" />
<orderEntry type="library" name="Gradle: com.android.support:support-core-ui-27.1.1" level="project" />
<orderEntry type="library" name="Gradle: com.android.support:support-core-utils-27.1.1" level="project" />
<orderEntry type="library" name="Gradle: com.google.guava:guava:23.0-android@jar" level="project" />
<orderEntry type="library" name="Gradle: com.squareup.okio:okio:1.14.0@jar" level="project" />
<orderEntry type="library" name="Gradle: com.google.errorprone:error_prone_annotations:2.0.18@jar" level="project" />
<orderEntry type="library" name="Gradle: com.google.j2objc:j2objc-annotations:1.1@jar" level="project" />
<orderEntry type="library" name="Gradle: com.android.support:support-fragment-27.1.1" level="project" />
<orderEntry type="library" name="Gradle: commons-codec:commons-codec:1.9@jar" level="project" />
<orderEntry type="library" name="Gradle: android.arch.core:runtime-1.1.0" level="project" />
<orderEntry type="library" name="Gradle: com.android.support:design-27.1.1" level="project" />
<orderEntry type="library" name="Gradle: com.android.support:appcompat-v7-27.1.1" level="project" />
<orderEntry type="library" name="Gradle: com.writingminds:FFmpegAndroid-0.3.2" level="project" />
<orderEntry type="library" name="Gradle: com.squareup.okhttp3:okhttp:3.10.0@jar" level="project" />
<orderEntry type="library" name="Gradle: com.android.support:exifinterface-27.1.0" level="project" />
<orderEntry type="library" name="Gradle: android.arch.lifecycle:livedata-core-1.1.0" level="project" />
<orderEntry type="library" name="Gradle: com.squareup.picasso:picasso-2.71828" level="project" />
<orderEntry type="library" name="Gradle: android.arch.core:common:1.1.0@jar" level="project" />
<orderEntry type="library" name="Gradle: android.arch.lifecycle:runtime-1.1.0" level="project" />
</component>
</module>
24 changes: 15 additions & 9 deletions app/build.gradle
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
apply plugin: 'com.android.application'

android {
compileSdkVersion 25
buildToolsVersion '26.0.2'
compileSdkVersion 27
buildToolsVersion '27.0.3'

defaultConfig {
applicationId "org.witness.sscphase1"
minSdkVersion 16
targetSdkVersion 25
targetSdkVersion 27
versionCode 4002
versionName "4.0.0.2"
ndk {
Expand All @@ -18,6 +18,11 @@ android {

}

compileOptions {
sourceCompatibility 1.8
targetCompatibility 1.8
}

buildTypes {
release {
minifyEnabled false
Expand Down Expand Up @@ -45,10 +50,11 @@ repositories {
}

dependencies {
compile 'com.google.guava:guava:22.0'
compile 'commons-codec:commons-codec:1.9'
compile 'com.android.support:appcompat-v7:25.4.0'
compile 'com.android.support:design:25.4.0'
compile 'com.writingminds:FFmpegAndroid:0.3.2'
compile 'com.squareup.picasso:picasso:2.6.0-SNAPSHOT'
implementation 'com.google.guava:guava:23.0-android'
implementation 'commons-codec:commons-codec:1.9'
implementation 'com.android.support:appcompat-v7:27.1.1'
implementation 'com.android.support:design:27.1.1'
implementation 'com.writingminds:FFmpegAndroid:0.3.2'
implementation 'com.squareup.picasso:picasso:2.71828'
implementation 'com.squareup.okhttp3:okhttp:3.10.0'
}
5 changes: 4 additions & 1 deletion app/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@
package="org.witness.sscphase1"
android:installLocation="auto">

<uses-permission android:name="android.permission.INTERNET"/>

<uses-permission android:name="android.permission.READ_MEDIA_STORAGE"/>

<uses-permission android:name="android.permission.WAKE_LOCK"/>
Expand Down Expand Up @@ -73,12 +75,13 @@
</activity>
<provider
android:name="android.support.v4.content.FileProvider"
android:authorities="org.witness.securesmartcam.camera_capture"
android:authorities="${applicationId}.provider"
android:exported="false"
android:grantUriPermissions="true">
<meta-data
android:name="android.support.FILE_PROVIDER_PATHS"
android:resource="@xml/camera_capture_paths" />
</provider>
</application>

</manifest>
60 changes: 60 additions & 0 deletions app/src/main/java/edu/mit/media/equalais/Equalais.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
package edu.mit.media.equalais;

import android.util.Base64;
import android.util.Log;

import java.io.File;
import java.io.IOException;

import okhttp3.MediaType;
import okhttp3.MultipartBody;
import okhttp3.OkHttpClient;
import okhttp3.Request;
import okhttp3.RequestBody;
import okhttp3.Response;

public class Equalais {

private final static String ENDPOINT = "https://equal-ais.appspot.com";
private final static MediaType MEDIA_TYPE_JPG = MediaType.parse("image/jpg");

public byte[] perturb (byte[] faceJpeg)
{

OkHttpClient client = new OkHttpClient();

RequestBody requestBody = new MultipartBody.Builder()
.setType(MultipartBody.FORM)
.addFormDataPart("image", "face.jpg",
RequestBody.create(MEDIA_TYPE_JPG, faceJpeg))
.build();

// Create request for remote resource.
Request request = new Request.Builder()
.url(ENDPOINT)
.post(requestBody)
.build();

try {
Response response = client.newCall(request).execute();

if (response.isSuccessful()) {

String eqFace = response.body().string();

byte[] resp = Base64.decode(eqFace,Base64.DEFAULT);

return resp;


}

}
catch (IOException ioe)
{
Log.e(getClass().getName(),"error making post request",ioe);
}

return null;
}
}
3 changes: 2 additions & 1 deletion app/src/main/java/org/witness/obscuracam/MainActivity.java
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@
import org.witness.obscuracam.ui.adapters.AskForPermissionAdapter;
import org.witness.obscuracam.ui.adapters.GalleryCursorRecyclerViewAdapter;
import org.witness.obscuracam.video.VideoEditor;
import org.witness.sscphase1.BuildConfig;
import org.witness.sscphase1.R;

import java.io.File;
Expand Down Expand Up @@ -377,7 +378,7 @@ private void takePicture() {
image.createNewFile();

Uri photoURI = FileProvider.getUriForFile(this,
"org.witness.securesmartcam.camera_capture",
BuildConfig.APPLICATION_ID + ".provider",
image);
takePictureIntent.putExtra(MediaStore.EXTRA_OUTPUT, photoURI);

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,93 @@
package org.witness.obscuracam.photo.filters;

import android.content.Context;
import android.graphics.Bitmap;
import android.graphics.BitmapFactory;
import android.graphics.Canvas;
import android.graphics.Paint;
import android.graphics.RectF;
import android.os.AsyncTask;
import android.util.Log;

import java.io.ByteArrayOutputStream;
import java.util.Properties;

import edu.mit.media.equalais.Equalais;

public class EqualaisObscure implements RegionProcesser {

Paint mPainter;
Context mContext;

RectF mRect;
Bitmap mLastBmp;

public EqualaisObscure (Context context, Paint painter)
{
mContext = context;
mPainter = painter;
}

@Override
public void processRegion(final RectF rect, final Canvas canvas, final Bitmap originalBmp) {

if (mRect != null && mRect.equals(rect))
{
if (mLastBmp != null)
{
canvas.drawBitmap(mLastBmp, null, rect, mPainter);
return;
}
}

mRect = rect;

// The Very Basic
new AsyncTask<Void, Void, byte[]>() {
protected void onPreExecute() {
// Pre Code
}
protected byte[] doInBackground(Void... unused) {
// Background Code
ByteArrayOutputStream baos = new ByteArrayOutputStream();

try {
Bitmap rectBitmap = Bitmap.createBitmap(originalBmp, (int) rect.left, (int) rect.top, (int) rect.width(), (int) rect.height());
rectBitmap.compress(Bitmap.CompressFormat.JPEG, 100, baos);

Equalais equalais = new Equalais();
return equalais.perturb(baos.toByteArray());
}
catch (Exception e)
{
Log.e("Equalais","Error perturbing!",e);
return null;
}

}
protected void onPostExecute(byte[] resp) {
// Post Code
if (resp != null)
{
mLastBmp = BitmapFactory.decodeByteArray(resp, 0, resp.length);
canvas.drawBitmap(mLastBmp, null, rect, mPainter);
}
}
}.execute();
}

@Override
public Properties getProperties() {
return null;
}

@Override
public Bitmap getBitmap() {
return null;
}

@Override
public void setProperties(Properties props) {

}
}
Loading

0 comments on commit 5d24233

Please sign in to comment.