Commit c385d98d authored by Pyone Thant Win's avatar Pyone Thant Win
Browse files

OpenCV, Image attributes

parent 280d8b02
......@@ -17,6 +17,7 @@ android {
proguardFiles getDefaultProguardFile('proguard-android-optimize.txt'), 'proguard-rules.pro'
}
}
sourceSets { main { jni.srcDirs = ['src/main/jni', 'src/main/jniLibs/'] } }
}
dependencies {
......@@ -30,4 +31,5 @@ dependencies {
implementation 'com.android.volley:volley:1.1.1'
implementation 'com.google.code.gson:gson:2.4'
implementation project(path: ':openCVLibrary3410')
implementation 'com.squareup.picasso:picasso:2.71828'
}
......@@ -18,12 +18,10 @@
android:roundIcon="@mipmap/ic_launcher_round"
android:supportsRtl="true"
android:theme="@style/AppTheme">
<activity android:name=".export_data"></activity>
<activity android:name=".side_ruler"></activity>
<activity android:name=".import_pictures" />
<activity android:name=".export_data" />
<activity android:name=".foodInfo" />
<activity
android:name=".take_picture"
android:label="@string/title_activity_take_picture"
android:theme="@style/AppTheme.NoActionBar" />
<activity android:name=".login" />
<activity android:name=".MainActivity">
<intent-filter>
......
......@@ -7,18 +7,28 @@ import android.content.Intent;
import android.database.sqlite.SQLiteDatabase;
import android.database.sqlite.SQLiteOpenHelper;
import android.os.Bundle;
import android.util.Log;
import android.view.View;
import android.widget.Button;
import android.widget.EditText;
import android.widget.Toast;
import org.opencv.android.OpenCVLoader;
public class MainActivity extends AppCompatActivity {
SQLiteOpenHelper openHelper;
SQLiteDatabase db;
Button _btnregister, _btn_to_login, _btn_skip;
EditText _fname, _lname, _user_email, _user_pswd;
private static String TAG = "MAIN ACTIVITY";
static {
if (OpenCVLoader.initDebug()){
Log.i(TAG, "OPENCV Loaded Successfully");
} else {
Log.i(TAG, "OPENCV Not Loaded");
}
}
@Override
protected void onCreate(Bundle savedInstanceState) {
......
......@@ -9,6 +9,7 @@ import android.view.View;
import android.widget.Button;
import android.widget.EditText;
import android.widget.TextView;
import android.widget.Toast;
import java.io.BufferedReader;
import java.io.IOException;
......@@ -35,9 +36,13 @@ public class export_data extends AppCompatActivity {
@Override
public void onClick(View view) {
fr_density = getCSVDATA(_txt_fruitName.getText().toString());
Intent intent = new Intent(export_data.this, foodInfo.class);
intent.putExtra("density", fr_density);
startActivity(intent);
if (fr_density != 0){
Intent intent = new Intent(export_data.this, import_pictures.class);
intent.putExtra("density", fr_density);
startActivity(intent);
} else {
Toast.makeText(getApplicationContext(), "Sorry, the fruit is not in our database yet. Please put another fruit.", Toast.LENGTH_SHORT).show();
}
}
});
......
package com.example.calorieestimator;
import androidx.annotation.NonNull;
import androidx.annotation.Nullable;
import androidx.appcompat.app.AppCompatActivity;
import android.Manifest;
import android.content.Intent;
import android.content.pm.PackageManager;
import android.media.ExifInterface;
import android.net.Uri;
import android.os.Build;
import android.os.Bundle;
import android.provider.ContactsContract;
import android.util.Log;
import android.util.Rational;
import android.view.View;
import android.widget.Button;
import android.widget.ImageView;
import android.widget.TextView;
import android.widget.Toast;
import com.squareup.picasso.Picasso;
import java.io.IOException;
import java.io.InputStream;
public class import_pictures extends AppCompatActivity {
Button _get_side, _btn_next;
ImageView _side_view, _ruler;
private static final int IMAGE_PICK_CODE=1000;
private static final int PERMISSION_CODE=1001;
String focal_length;
String pathStr;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_import_pictures);
final Double density = getIntent().getExtras().getDouble("density");
_get_side = (Button)findViewById(R.id.btn_getSide);
_btn_next = (Button)findViewById(R.id.btn_next);
_side_view = (ImageView)findViewById(R.id.imageView_side);
_ruler = (ImageView)findViewById(R.id.imageView_ruler);
final String ruler_URL = "https://lh3.googleusercontent.com/proxy/8DtFyFkBz3Dzyt8cr8x7JGh2X5WAgQGC3rXn9gLwO0tDKGFBM7TXAoFZXiM0YrcAd4iHcEagGZU0q0iX7DW93i5OndoN-66v";
_get_side.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
Picasso.get().load(ruler_URL).into(_ruler);
openGallery();
}
});
_btn_next.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
//Toast.makeText(getApplicationContext(), focal_length, Toast.LENGTH_SHORT).show();
if (pathStr == ""){
Toast.makeText(getApplicationContext(), "Please select a picture", Toast.LENGTH_SHORT).show();
} else {
Intent intent = new Intent(import_pictures.this, side_ruler.class);
intent.getIntExtra("Focal_length", Integer.valueOf(focal_length));
intent.getDoubleExtra("density", density);
startActivity(intent);
}
//Toast.makeText(getApplicationContext(), side_path, Toast.LENGTH_SHORT).show();
}
});
}
private void openGallery(){
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) {
if (checkSelfPermission(Manifest.permission.READ_EXTERNAL_STORAGE) == PackageManager.PERMISSION_DENIED){
String[] permissions = {Manifest.permission.READ_EXTERNAL_STORAGE};
requestPermissions(permissions, PERMISSION_CODE);
} else {
Intent intent = new Intent(Intent.ACTION_PICK);
intent.setType("image/*");
startActivityForResult(intent, IMAGE_PICK_CODE);
}
}
}
@Override
public void onRequestPermissionsResult(int requestCode, @NonNull String[] permissions, @NonNull int[] grantResults) {
switch (requestCode) {
case PERMISSION_CODE:{
if (grantResults.length > 0 && grantResults[0] == PackageManager.PERMISSION_GRANTED){
openGallery();
} else {
Toast.makeText(this, "Permission Denied. Required to grant access.", Toast.LENGTH_SHORT).show();
}
}
}
}
@Override
protected void onActivityResult(int requestCode, int resultCode, @Nullable Intent data) {
//String path = "";
if (resultCode == RESULT_OK && requestCode == IMAGE_PICK_CODE){
Uri path = data.getData();
pathStr = data.getData().getPath();
_side_view.setImageURI(data.getData());
try{
InputStream in = getContentResolver().openInputStream(path);
ExifInterface exif = new ExifInterface(in);
focal_length= exif.getAttribute(ExifInterface.TAG_FOCAL_LENGTH);
focal_length = focal_length.split("/", 2)[0];
} catch (IOException e){
Log.e("ERRORRRRR", e.toString());
e.printStackTrace();
}
}
}
}
package com.example.calorieestimator;
import androidx.appcompat.app.AppCompatActivity;
import android.os.Bundle;
import android.widget.Button;
import android.widget.EditText;
import android.widget.ImageView;
public class side_ruler extends AppCompatActivity {
EditText width, height;
Button _btn_next;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_side_ruler);
Integer focal_length = getIntent().getExtras().getInt("Focal_length");
Double density = getIntent().getExtras().getDouble("density");
width = (EditText)findViewById(R.id.width_text);
height = (EditText)findViewById(R.id.height_text);
Double real_width;
Double real_height;
}
}
<?xml version="1.0" encoding="utf-8"?>
<androidx.constraintlayout.widget.ConstraintLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context=".import_pictures">
<TextView
android:id="@+id/textView2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginStart="173dp"
android:layout_marginTop="35dp"
android:layout_marginEnd="179dp"
android:layout_marginBottom="10dp"
android:text="Please pick the side view of fruit:"
android:textSize="20sp"
app:layout_constraintBottom_toTopOf="@+id/imageView_side"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintHorizontal_bias="0.491"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent" />
<Button
android:id="@+id/btn_getSide"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginStart="56dp"
android:layout_marginTop="10dp"
android:layout_marginEnd="10dp"
android:layout_marginBottom="60dp"
android:text="Go to gallery"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toStartOf="@+id/btn_next"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@+id/scroller" />
<Button
android:id="@+id/btn_next"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginStart="10dp"
android:layout_marginTop="10dp"
android:layout_marginEnd="58dp"
android:layout_marginBottom="60dp"
android:text="Next"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toEndOf="@+id/btn_getSide"
app:layout_constraintTop_toBottomOf="@+id/scroller"
app:layout_constraintVertical_bias="0.50" />
<ImageView
android:id="@+id/imageView_side"
android:layout_width="408dp"
android:layout_height="337dp"
android:layout_marginTop="10dp"
android:layout_marginBottom="0dp"
app:layout_constraintBottom_toTopOf="@+id/scroller"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintHorizontal_bias="0.333"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@+id/textView2"
app:srcCompat="@mipmap/ic_launcher" />
<ScrollView
android:id="@+id/scroller"
android:layout_width="410dp"
android:layout_height="25mm"
android:layout_marginTop="0dp"
android:layout_marginBottom="10dp"
app:layout_constraintBottom_toTopOf="@+id/btn_getSide"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintHorizontal_bias="0.0"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@+id/imageView_side">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical">
<ImageView
android:id="@+id/imageView_ruler"
android:layout_width="300mm"
android:layout_height="25mm"
android:layout_marginTop="2dp"
android:layout_marginBottom="5dp"
app:layout_constraintBottom_toTopOf="@+id/scroller"
app:layout_constraintStart_toStartOf="@+id/scroller"
app:layout_constraintTop_toBottomOf="@+id/scroller"
app:layout_constraintVertical_bias="0.551"
app:srcCompat="@drawable/ic_launcher_foreground" />
</LinearLayout>
</ScrollView>
</androidx.constraintlayout.widget.ConstraintLayout>
\ No newline at end of file
<?xml version="1.0" encoding="utf-8"?>
<androidx.constraintlayout.widget.ConstraintLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context=".side_ruler">
<TextView
android:id="@+id/textView4"
android:layout_width="326dp"
android:layout_height="118dp"
android:layout_marginStart="42dp"
android:layout_marginTop="100dp"
android:layout_marginEnd="43dp"
android:layout_marginBottom="9dp"
android:text="Please put the estimation of fruit width and height based on the centimeter ruler reference earlier:"
android:textSize="24sp"
app:layout_constraintBottom_toTopOf="@+id/textView5"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent" />
<TextView
android:id="@+id/textView5"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginStart="41dp"
android:layout_marginTop="9dp"
android:layout_marginEnd="260dp"
android:layout_marginBottom="7dp"
android:text="Width (in cm):"
android:textSize="18sp"
app:layout_constraintBottom_toTopOf="@+id/width_text"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@+id/textView4" />
<EditText
android:id="@+id/width_text"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginStart="42dp"
android:layout_marginTop="2dp"
android:layout_marginEnd="156dp"
android:layout_marginBottom="17dp"
android:ems="10"
android:inputType="number"
app:layout_constraintBottom_toTopOf="@+id/textView6"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@+id/textView5" />
<TextView
android:id="@+id/textView6"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginStart="43dp"
android:layout_marginTop="13dp"
android:layout_marginEnd="252dp"
android:layout_marginBottom="6dp"
android:text="Height (in cm):"
android:textSize="18sp"
app:layout_constraintBottom_toTopOf="@+id/height_text"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@+id/width_text" />
<EditText
android:id="@+id/height_text"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginStart="40dp"
android:layout_marginTop="2dp"
android:layout_marginEnd="158dp"
android:layout_marginBottom="50dp"
android:ems="10"
android:inputType="number"
app:layout_constraintBottom_toTopOf="@+id/btn_next"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@+id/textView6" />
<Button
android:id="@+id/btn_next"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginStart="160dp"
android:layout_marginTop="50dp"
android:layout_marginEnd="163dp"
android:layout_marginBottom="162dp"
android:text="Next"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@+id/height_text" />
</androidx.constraintlayout.widget.ConstraintLayout>
\ No newline at end of file
......@@ -16,5 +16,4 @@ org.gradle.jvmargs=-Xmx1536m
# https://developer.android.com/topic/libraries/support-library/androidx-rn
android.useAndroidX=true
# Automatically convert third-party libraries to use AndroidX
android.enableJetifier=true
android.enableJetifier=true
\ No newline at end of file
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 to comment