Commit cafce5d8 by Simhachalam ch

removed opencv library to reduce the apk size

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