Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

ADD) save plate image #1

Open
wants to merge 6 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .idea/gradle.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

113 changes: 113 additions & 0 deletions app/src/main/java/com/carplate/camerax/DBHelper.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,113 @@
package com.carplate.camerax;
import android.content.Context;
import android.database.Cursor;
import android.database.sqlite.SQLiteDatabase;
import android.database.sqlite.SQLiteOpenHelper;

public class DBHelper extends SQLiteOpenHelper {
static final String DATABASE_NAME = "test.db";

// DBHelper 생성자
public DBHelper(Context context, int version) {
super(context, DATABASE_NAME, null, version);
}

// Person Table 생성
@Override
public void onCreate(SQLiteDatabase db) {
db.execSQL("CREATE TABLE ExistCar(carNum TEXT)");
}

// Person Table Upgrade
@Override
public void onUpgrade(SQLiteDatabase db, int oldVersion, int newVersion) {
db.execSQL("DROP TABLE IF EXISTS Person");
onCreate(db);
}

// Person Table 데이터 입력
public void insert(String carNum) {
SQLiteDatabase db = getWritableDatabase();
db.execSQL("INSERT INTO ExistCar VALUES('" + carNum + "')");
db.close();
}

/*
// Person Table 데이터 수정
public void Update(String name, int age, String Addr) {
SQLiteDatabase db = getWritableDatabase();
db.execSQL("UPDATE Person SET age = " + age + ", ADDR = '" + Addr + "'" + " WHERE NAME = '" + name + "'");
db.close();
}


// Person Table 데이터 삭제
public void Delete(String name) {
SQLiteDatabase db = getWritableDatabase();
db.execSQL("DELETE Person WHERE NAME = '" + name + "'");
db.close();
}

*/

// Person Table 조회
public boolean getResult(String carNum) {
// 읽기가 가능하게 DB 열기
SQLiteDatabase db = getReadableDatabase();

// DB에 있는 데이터를 쉽게 처리하기 위해 Cursor를 사용하여 테이블에 있는 모든 데이터 출력
Cursor cursor = db.rawQuery("SELECT * FROM ExistCar WHERE carNum = ?", new String[] {carNum});
while (cursor.moveToNext()) {
return true;
}

return false;
}
}

/*
public class ConnectDB {
private static ConnectDB instance = new ConnectDB();

public static ConnectDB getInstance() {
return instance;
}
public ConnectDB() { }

// oracle 계정
String jdbcUrl = "jdbc:oracle:thin:@IPv4주소:1521:testdb";
String userId = "test";
String userPw = "test";

Connection conn = null;
PreparedStatement pstmt = null;
ResultSet rs = null;

String sql = "";
String returns = "a";

public String connectionDB(String detectNum) {
try {
Class.forName("oracle.jdbc.driver.OracleDriver");
conn = DriverManager.getConnection(jdbcUrl, userId, userPw);

sql = "SELECT id FROM plateNumTable WHERE plateNum = ?";
pstmt = conn.prepareStatement(sql);
pstmt.setString(1, detectNum);

rs = pstmt.executeQuery();
if (rs.next()) {
returns = "DB에 존재하는 차량";
} else {
returns = "DB에 존재하지 않는 차량";
}
} catch (Exception e) {
e.printStackTrace();
} finally {
if (pstmt != null)try {pstmt.close();} catch (SQLException ex) {}
if (conn != null)try {conn.close(); } catch (SQLException ex) { }
}
return returns;
}
}
*/
87 changes: 73 additions & 14 deletions app/src/main/java/com/carplate/camerax/MainActivity.java
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
package com.carplate.camerax;



import androidx.appcompat.app.AppCompatActivity;

import android.annotation.SuppressLint;
Expand All @@ -16,6 +14,7 @@
import android.widget.Button;
import android.widget.ImageView;
import android.widget.TextView;
import android.widget.Toast;

import org.opencv.android.BaseLoaderCallback;
import org.opencv.android.CameraBridgeViewBase;
Expand All @@ -35,7 +34,9 @@
import org.tensorflow.lite.nnapi.NnApiDelegate;



import java.io.File;
import java.io.FileNotFoundException;
import java.io.FileOutputStream;
import java.io.IOException;
import java.util.ArrayList;
import java.util.Collections;
Expand Down Expand Up @@ -76,6 +77,8 @@ public class MainActivity extends AppCompatActivity
private Bitmap onFrame2; // alignment input
private Bitmap onFrame3; // char input

String beforePlate = "0";

// 모델 정의
DHDetectionModel detectionModel;
AlignmentModel alignmentModel;
Expand Down Expand Up @@ -356,23 +359,79 @@ public Mat onCameraFrame(CameraBridgeViewBase.CvCameraViewFrame inputFrame) {
double fps = Math.round(((1.0/(end-start))*1000*100.0))/100.0;
String infer_result = fps + " fps";

runOnUiThread(new Runnable() {
@Override
public void run() {
try {
tvTime.setText(infer_result);
textView.setText(result2);
imageView.setImageBitmap(onFrame3);
} catch (Exception e) {
e.printStackTrace();
if(result2.equals(beforePlate)){}
else {
runOnUiThread(new Runnable() {
@Override
public void run() {
try {
tvTime.setText(infer_result);
textView.setText(result2);
imageView.setImageBitmap(onFrame3);
beforePlate = result2;
saveImg(onFrame3, result2);
DBHelper dbHelper = new DBHelper(MainActivity.this, 1);
//String checkDB = connectDB.connectionDB(result2);

if(dbHelper.getResult(result2)) {
Toast.makeText(MainActivity.this, "exist", Toast.LENGTH_SHORT).show();
}else{
Toast.makeText(MainActivity.this, "no exist", Toast.LENGTH_SHORT).show();
}

} catch (Exception e) {
e.printStackTrace();
}
}
}
});
});
}
}
else{

m_CameraView.enableView();
}
return matInput;
}

private void saveImg(Bitmap bitmap, String textview) {

try {
//저장할 파일 경로
File storageDir = new File(getFilesDir() + "/capture");
if (!storageDir.exists()) //폴더가 없으면 생성.
storageDir.mkdirs();

String filename = textView.getText().toString() + ".jpg";

// 기존에 있다면 삭제
File file = new File(storageDir, filename);
boolean deleted = file.delete();
Log.d("TAG", "Delete Dup Check : " + deleted);
FileOutputStream output = null;

try {
output = new FileOutputStream(file);
//BitmapDrawable drawable = (BitmapDrawable) ivCapture.getDrawable();
//Bitmap bitmap = drawable.getBitmap();
bitmap.compress(Bitmap.CompressFormat.JPEG, 70, output); //해상도에 맞추어 Compress
} catch (FileNotFoundException e) {
e.printStackTrace();
} finally {
try {
assert output != null;
output.close();
} catch (IOException e) {
e.printStackTrace();
}
}

Log.d("TAG", "Captured Saved");
Toast.makeText(this, "Capture Saved ", Toast.LENGTH_SHORT).show();
} catch (Exception e) {
Log.d("TAG", "Capture Saving Error!", e);
Toast.makeText(this, "Save failed", Toast.LENGTH_SHORT).show();

}
}

}
9 changes: 9 additions & 0 deletions opencv/build/intermediates/cxx/create_cxx_tasks_30_timing.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
# C/C++ build system timings
create_cxx_tasks
create-initial-cxx-model
create-module-model 16ms
create-ARM64_V8A-model 10ms
[gap of 25ms]
create-initial-cxx-model completed in 54ms
create_cxx_tasks completed in 54ms

11 changes: 11 additions & 0 deletions opencv/build/intermediates/cxx/ndk_locator_record_366m712u.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
{
"ndk": "C:\\CookAndroid\\SDK\\ndk\\23.1.7779620",
"revision": {
"mMajor": 23,
"mMinor": 1,
"mMicro": 7779620,
"mPreview": 0,
"mPrecision": "MICRO",
"mPreviewSeparator": " "
}
}
86 changes: 86 additions & 0 deletions opencv/build/intermediates/cxx/ndk_locator_record_366m712u.log
Original file line number Diff line number Diff line change
@@ -0,0 +1,86 @@
[
{
"level_": 0,
"message_": "android.ndkVersion from module build.gradle is [not set]",
"file_": "",
"tag_": "",
"diagnosticCode_": 0,
"memoizedIsInitialized": 1,
"unknownFields": {
"fields": {},
"fieldsDescending": {}
},
"memoizedSize": -1,
"memoizedHashCode": 2084317329
},
{
"level_": 0,
"message_": "android.ndkPath from module build.gradle is not set",
"file_": "",
"tag_": "",
"diagnosticCode_": 0,
"memoizedIsInitialized": 1,
"unknownFields": {
"fields": {},
"fieldsDescending": {}
},
"memoizedSize": -1,
"memoizedHashCode": -1418461864
},
{
"level_": 0,
"message_": "ndk.dir in local.properties is not set",
"file_": "",
"tag_": "",
"diagnosticCode_": 0,
"memoizedIsInitialized": 1,
"unknownFields": {
"fields": {},
"fieldsDescending": {}
},
"memoizedSize": -1,
"memoizedHashCode": -714000671
},
{
"level_": 0,
"message_": "Not considering ANDROID_NDK_HOME because support was removed after deprecation period.",
"file_": "",
"tag_": "",
"diagnosticCode_": 0,
"memoizedIsInitialized": 1,
"unknownFields": {
"fields": {},
"fieldsDescending": {}
},
"memoizedSize": -1,
"memoizedHashCode": 1148813399
},
{
"level_": 0,
"message_": "sdkFolder is C:\\CookAndroid\\SDK",
"file_": "",
"tag_": "",
"diagnosticCode_": 0,
"memoizedIsInitialized": 1,
"unknownFields": {
"fields": {},
"fieldsDescending": {}
},
"memoizedSize": -1,
"memoizedHashCode": -1616183371
},
{
"level_": 0,
"message_": "Because no explicit NDK was requested, the default version [23.1.7779620] for this Android Gradle Plugin will be used",
"file_": "",
"tag_": "",
"diagnosticCode_": 0,
"memoizedIsInitialized": 1,
"unknownFields": {
"fields": {},
"fieldsDescending": {}
},
"memoizedSize": -1,
"memoizedHashCode": 2082435688
}
]
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
{
"sdkFolder": "C:\\CookAndroid\\SDK",
"sideBySideNdkFolderNames": [
"23.1.7779620"
]
}