Skip to content

Commit

Permalink
PMD User Interface
Browse files Browse the repository at this point in the history
  • Loading branch information
linzuzeng committed Feb 5, 2018
1 parent 17fdbe0 commit 610b140
Show file tree
Hide file tree
Showing 3 changed files with 199 additions and 44 deletions.
129 changes: 109 additions & 20 deletions app/src/main/java/org/lezizi/microsphere/PMDActivity.java
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,14 @@
import android.content.Intent;
import android.graphics.Bitmap;
import android.os.Environment;
import android.support.design.widget.FloatingActionButton;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.support.v7.widget.Toolbar;
import android.view.View;
import android.widget.ImageView;
import android.widget.SeekBar;
import android.widget.TextView;

import org.opencv.android.Utils;
import org.opencv.core.CvType;
Expand All @@ -17,50 +22,134 @@
import org.opencv.imgcodecs.Imgcodecs;
import org.opencv.imgproc.Imgproc;

import java.security.Key;
import java.util.ArrayList;
import java.util.List;

public class PMDActivity extends AppCompatActivity {
protected MatOfKeyPoint keypoints;
protected Mat cimg;
protected Mat resized;
protected void update_preview(){
SeekBar bar1 = findViewById(R.id.seekBar1);
SeekBar bar2 = findViewById(R.id.seekBar2);
SeekBar bar3 = findViewById(R.id.seekBar3);
float barValue1 = bar1.getProgress()/(float)100.0;
float barValue2 = bar2.getProgress()/(float)100.0;
float barValue3 = bar3.getProgress()/(float)100.0;
TextView result= findViewById(R.id.textView2);

Mat out=new Mat(cimg.rows()/4, cimg.cols()/4, CvType.CV_64FC3);

ArrayList<KeyPoint> samll_list=new ArrayList<>();
ArrayList<KeyPoint> middle_list=new ArrayList<>();
ArrayList<KeyPoint> big_list=new ArrayList<>();
for (KeyPoint vkp : keypoints.toList())
{
if (vkp.size<barValue1){
samll_list.add(vkp);
}
if (barValue1<=vkp.size && vkp.size<barValue2){
middle_list.add(vkp);
}
if (barValue2<=vkp.size && vkp.size<barValue3){
big_list.add(vkp);
}
}

result.setText(String.format("(%.2f pix<d)=%d; (%.2f pix< d <%.2f pix)=%d; (%.2f pix< d <%.2f pix)=%d;",
barValue1,
samll_list.size(),
barValue1,
barValue2,
middle_list.size(),
barValue2,
barValue3,
big_list.size()
) );
MatOfKeyPoint small=new MatOfKeyPoint();
small.fromList(samll_list);
Features2d.drawKeypoints(resized,small,out,new org.opencv.core.Scalar(0,255,0), Features2d.DRAW_RICH_KEYPOINTS );

MatOfKeyPoint middle=new MatOfKeyPoint();
middle.fromList(middle_list);
Features2d.drawKeypoints(out,middle,out,new org.opencv.core.Scalar(0,0,255), Features2d.DRAW_RICH_KEYPOINTS );

MatOfKeyPoint big=new MatOfKeyPoint();
big.fromList(big_list);
Features2d.drawKeypoints(out,big,out,new org.opencv.core.Scalar(255,0,0), Features2d.DRAW_RICH_KEYPOINTS );

Mat m=new Mat(cimg.rows(), cimg.cols(), CvType.CV_64FC3);
Imgproc.resize(out, m, m.size(),0,0,Imgproc.INTER_AREA);


// convert to bitmap:
Bitmap bm = Bitmap.createBitmap(m.cols(), m.rows(),Bitmap.Config.ARGB_8888);
Utils.matToBitmap(m, bm);

// find the imageview and draw it!
ImageView iv = findViewById(R.id.imageView1);
iv.setImageBitmap(bm);
}
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_pmd);

Intent intent = getIntent();
String filename=intent.getStringExtra(MainActivity.PMDActivity_Filename);

FeatureDetector detector = FeatureDetector.create(FeatureDetector.SIMPLEBLOB);
detector.read(MainActivity.app_mainpath + "detector.xml");
Mat cimg;

try {
FeatureDetector detector = FeatureDetector.create(FeatureDetector.SIMPLEBLOB);
detector.read(MainActivity.app_mainpath + "detector.xml");
cimg = Imgcodecs.imread(filename);

resized = new Mat(cimg.rows()/4, cimg.cols()/4, CvType.CV_64FC3);
Imgproc.resize(cimg, resized, resized.size(),0,0,Imgproc.INTER_AREA);
keypoints=new MatOfKeyPoint();
detector.detect(resized,keypoints);
} catch (Exception e) {
finish();
return;
}
Mat resized = new Mat(cimg.rows()/4, cimg.cols()/4, CvType.CV_64FC3);
Imgproc.resize(cimg, resized, resized.size(),0,0,Imgproc.INTER_AREA);
MatOfKeyPoint keypoints = new MatOfKeyPoint();
detector.detect(resized,keypoints);

float max_size=0;
for (KeyPoint vkp : keypoints.toList())
{

if (vkp.size>max_size) max_size=vkp.size;
}
SeekBar bar1 = findViewById(R.id.seekBar1);
SeekBar bar2 = findViewById(R.id.seekBar2);
SeekBar bar3 = findViewById(R.id.seekBar3);
bar1.setMax((int)(max_size*100.0));
bar2.setMax((int)(max_size*100.0));
bar3.setMax((int)(max_size*100.0));

Mat out=new Mat(cimg.rows()/4, cimg.cols()/4, CvType.CV_64FC3);
Mat m=new Mat(cimg.rows(), cimg.cols(), CvType.CV_64FC3);

Features2d.drawKeypoints(resized,keypoints,out,new org.opencv.core.Scalar(0,255,0), Features2d.DRAW_RICH_KEYPOINTS );
Imgproc.resize(out, m, m.size(),0,0,Imgproc.INTER_AREA);
SeekBar.OnSeekBarChangeListener listener=new SeekBar.OnSeekBarChangeListener(){
@Override
public void onProgressChanged(SeekBar seekBar, int i, boolean b) {

if (b){
update_preview();
}
}

// convert to bitmap:
Bitmap bm = Bitmap.createBitmap(m.cols(), m.rows(),Bitmap.Config.ARGB_8888);
Utils.matToBitmap(m, bm);
@Override
public void onStartTrackingTouch(SeekBar seekBar) {

// find the imageview and draw it!
ImageView iv = findViewById(R.id.imageView1);
iv.setImageBitmap(bm);
}

@Override
public void onStopTrackingTouch(SeekBar seekBar) {

}
};

bar1.setOnSeekBarChangeListener(listener);
bar2.setOnSeekBarChangeListener(listener);
bar3.setOnSeekBarChangeListener(listener);

update_preview();
}

}
18 changes: 0 additions & 18 deletions app/src/main/res/layout/activity_maaresult.xml
Original file line number Diff line number Diff line change
Expand Up @@ -16,22 +16,4 @@
android:layout_height="0dp"
android:layout_width="0dp" />

<!--TextView
android:id="@+id/result_text2"
android:layout_width="0dp"
android:layout_height="0dp"
android:background="#ffffff"
android:gravity="center"
android:scrollHorizontally="false"
android:text="Hello World!"
android:textAppearance="@android:style/TextAppearance.DeviceDefault.Large"
android:visibility="visible"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintHorizontal_bias="1.0"
app:layout_constraintLeft_toLeftOf="parent"
app:layout_constraintRight_toRightOf="parent"
app:layout_constraintTop_toTopOf="parent"
app:layout_constraintVertical_bias="1.0" /-->
</android.support.constraint.ConstraintLayout>
96 changes: 90 additions & 6 deletions app/src/main/res/layout/activity_pmd.xml
Original file line number Diff line number Diff line change
@@ -1,15 +1,99 @@
<?xml version="1.0" encoding="utf-8"?>
<android.support.constraint.ConstraintLayout xmlns:android="http://schemas.android.com/apk/res/android"
<android.support.design.widget.CoordinatorLayout 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="org.lezizi.microsphere.PMDActivity">

<ImageView
android:id="@+id/imageView1"

<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:paddingLeft="10dp"
android:paddingRight="10dp"
android:orientation="vertical"
>
<TextView
android:id="@+id/textView1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"

android:gravity="center"
android:scrollHorizontally="false"
android:text="Diameter Range Configurations"
android:textAppearance="@android:style/TextAppearance.DeviceDefault.Medium"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintHorizontal_bias="1.0"
app:layout_constraintLeft_toLeftOf="parent"
app:layout_constraintRight_toRightOf="parent"
app:layout_constraintTop_toTopOf="parent"
app:layout_constraintVertical_bias="1.0" />


<SeekBar
android:id="@+id/seekBar1"
android:layout_width="match_parent"
android:layout_height="wrap_content"
/>


<SeekBar
android:id="@+id/seekBar2"
android:layout_width="match_parent"
android:layout_height="wrap_content"
/>


<SeekBar
android:id="@+id/seekBar3"
android:layout_width="match_parent"
android:layout_height="wrap_content"
/>
<TextView
android:id="@+id/textView3"
android:layout_width="wrap_content"
android:layout_height="wrap_content"

android:gravity="center"
android:scrollHorizontally="false"
android:text="Detection Result"
android:textAppearance="@android:style/TextAppearance.DeviceDefault.Medium"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintHorizontal_bias="1.0"
app:layout_constraintLeft_toLeftOf="parent"
app:layout_constraintRight_toRightOf="parent"
app:layout_constraintTop_toTopOf="parent"
app:layout_constraintVertical_bias="1.0" />
<TextView
android:id="@+id/textView2"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="No result." />
<ImageView
android:id="@+id/imageView1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:src="@color/album_FontLight"
/>

</LinearLayout>

<com.github.mikephil.charting.charts.BarChart
android:background="#ffffff"
android:id="@+id/result_text"
android:visibility="invisible"
android:layout_width="match_parent"
android:layout_height="match_parent"
/>

<android.support.design.widget.FloatingActionButton
android:id="@+id/fab"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:src="@color/album_FontLight"
/>
</android.support.constraint.ConstraintLayout>
android:layout_gravity="bottom|end"
android:layout_margin="@dimen/fab_margin"
app:srcCompat="@android:drawable/ic_menu_view" />


</android.support.design.widget.CoordinatorLayout>

0 comments on commit 610b140

Please sign in to comment.