Commit cafce5d8 by Simhachalam ch

removed opencv library to reduce the apk size

parent f3e89ee8
......@@ -72,7 +72,7 @@ android {
vportal {
applicationId "com.vsoft.vera.vportal"
versionCode 1
versionName "0.1.9"
versionName "0.2.1"
}
}
}
......@@ -124,7 +124,7 @@ dependencies {
implementation 'de.hdodenhof:circleimageview:3.0.0'
implementation 'com.github.bumptech.glide:glide:4.8.0'
annotationProcessor 'com.github.bumptech.glide:compiler:4.8.0'
implementation 'com.quickbirdstudios:opencv:4.1.0'
// implementation 'com.quickbirdstudios:opencv:4.1.0'
implementation 'org.jsoup:jsoup:1.11.3'
//static Reports Screen
implementation 'com.numetriclabz.numandroidcharts:numandroidcharts:1.0.9'
......
......@@ -91,13 +91,6 @@ import com.wang.avi.AVLoadingIndicatorView;
import org.json.JSONArray;
import org.json.JSONException;
import org.json.JSONObject;
import org.opencv.android.BaseLoaderCallback;
import org.opencv.android.LoaderCallbackInterface;
import org.opencv.android.OpenCVLoader;
import org.opencv.android.Utils;
import org.opencv.core.CvType;
import org.opencv.core.Mat;
import org.opencv.imgproc.Imgproc;
import java.io.ByteArrayOutputStream;
import java.io.File;
import java.io.FileInputStream;
......@@ -167,7 +160,7 @@ public class ChatActivity extends AppCompatActivity implements OnDSListener, OnD
private static final long LISTENING_DIALOG_DISMISS_DELAY_TIME = 10000;
private Boolean opencvEnd = false;
private boolean isBlur = false;
private Mat imageMat;
// private Mat imageMat;
private ImageButton sendButton;
private final static String INIT_MSG = "hi";
private String chatHistroy= "";
......@@ -1133,7 +1126,7 @@ public class ChatActivity extends AppCompatActivity implements OnDSListener, OnD
if(data != null ){
if (takePictureFilePath != null && !takePictureFilePath.isEmpty()) {
processImageAsBitmap(takePictureFilePath);
// processImageAsBitmap(takePictureFilePath);
}
}else {
initChatMessage("stop");
......@@ -1159,109 +1152,109 @@ public class ChatActivity extends AppCompatActivity implements OnDSListener, OnD
private void processImageAsBitmap(String imageFilePath) {
try {
BitmapFactory.Options bitmapOptions = new BitmapFactory.Options();
takePhotobitmap = BitmapFactory.decodeFile(imageFilePath, bitmapOptions);
// setImageOrientation(imageFilePath, bitmap);
if (takePhotobitmap != null) {
opencvProcess(takePhotobitmap);
if (isBlur) {
reTakePhoto();
} else {
ByteArrayOutputStream byteArrayOutputStream = new ByteArrayOutputStream();
takePhotobitmap.compress(Bitmap.CompressFormat.JPEG, 75, byteArrayOutputStream);
byte[] byteArray = byteArrayOutputStream.toByteArray();
String base64Image = Base64.encodeToString(byteArray, Base64.DEFAULT);
addMessage(mLoggedInUsername, "", takePictureFilePath);
if (null == mLoggedInUsername) return;
if (!mSocket.connected()) return;
textDotLoader.show();
// perform the sending message attempt.
JSONObject jsonObject = new JSONObject();
try {
jsonObject.put(CLIENT_MESSAGE_KEY, "");
jsonObject.put(CLIENT_MAIL_KEY, PrefManager.getSharedPref(this, PrefManager.PREFERENCE_USER_EMAIL_ID));
jsonObject.put(SESSION_ID_UNIQ, PrefManager.getSharedPref(ChatActivity.this, PrefManager.SESSION_ID));
jsonObject.put(LOCATION, "location");
jsonObject.put(USER_SYSID, userSysId);
jsonObject.put(SCANNED_IMAGE, base64Image);
} catch (JSONException e) {
e.printStackTrace();
}
mSocket.emit(NEW_MESSAGE, jsonObject);
}
} else {
}
} catch (Exception e) {
e.printStackTrace();
}
}
private BaseLoaderCallback mLoaderCallback = new BaseLoaderCallback(this) {
@Override
public void onManagerConnected(int status) {
switch (status) {
case LoaderCallbackInterface.SUCCESS:
{
Log.i("OpenCV", "OpenCV loaded successfully");
imageMat=new Mat();
} break;
default:
{
super.onManagerConnected(status);
} break;
}
}
};
private void opencvProcess(Bitmap image) {
BitmapFactory.Options options = new BitmapFactory.Options();
options.inDither = true;
options.inPreferredConfig = Bitmap.Config.ARGB_8888;
int l = CvType.CV_8UC1; //8-bit grey scale image
Utils.bitmapToMat(image, imageMat);
Mat matImageGrey = new Mat();
Imgproc.cvtColor(imageMat, matImageGrey, Imgproc.COLOR_BGR2GRAY);
Bitmap destImage;
destImage = Bitmap.createBitmap(image);
Mat dst2 = new Mat();
Utils.bitmapToMat(destImage, dst2);
Mat laplacianImage = new Mat();
dst2.convertTo(laplacianImage, l);
Imgproc.Laplacian(matImageGrey, laplacianImage, CvType.CV_8U);
Mat laplacianImage8bit = new Mat();
laplacianImage.convertTo(laplacianImage8bit, l);
Bitmap bmp = Bitmap.createBitmap(laplacianImage8bit.cols(), laplacianImage8bit.rows(), Bitmap.Config.ARGB_8888);
Utils.matToBitmap(laplacianImage8bit, bmp);
int[] pixels = new int[bmp.getHeight() * bmp.getWidth()];
bmp.getPixels(pixels, 0, bmp.getWidth(), 0, 0, bmp.getWidth(), bmp.getHeight());
int maxLap = -16777216; // 16m
for (int pixel : pixels) {
if (pixel > maxLap)
maxLap = pixel;
}
// private void processImageAsBitmap(String imageFilePath) {
// try {
// BitmapFactory.Options bitmapOptions = new BitmapFactory.Options();
// takePhotobitmap = BitmapFactory.decodeFile(imageFilePath, bitmapOptions);
//// setImageOrientation(imageFilePath, bitmap);
//
// if (takePhotobitmap != null) {
//
// opencvProcess(takePhotobitmap);
// if (isBlur) {
// reTakePhoto();
// } else {
// ByteArrayOutputStream byteArrayOutputStream = new ByteArrayOutputStream();
// takePhotobitmap.compress(Bitmap.CompressFormat.JPEG, 75, byteArrayOutputStream);
// byte[] byteArray = byteArrayOutputStream.toByteArray();
// String base64Image = Base64.encodeToString(byteArray, Base64.DEFAULT);
// addMessage(mLoggedInUsername, "", takePictureFilePath);
//
// if (null == mLoggedInUsername) return;
// if (!mSocket.connected()) return;
// textDotLoader.show();
//
// // perform the sending message attempt.
// JSONObject jsonObject = new JSONObject();
// try {
// jsonObject.put(CLIENT_MESSAGE_KEY, "");
// jsonObject.put(CLIENT_MAIL_KEY, PrefManager.getSharedPref(this, PrefManager.PREFERENCE_USER_EMAIL_ID));
// jsonObject.put(SESSION_ID_UNIQ, PrefManager.getSharedPref(ChatActivity.this, PrefManager.SESSION_ID));
// jsonObject.put(LOCATION, "location");
// jsonObject.put(USER_SYSID, userSysId);
// jsonObject.put(SCANNED_IMAGE, base64Image);
// } catch (JSONException e) {
// e.printStackTrace();
// }
// mSocket.emit(NEW_MESSAGE, jsonObject);
// }
//
// } else {
// }
//
//
// } catch (Exception e) {
// e.printStackTrace();
// }
// }
int soglia = -6118750;
if (maxLap <= soglia) {
System.out.println("is blur image");
}
soglia += 6118750;
maxLap += 6118750;
opencvEnd = true;
isBlur = maxLap <= soglia;
}
// private BaseLoaderCallback mLoaderCallback = new BaseLoaderCallback(this) {
// @Override
// public void onManagerConnected(int status) {
// switch (status) {
// case LoaderCallbackInterface.SUCCESS:
// {
// Log.i("OpenCV", "OpenCV loaded successfully");
// imageMat=new Mat();
// } break;
// default:
// {
// super.onManagerConnected(status);
// } break;
// }
// }
// };
// private void opencvProcess(Bitmap image) {
// BitmapFactory.Options options = new BitmapFactory.Options();
// options.inDither = true;
// options.inPreferredConfig = Bitmap.Config.ARGB_8888;
// int l = CvType.CV_8UC1; //8-bit grey scale image
//
// Utils.bitmapToMat(image, imageMat);
// Mat matImageGrey = new Mat();
// Imgproc.cvtColor(imageMat, matImageGrey, Imgproc.COLOR_BGR2GRAY);
//
// Bitmap destImage;
// destImage = Bitmap.createBitmap(image);
// Mat dst2 = new Mat();
// Utils.bitmapToMat(destImage, dst2);
// Mat laplacianImage = new Mat();
// dst2.convertTo(laplacianImage, l);
// Imgproc.Laplacian(matImageGrey, laplacianImage, CvType.CV_8U);
// Mat laplacianImage8bit = new Mat();
// laplacianImage.convertTo(laplacianImage8bit, l);
//
// Bitmap bmp = Bitmap.createBitmap(laplacianImage8bit.cols(), laplacianImage8bit.rows(), Bitmap.Config.ARGB_8888);
// Utils.matToBitmap(laplacianImage8bit, bmp);
// int[] pixels = new int[bmp.getHeight() * bmp.getWidth()];
// bmp.getPixels(pixels, 0, bmp.getWidth(), 0, 0, bmp.getWidth(), bmp.getHeight());
//
// int maxLap = -16777216; // 16m
// for (int pixel : pixels) {
// if (pixel > maxLap)
// maxLap = pixel;
// }
//
// int soglia = -6118750;
// if (maxLap <= soglia) {
// System.out.println("is blur image");
// }
// soglia += 6118750;
// maxLap += 6118750;
// opencvEnd = true;
// isBlur = maxLap <= soglia;
// }
private void checkTTS() {
Intent check = new Intent();
......@@ -1273,15 +1266,17 @@ public class ChatActivity extends AppCompatActivity implements OnDSListener, OnD
public void onResume()
{
super.onResume();
if(mSocket != null && !mSocket.connected())
if(mSocket != null && !mSocket.connected()){
mSocket.connect();
if (!OpenCVLoader.initDebug()) {
Log.d("OpenCV", "Internal OpenCV library not found. Using OpenCV Manager for initialization");
OpenCVLoader.initAsync(OpenCVLoader.OPENCV_VERSION_3_0_0, this, mLoaderCallback);
} else {
Log.d("OpenCV", "OpenCV library found inside package. Using it!");
mLoaderCallback.onManagerConnected(LoaderCallbackInterface.SUCCESS);
}
// if (!OpenCVLoader.initDebug()) {
// Log.d("OpenCV", "Internal OpenCV library not found. Using OpenCV Manager for initialization");
// OpenCVLoader.initAsync(OpenCVLoader.OPENCV_VERSION_3_0_0, this, mLoaderCallback);
// } else {
// Log.d("OpenCV", "OpenCV library found inside package. Using it!");
// mLoaderCallback.onManagerConnected(LoaderCallbackInterface.SUCCESS);
// }
}
RecyclerView.OnItemTouchListener mOnItemTouchListener = new RecyclerView.OnItemTouchListener() {
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or sign in to comment