Memperbaiki OCR
This commit is contained in:
parent
6c5edf8997
commit
1b57781980
@ -12,6 +12,7 @@ use App\Models\User;
|
|||||||
use Barryvdh\DomPDF\Facade\Pdf;
|
use Barryvdh\DomPDF\Facade\Pdf;
|
||||||
use Carbon\Carbon;
|
use Carbon\Carbon;
|
||||||
use Illuminate\Support\Facades\DB;
|
use Illuminate\Support\Facades\DB;
|
||||||
|
use Illuminate\Support\Facades\Http;
|
||||||
use Illuminate\Support\Facades\Log;
|
use Illuminate\Support\Facades\Log;
|
||||||
use Illuminate\Support\Facades\Mail;
|
use Illuminate\Support\Facades\Mail;
|
||||||
use Illuminate\Support\Str;
|
use Illuminate\Support\Str;
|
||||||
@ -25,6 +26,7 @@ use Laravolt\Indonesia\Models\Province;
|
|||||||
use Laravolt\Indonesia\Models\Village;
|
use Laravolt\Indonesia\Models\Village;
|
||||||
use Pusher\Pusher;
|
use Pusher\Pusher;
|
||||||
use Ramsey\Uuid\Uuid;
|
use Ramsey\Uuid\Uuid;
|
||||||
|
use GuzzleHttp\Client;
|
||||||
|
|
||||||
class LoginController extends Controller
|
class LoginController extends Controller
|
||||||
{
|
{
|
||||||
@ -94,7 +96,6 @@ class LoginController extends Controller
|
|||||||
|
|
||||||
public function register(Request $request)
|
public function register(Request $request)
|
||||||
{
|
{
|
||||||
// return response()->json($request->all());
|
|
||||||
$request->validate(
|
$request->validate(
|
||||||
[
|
[
|
||||||
'nama_depan' => ['required'],
|
'nama_depan' => ['required'],
|
||||||
@ -181,64 +182,74 @@ class LoginController extends Controller
|
|||||||
$ktpBase64 = $request->request->get('ktp');
|
$ktpBase64 = $request->request->get('ktp');
|
||||||
$wajahBase64 = $request->request->get('wajah');
|
$wajahBase64 = $request->request->get('wajah');
|
||||||
|
|
||||||
$validatedData['email_verified_at'] = now();
|
// $validatedData['email_verified_at'] = now();
|
||||||
|
|
||||||
if ($ktpBase64 && $wajahBase64) {
|
if ($ktpBase64 && $wajahBase64) {
|
||||||
// Konversi string Base64 ke file gambar
|
// Konversi string Base64 ke file gambar
|
||||||
$ktpFile = base64_decode(preg_replace('#^data:image/\w+;base64,#i', '', $ktpBase64));
|
$ktpFile = base64_decode(preg_replace('#^data:image/\w+;base64,#i', '', $ktpBase64));
|
||||||
$wajahFile = base64_decode(preg_replace('#^data:image/\w+;base64,#i', '', $wajahBase64));
|
$wajahFile = base64_decode(preg_replace('#^data:image/\w+;base64,#i', '', $wajahBase64));
|
||||||
|
|
||||||
$foto_ktp = 'Foto-KTP-' . $nama_depan . '-' . $nama_belakang . '.jpg';
|
$foto_ktp = 'Foto-KTP-' . $email . '.jpg';
|
||||||
$foto_wajah = 'Foto-Wajah-' . $nama_depan . '-' . $nama_belakang . '.jpg';
|
$foto_wajah = 'Foto-Wajah-' . $email . '.jpg';
|
||||||
|
|
||||||
file_put_contents(public_path('storage/foto-ktp/' . $foto_ktp), $ktpFile);
|
file_put_contents(public_path('storage/foto-ktp/' . $foto_ktp), $ktpFile);
|
||||||
file_put_contents(public_path('storage/foto-wajah/' . $foto_wajah), $wajahFile);
|
file_put_contents(public_path('storage/foto-wajah/' . $foto_wajah), $wajahFile);
|
||||||
}
|
}
|
||||||
|
|
||||||
//OCR
|
|
||||||
try {
|
try {
|
||||||
// $fotoKTP = public_path('storage/foto-ktp/' . $foto_ktp);
|
// OCR
|
||||||
|
$client = new Client();
|
||||||
|
$response = $client->request('POST', 'http://localhost:8888/process-image', [
|
||||||
|
'multipart' => [
|
||||||
|
[
|
||||||
|
'name' => 'image',
|
||||||
|
'contents' => fopen(public_path('storage/foto-ktp/'.$foto_ktp), 'r'),
|
||||||
|
'filename' => $foto_ktp,
|
||||||
|
],
|
||||||
|
],
|
||||||
|
]);
|
||||||
|
|
||||||
// $image = Image::make($fotoKTP);
|
$result = $response->getBody()->getContents();
|
||||||
|
|
||||||
// $image->greyscale(); // Convert to grayscale
|
$lines = json_decode($result,true);
|
||||||
// $image->contrast(10); // Increase contrast, adjust the value as needed
|
|
||||||
|
|
||||||
// $preprocessedfotoKTP = public_path('storage/preprocessed/preprocessed_image.jpg');
|
$namaKTP = str_replace(' ','',strtolower($nama_depan.$nama_belakang));
|
||||||
// $image->save($preprocessedfotoKTP);
|
$nikKTP = $nik;
|
||||||
|
$persentaseNama = 0;
|
||||||
|
$persentaseNik = 0;
|
||||||
|
|
||||||
// $result = (new TesseractOCR($preprocessedfotoKTP))->run();
|
foreach($lines['result'] as $line){
|
||||||
|
$teks = str_replace(' ','',strtolower($line));
|
||||||
|
$persentaseNamaSementara = 0;
|
||||||
|
$persentaseNikSementara = 0;
|
||||||
|
similar_text($teks,$namaKTP,$persentaseNamaSementara);
|
||||||
|
similar_text($teks,$nikKTP,$persentaseNikSementara);
|
||||||
|
|
||||||
// (5) Normalize
|
if($persentaseNamaSementara > 0){
|
||||||
|
if($persentaseNamaSementara > $persentaseNama){
|
||||||
|
$persentaseNama = $persentaseNamaSementara;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
// $lines = explode("\n", $result);
|
if($persentaseNikSementara > 0){
|
||||||
// $namaOCR = '';
|
if($persentaseNikSementara > $persentaseNik){
|
||||||
// $nikOCR = '';
|
$persentaseNik = $persentaseNikSementara;
|
||||||
// $nikInputan = $nik;
|
}
|
||||||
// $namaInputan = $nama_depan . ' ' . $nama_belakang;
|
}
|
||||||
|
}
|
||||||
|
|
||||||
// foreach ($lines as $line) {
|
$persentase_kemiripan = ($persentaseNama + $persentaseNik)/2;
|
||||||
// // Mencari NIK
|
|
||||||
// if (strpos($line, $nikInputan) !== false) {
|
|
||||||
// $nikOCR = preg_replace('/[^0-9]/', '', $line);
|
|
||||||
// }
|
|
||||||
|
|
||||||
// // Mencari nama
|
$status = 'Progress';
|
||||||
// if (strpos($line, $namaInputan) !== false) {
|
|
||||||
// $namaOCR = trim(substr($line, strpos($line, ':') + 1));
|
|
||||||
// }
|
|
||||||
// }
|
|
||||||
|
|
||||||
//Selesai
|
if($status >= 50){
|
||||||
|
$status = 'Finished';
|
||||||
// $persentase_kemiripan = (similar_text($nikInputan, $nikOCR, $percent) + similar_text($namaOCR, $namaOCR, $percent)) / 2;
|
}else if($status <= 35){
|
||||||
// $status = 'Progress';
|
return response()->json([
|
||||||
|
'status' => false,
|
||||||
// if (similar_text($nikInputan, $nikOCR, $percent) >= 70 && similar_text($namaOCR, $namaOCR, $percent) >= 70) {
|
'message' => 'Sistem tidak dapat mendeteksi foto KTP. Kemungkinan foto tidak jelas atau buram, silahkan upload foto KTP yang jelas. Persentase kemiripan inputan : '.$persentase_kemiripan.'%'
|
||||||
// $status = 'Progress';
|
]);
|
||||||
// } else {
|
}
|
||||||
// $status = 'Progress';
|
|
||||||
// }
|
|
||||||
|
|
||||||
DB::beginTransaction();
|
DB::beginTransaction();
|
||||||
|
|
||||||
@ -261,6 +272,7 @@ class LoginController extends Controller
|
|||||||
'gender' => $gender,
|
'gender' => $gender,
|
||||||
'kode_kelurahan' => $kode_kelurahan,
|
'kode_kelurahan' => $kode_kelurahan,
|
||||||
'remember_token' => Str::random(10),
|
'remember_token' => Str::random(10),
|
||||||
|
'status' => $status
|
||||||
]);
|
]);
|
||||||
|
|
||||||
DB::commit();
|
DB::commit();
|
||||||
@ -273,15 +285,22 @@ class LoginController extends Controller
|
|||||||
$pusher = new Pusher('3e5bdc20dddd7fbc655e', 'f2274c37c616d29ff590', '1659859', $options);
|
$pusher = new Pusher('3e5bdc20dddd7fbc655e', 'f2274c37c616d29ff590', '1659859', $options);
|
||||||
|
|
||||||
$payload = [
|
$payload = [
|
||||||
'service' => 'User'
|
'service' => 'User',
|
||||||
];
|
];
|
||||||
|
|
||||||
$pusher->trigger('chanel-update-notifikasi-untuk-admin', 'event-update-notifikasi-untuk-admin', $payload);
|
$pusher->trigger('chanel-update-notifikasi-untuk-admin', 'event-update-notifikasi-untuk-admin', $payload);
|
||||||
|
|
||||||
|
if($status == 'Finished'){
|
||||||
|
return response()->json([
|
||||||
|
'status' => true,
|
||||||
|
'message' => 'Akun anda sudah terdaftar dan dapat digunakan',
|
||||||
|
]);
|
||||||
|
}else{
|
||||||
return response()->json([
|
return response()->json([
|
||||||
'status' => true,
|
'status' => true,
|
||||||
'message' => 'Akun anda sudah terdaftar dan butuh verifikasi hingga maksimal 1 hari kerja',
|
'message' => 'Akun anda sudah terdaftar dan butuh verifikasi hingga maksimal 1 hari kerja',
|
||||||
]);
|
]);
|
||||||
|
}
|
||||||
} catch (\Exception $e) {
|
} catch (\Exception $e) {
|
||||||
DB::rollBack();
|
DB::rollBack();
|
||||||
|
|
||||||
@ -369,73 +388,35 @@ class LoginController extends Controller
|
|||||||
|
|
||||||
public function getOcr()
|
public function getOcr()
|
||||||
{
|
{
|
||||||
//OCR
|
$client = new Client();
|
||||||
// dd(phpinfo());
|
$response = $client->request('POST', 'http://localhost:8888/process-image', [
|
||||||
try {
|
'multipart' => [
|
||||||
$fotoKTP = public_path('storage/foto-ktp/ktp.jpg');
|
[
|
||||||
|
'name' => 'image',
|
||||||
|
'contents' => fopen(public_path('storage/foto-ktp/foto_ktp.jpg'), 'r'),
|
||||||
|
'filename' => 'foto_ktp.jpg',
|
||||||
|
],
|
||||||
|
],
|
||||||
|
]);
|
||||||
|
|
||||||
$image = Image::make($fotoKTP);
|
dd($response->getBody()->getContents());
|
||||||
|
|
||||||
$image->greyscale(); // Convert to grayscale
|
|
||||||
$image->contrast(10); // Increase contrast, adjust the value as needed
|
|
||||||
|
|
||||||
$preprocessedfotoKTP = public_path('storage/preprocessed/preprocessed_image.jpg');
|
|
||||||
$image->save($preprocessedfotoKTP);
|
|
||||||
|
|
||||||
$result = (new TesseractOCR($preprocessedfotoKTP))->run();
|
|
||||||
|
|
||||||
// (5) Normalize
|
|
||||||
|
|
||||||
$lines = explode("\n", $result);
|
|
||||||
$nikOCR = '';
|
|
||||||
$namaOCR = '';
|
|
||||||
$nikInputan = '3471140209790001';
|
|
||||||
$namaInputan = 'RIYANTO. SE';
|
|
||||||
|
|
||||||
foreach ($lines as $line) {
|
|
||||||
// Mencari NIK
|
|
||||||
if (strpos($line, $nikInputan) !== false) {
|
|
||||||
$nikOCR = preg_replace('/[^0-9]/', '', $line);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// Mencari nama
|
public function email()
|
||||||
if (strpos($line, $namaInputan) !== false) {
|
{
|
||||||
$namaOCR = trim(substr($line, strpos($line, ':') + 1));
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
//Selesai
|
|
||||||
|
|
||||||
$persentase_kemiripan = (similar_text($nikInputan, $nikOCR, $percent) + similar_text($namaOCR, $namaOCR, $percent)) / 2;
|
|
||||||
// $status = 'Progress';
|
|
||||||
|
|
||||||
dd([$persentase_kemiripan, $lines]);
|
|
||||||
|
|
||||||
// if (similar_text($nikInputan, $nikOCR, $percent) >= 70 && similar_text($namaOCR, $namaOCR, $percent) >= 70) {
|
|
||||||
// $status = 'Progress';
|
|
||||||
// } else {
|
|
||||||
// $status = 'Progress';
|
|
||||||
// }
|
|
||||||
} catch (\Exception $e) {
|
|
||||||
// $status = 'Progress';
|
|
||||||
dd($e);
|
|
||||||
}
|
|
||||||
//OCR
|
|
||||||
}
|
|
||||||
|
|
||||||
public function email(){
|
|
||||||
$verificationEmail = [
|
$verificationEmail = [
|
||||||
'email' => 'Halo',
|
'email' => 'Halo',
|
||||||
'code' => 'kode'
|
'code' => 'kode',
|
||||||
];
|
];
|
||||||
return view('email.verification-email', compact('verificationEmail'));
|
return view('email.verification-email', compact('verificationEmail'));
|
||||||
}
|
}
|
||||||
|
|
||||||
public function invoice(){
|
public function invoice()
|
||||||
|
{
|
||||||
// return view('invoice.export-invoice');
|
// return view('invoice.export-invoice');
|
||||||
|
|
||||||
// $transaction = Transaction::findOrFail('80d9b19b-ba17-4aea-8cad-c3b4661d33bc');
|
// $transaction = Transaction::findOrFail('80d9b19b-ba17-4aea-8cad-c3b4661d33bc');
|
||||||
$pdf = Pdf::loadView('invoice.export-invoice')->setPaper('A4', 'portrait');
|
$pdf = Pdf::loadView('invoice.export-invoice')->setPaper('A4', 'portrait');
|
||||||
return $pdf->download("invoice-".uniqid().".pdf");
|
return $pdf->download('invoice-' . uniqid() . '.pdf');
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -27,7 +27,7 @@ return new class extends Migration
|
|||||||
$table->string('foto_ktp')->nullable();
|
$table->string('foto_ktp')->nullable();
|
||||||
$table->string('foto_wajah')->nullable();
|
$table->string('foto_wajah')->nullable();
|
||||||
$table->string('foto_profile')->nullable();
|
$table->string('foto_profile')->nullable();
|
||||||
$table->integer('persentase_kemiripan')->nullable();
|
$table->float('persentase_kemiripan')->nullable();
|
||||||
$table->enum('status',['Finished','Progress','Rejected'])->default('Progress');
|
$table->enum('status',['Finished','Progress','Rejected'])->default('Progress');
|
||||||
$table->string('gender',15);
|
$table->string('gender',15);
|
||||||
$table->char('kode_kelurahan',10);
|
$table->char('kode_kelurahan',10);
|
||||||
|
@ -136,7 +136,7 @@
|
|||||||
<span class="fw-bold text-start">Persentase Kemiripan</span>
|
<span class="fw-bold text-start">Persentase Kemiripan</span>
|
||||||
<span class="text-muted ">{{ $user->persentase_kemiripan }}</span>
|
<span class="text-muted ">{{ $user->persentase_kemiripan }}</span>
|
||||||
</div>
|
</div>
|
||||||
@if ($user->status == 'Progress')
|
{{-- @if ($user->status == 'Progress') --}}
|
||||||
<div class="d-flex justify-content-between align-items-center">
|
<div class="d-flex justify-content-between align-items-center">
|
||||||
<div class="card-title pb-2 m-0">
|
<div class="card-title pb-2 m-0">
|
||||||
<h4>Setujui pembuatan akun ini?</h4>
|
<h4>Setujui pembuatan akun ini?</h4>
|
||||||
@ -144,9 +144,8 @@
|
|||||||
</div>
|
</div>
|
||||||
<a class="btn btn-primary text-white" id="approveUser"
|
<a class="btn btn-primary text-white" id="approveUser"
|
||||||
data-id="{{ $user->id }}">Setujui</a>
|
data-id="{{ $user->id }}">Setujui</a>
|
||||||
<a class="btn btn-danger text-white" id="denyUser"
|
<a class="btn btn-danger text-white" id="denyUser" data-id="{{ $user->id }}">Tolak</a>
|
||||||
data-id="{{ $user->id }}">Tolak</a>
|
{{-- @endif --}}
|
||||||
@endif
|
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
@ -629,13 +629,13 @@
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (verificationCode == kode && waktuSekarangDetik > 0) {
|
// if (verificationCode == kode && waktuSekarangDetik > 0) {
|
||||||
verificationStatus = true;
|
// verificationStatus = true;
|
||||||
}
|
// }
|
||||||
|
|
||||||
let formData = new FormData(this);
|
let formData = new FormData(this);
|
||||||
formData.append('kode_verifikasi', verificationCode);
|
// formData.append('kode_verifikasi', verificationCode);
|
||||||
formData.append('verification_status', verificationStatus ? 'true' : 'false');
|
// formData.append('verification_status', verificationStatus ? 'true' : 'false');
|
||||||
|
|
||||||
Swal.fire({
|
Swal.fire({
|
||||||
html: '<div class="mt-3"><lord-icon src="https://cdn.lordicon.com/etwtznjn.json" trigger="loop" colors="primary:#0ab39c,secondary:#405189" style="width:120px;height:120px"></lord-icon><div class="mt-4 pt-2 fs-15"><h4>Form Anda sedang diproses!</h4><p class="text-muted mx-4 mb-0">Mohon tunggu...</p></div></div>',
|
html: '<div class="mt-3"><lord-icon src="https://cdn.lordicon.com/etwtznjn.json" trigger="loop" colors="primary:#0ab39c,secondary:#405189" style="width:120px;height:120px"></lord-icon><div class="mt-4 pt-2 fs-15"><h4>Form Anda sedang diproses!</h4><p class="text-muted mx-4 mb-0">Mohon tunggu...</p></div></div>',
|
||||||
@ -666,9 +666,9 @@
|
|||||||
confirmButtonText: 'OK',
|
confirmButtonText: 'OK',
|
||||||
}).then(function() {
|
}).then(function() {
|
||||||
if (response.status) {
|
if (response.status) {
|
||||||
console.log(response);
|
|
||||||
location.reload();
|
location.reload();
|
||||||
}
|
}
|
||||||
|
console.log(response);
|
||||||
});
|
});
|
||||||
},
|
},
|
||||||
error: function(error) {
|
error: function(error) {
|
||||||
|
Loading…
Reference in New Issue
Block a user