Skip to content

Commit

Permalink
Merge branch 'master' of https://github.com/tink-expo/cs470-auto-wifi
Browse files Browse the repository at this point in the history
…into id-pw-pick
  • Loading branch information
tink-expo committed Dec 1, 2019
2 parents ec7f2d4 + dd37f4f commit 9a78723
Show file tree
Hide file tree
Showing 31 changed files with 451 additions and 121 deletions.
48 changes: 46 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,2 +1,46 @@
## Android App for automatic Wifi connection using OCR
This is a team repository for CS470 final project.
# Android App for automatic Wifi connection using OCR
>This is a team 12 repository for CS470 final project.
<br></br>

## Application Overview
When using the provided network in places like cafe, people have to search for the matching WIFI network ID in the available WIFI list and type the PW manually.
**This Android application will enable user to connect to WIFI automatically by just simply scanning the picture that contains WIFI ID and PW**

<img src="./image_readme/wifi.jpg" width="450px"></img>

<br></br>

## Process Pipeline
1. [Input] Picture that contains WIFI ID and PW. The picture can contain letters other than the ID and PW, and the letters can be hand-written.
2. Detect the words and their positions using OCR pretrained model.
3. From the detected information in step 2, extract WIFI ID and PW.
4. Using Android network API, connect to WIFI automatically using retrieved ID and PW.

<br></br>

## Use Flow
<img src="./image_readme/Use Flow.png"></img>

<br></br>

## Considerations for Implementation
### Evaluation
Though we use pretrained model for OCR, we have to post process the ID and PW information from the OCR model output. We will evaluate out application by measuring the success rate of "Extracting both correct ID and PW from arbitrary WIFI information picture".

### Input data
Though we use pretrained model, we need input data for making a good post processing strategy and evaluation.
We will first collect some real WIFI information picture data by Hand collecting and crawl from Google image search.
Since the images we require are very specific, the amount of data that can be collected by above ways might not be large. However, the reason we need input data is not for training but for evaluation and deciding post processing strategy. If the collected data is too small even for above objectives, we will search for other ways to enlarge the data. (e.g. generation based on collected real data)

### OCR model
We will modularize here, and first use OCR cloud API.
This will require network connection, so we will try applying an on-device model if time allows.
Model output will be collection of
{Detected characters, Bounding box position and size}s

### Post processing for ID and PW extraction
We will first try deterministic way for this, using approaches listed below. If it is too unsuccessful, we should search for other approaches.
- Word position and size. (Centered, Big, SSID is usually followed by Password, etc)
- Field tag. (ID, PW, etc)
- Match with retrieved available Wi-fi SSIDs.
2 changes: 1 addition & 1 deletion android/app/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@
android:label="@string/app_name"
android:roundIcon="@mipmap/ic_launcher_round"
android:supportsRtl="true"
android:theme="@style/AppTheme">
android:theme="@style/AppTheme.NoActionBar">
<activity
android:name=".MainActivity"
android:label="@string/app_name"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
import android.view.SurfaceView;
import android.view.View;
import android.view.WindowManager;
import android.widget.Button;
import android.widget.ImageButton;

public class CameraActivity extends AppCompatActivity {
private SurfaceView surfaceView;
Expand All @@ -24,7 +24,7 @@ protected void onCreate(Bundle savedInstanceState) {
surfaceView = findViewById(R.id.cameraSurfaceView);
cameraPreview = new CameraPreview(this, this, Camera.CameraInfo.CAMERA_FACING_BACK, surfaceView);

Button button = findViewById(R.id.cameraButton);
ImageButton button = findViewById(R.id.cameraButton);
button.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
import android.support.v7.app.AppCompatActivity;
import android.util.Log;
import android.view.View;
import android.widget.Button;
import android.widget.ImageButton;

public class MainActivity extends AppCompatActivity {

Expand All @@ -14,8 +14,8 @@ protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);

Button button = (Button) findViewById(R.id.mainButton);
button.setOnClickListener(new Button.OnClickListener() {
ImageButton button = (ImageButton) findViewById(R.id.mainButton);
button.setOnClickListener(new ImageButton.OnClickListener() {
@Override
public void onClick(View view) {
Intent intent = new Intent(MainActivity.this, CameraActivity.class);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,10 +9,10 @@
import android.net.wifi.ScanResult;
import android.net.wifi.WifiManager;
import android.os.Bundle;
import android.os.Handler;
import android.support.v7.app.AppCompatActivity;
import android.util.Log;
import android.widget.ImageView;
import android.widget.TextView;

import com.example.hsh0908y.auto_wifi.common.SsidPw;
import com.example.hsh0908y.auto_wifi.common.TextBlock;
Expand All @@ -28,6 +28,7 @@
public class ProcessingActivity extends AppCompatActivity {

final static String TAG = "ProcessingActivity";
final static int IMAGE_ANIMATE_PERIOD = 2000;

private boolean hasTriedWifiConnect = false;
private String selectedSsid;
Expand Down Expand Up @@ -56,14 +57,23 @@ protected void onCreate(Bundle savedInstanceState) {

selectedSsid = intent.getStringExtra("selectedSsid");

// Temporary: show image and hasId
ImageView imageView = (ImageView) findViewById(R.id.processingImageView);
imageView.setImageBitmap(unscaledBitmap);
TextView textView = (TextView) findViewById(R.id.processingTextView);
textView.setText("hasId : " + String.valueOf(selectedSsid == null));

wifiManager = (WifiManager) getApplicationContext().getSystemService(Context.WIFI_SERVICE);
Log.d(TAG, String.valueOf(wifiManager.getConnectionInfo() == null));

// Animate loading image
final ImageView imageView = (ImageView) findViewById(R.id.processingImageView);
final Handler handler = new Handler();
final int[] images = new int[] {R.drawable.icon_wifi_1, R.drawable.icon_wifi_2, R.drawable.icon_wifi_3};
final int[] currentIdx = new int[] {0};
Runnable imageAnimateRunnable = new Runnable() {
@Override
public void run() {
imageView.setImageResource(images[currentIdx[0]]);
currentIdx[0] = (currentIdx[0] + 1) % images.length;
handler.postDelayed(this, IMAGE_ANIMATE_PERIOD);
}
};
handler.postDelayed(imageAnimateRunnable, IMAGE_ANIMATE_PERIOD);
}

@Override
Expand Down
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added android/app/src/main/res/drawable/icon_wifi_1.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added android/app/src/main/res/drawable/icon_wifi_2.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added android/app/src/main/res/drawable/icon_wifi_3.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
5 changes: 5 additions & 0 deletions android/app/src/main/res/drawable/rectangle.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
<?xml version="1.0" encoding="UTF-8"?>
<shape xmlns:android="http://schemas.android.com/apk/res/android" android:id="@+id/rectangle">
<corners android:radius="10dp" />
<solid android:color="#ffffffff" />
</shape>
5 changes: 5 additions & 0 deletions android/app/src/main/res/drawable/rectangle_opaque.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
<?xml version="1.0" encoding="UTF-8"?>
<shape xmlns:android="http://schemas.android.com/apk/res/android" android:id="@+id/rectangle">
<corners android:radius="10dp" />
<solid android:color="#e0ffffff" />
</shape>
48 changes: 37 additions & 11 deletions android/app/src/main/res/layout/activity_camera.xml
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
<android.support.constraint.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:background="@color/colorWhite"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context="com.example.hsh0908y.auto_wifi.CameraActivity">
Expand All @@ -10,32 +11,42 @@
android:id="@+id/cameraSurfaceView"
android:layout_width="match_parent"
android:layout_height="0dp"
app:layout_constraintBottom_toBottomOf="@id/cameraMenusLayout"
app:layout_constraintDimensionRatio="3:4"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent"
app:layout_constraintVertical_bias="0.0" />
app:layout_constraintTop_toTopOf="parent" />

<android.support.constraint.ConstraintLayout
android:id="@+id/cameraMenusLayout"
android:layout_width="match_parent"
android:layout_height="0dp"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintTop_toBottomOf="@id/cameraSurfaceView">
app:layout_constraintTop_toTopOf="parent">

<View
android:id="@+id/rectangleView4"
android:layout_width="0dp"
android:layout_height="72dp"
android:layout_marginBottom="24dp"
android:layout_marginEnd="45dp"
android:layout_marginStart="45dp"
android:background="@drawable/rectangle_opaque"
app:layout_constraintBottom_toTopOf="@+id/cameraButton"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent" />

<RadioGroup
android:layout_width="wrap_content"
android:id="@+id/radioGroup"
android:layout_width="200dp"
android:layout_height="wrap_content"
android:layout_marginEnd="16dp"
android:layout_marginStart="16dp"
android:layout_marginBottom="8dp"
android:checkedButton="@+id/cameraRadioButtonIdpw"
android:orientation="horizontal"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent"
app:layout_constraintBottom_toTopOf="@id/cameraButton"
tools:layout_editor_absoluteY="363dp">
app:layout_constraintBottom_toBottomOf="@id/rectangleView4">

<RadioButton
android:id="@+id/cameraRadioButtonIdpw"
Expand All @@ -52,17 +63,32 @@
android:text="Only PW" />
</RadioGroup>

<Button
<ImageButton
android:id="@+id/cameraButton"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginBottom="16dp"
android:layout_marginEnd="16dp"
android:layout_marginStart="16dp"
android:text="Button"
android:background="@android:color/transparent"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent" />
app:layout_constraintStart_toStartOf="parent"
app:srcCompat="@drawable/icon_camera_btn" />

<TextView
android:id="@+id/textView3"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginEnd="16dp"
android:layout_marginStart="16dp"
android:layout_marginTop="8dp"
android:text="Take a photo with Wi-Fi information"
android:textColor="@color/colorBlack"
android:textSize="16sp"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="@+id/rectangleView4" />
</android.support.constraint.ConstraintLayout>

</android.support.constraint.ConstraintLayout>
Loading

0 comments on commit 9a78723

Please sign in to comment.