-
-
Notifications
You must be signed in to change notification settings - Fork 81
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
add expirmental support for http://equalais.media.mit.edu/
equalais modifies images to make them difficult for AI/ML to read
- Loading branch information
Showing
16 changed files
with
244 additions
and
64 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
93 changes: 93 additions & 0 deletions
93
app/src/main/java/org/witness/obscuracam/photo/filters/EqualaisObscure.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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) { | ||
|
||
} | ||
} |
Oops, something went wrong.