Feat : BackEnd Robo Soil

This commit is contained in:
EdyAtthoillah123 2023-09-11 17:00:03 +07:00
commit 8b1779eec0
32 changed files with 664 additions and 0 deletions

View File

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

16
RoboSoil/RoboSoil/asgi.py Normal file
View File

@ -0,0 +1,16 @@
"""
ASGI config for RoboSoil project.
It exposes the ASGI callable as a module-level variable named ``application``.
For more information on this file, see
https://docs.djangoproject.com/en/4.2/howto/deployment/asgi/
"""
import os
from django.core.asgi import get_asgi_application
os.environ.setdefault('DJANGO_SETTINGS_MODULE', 'RoboSoil.settings')
application = get_asgi_application()

View File

@ -0,0 +1,126 @@
"""
Django settings for RoboSoil project.
Generated by 'django-admin startproject' using Django 4.2.4.
For more information on this file, see
https://docs.djangoproject.com/en/4.2/topics/settings/
For the full list of settings and their values, see
https://docs.djangoproject.com/en/4.2/ref/settings/
"""
from pathlib import Path
import os
# Build paths inside the project like this: BASE_DIR / 'subdir'.
BASE_DIR = Path(__file__).resolve().parent.parent
# Quick-start development settings - unsuitable for production
# See https://docs.djangoproject.com/en/4.2/howto/deployment/checklist/
# SECURITY WARNING: keep the secret key used in production secret!
SECRET_KEY = 'django-insecure-a-#2wlv!^7%=o3#05y)kylny_obz45(ni9k9*hwho!)ub26$#9'
# SECURITY WARNING: don't run with debug turned on in production!
DEBUG = True
ALLOWED_HOSTS = []
# Application definition
INSTALLED_APPS = [
'django.contrib.admin',
'django.contrib.auth',
'django.contrib.contenttypes',
'django.contrib.sessions',
'django.contrib.messages',
'django.contrib.staticfiles',
'Robo_Soil'
]
MIDDLEWARE = [
'django.middleware.security.SecurityMiddleware',
'django.contrib.sessions.middleware.SessionMiddleware',
'django.middleware.common.CommonMiddleware',
'django.middleware.csrf.CsrfViewMiddleware',
'django.contrib.auth.middleware.AuthenticationMiddleware',
'django.contrib.messages.middleware.MessageMiddleware',
'django.middleware.clickjacking.XFrameOptionsMiddleware',
]
ROOT_URLCONF = 'RoboSoil.urls'
TEMPLATES = [
{
'BACKEND': 'django.template.backends.django.DjangoTemplates',
'DIRS': [],
'APP_DIRS': True,
'OPTIONS': {
'context_processors': [
'django.template.context_processors.debug',
'django.template.context_processors.request',
'django.contrib.auth.context_processors.auth',
'django.contrib.messages.context_processors.messages',
],
},
},
]
WSGI_APPLICATION = 'RoboSoil.wsgi.application'
# Database
# https://docs.djangoproject.com/en/4.2/ref/settings/#databases
DATABASES = {
'default': {
'ENGINE': 'django.db.backends.sqlite3',
'NAME': BASE_DIR / 'db.sqlite3',
}
}
# Password validation
# https://docs.djangoproject.com/en/4.2/ref/settings/#auth-password-validators
AUTH_PASSWORD_VALIDATORS = [
{
'NAME': 'django.contrib.auth.password_validation.UserAttributeSimilarityValidator',
},
{
'NAME': 'django.contrib.auth.password_validation.MinimumLengthValidator',
},
{
'NAME': 'django.contrib.auth.password_validation.CommonPasswordValidator',
},
{
'NAME': 'django.contrib.auth.password_validation.NumericPasswordValidator',
},
]
# Internationalization
# https://docs.djangoproject.com/en/4.2/topics/i18n/
LANGUAGE_CODE = 'en-us'
TIME_ZONE = 'UTC'
USE_I18N = True
USE_TZ = True
# Static files (CSS, JavaScript, Images)
# https://docs.djangoproject.com/en/4.2/howto/static-files/
STATIC_URL = 'static/'
MEDIA_URL = '/media/'
MEDIA_ROOT = os.path.join(BASE_DIR, 'media')
# Default primary key field type
# https://docs.djangoproject.com/en/4.2/ref/settings/#default-auto-field
DEFAULT_AUTO_FIELD = 'django.db.models.BigAutoField'

23
RoboSoil/RoboSoil/urls.py Normal file
View File

@ -0,0 +1,23 @@
"""
URL configuration for RoboSoil project.
The `urlpatterns` list routes URLs to views. For more information please see:
https://docs.djangoproject.com/en/4.2/topics/http/urls/
Examples:
Function views
1. Add an import: from my_app import views
2. Add a URL to urlpatterns: path('', views.home, name='home')
Class-based views
1. Add an import: from other_app.views import Home
2. Add a URL to urlpatterns: path('', Home.as_view(), name='home')
Including another URLconf
1. Import the include() function: from django.urls import include, path
2. Add a URL to urlpatterns: path('blog/', include('blog.urls'))
"""
from django.contrib import admin
from django.urls import path,include
urlpatterns = [
path('admin/', admin.site.urls),
path('', include("Robo_Soil.urls")),
]

16
RoboSoil/RoboSoil/wsgi.py Normal file
View File

@ -0,0 +1,16 @@
"""
WSGI config for RoboSoil project.
It exposes the WSGI callable as a module-level variable named ``application``.
For more information on this file, see
https://docs.djangoproject.com/en/4.2/howto/deployment/wsgi/
"""
import os
from django.core.wsgi import get_wsgi_application
os.environ.setdefault('DJANGO_SETTINGS_MODULE', 'RoboSoil.settings')
application = get_wsgi_application()

View File

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

View File

@ -0,0 +1,3 @@
from django.contrib import admin
# Register your models here.

View File

@ -0,0 +1,6 @@
from django.apps import AppConfig
class RoboSoilConfig(AppConfig):
default_auto_field = 'django.db.models.BigAutoField'
name = 'Robo_Soil'

View File

@ -0,0 +1,3 @@
from django.db import models
# Create your models here.

View File

@ -0,0 +1 @@
Hello World

View File

@ -0,0 +1,3 @@
from django.test import TestCase
# Create your tests here.

View File

@ -0,0 +1,11 @@
from . import views
from django.urls import path
from django.conf import settings
from django.conf.urls.static import static
urlpatterns = [
# path("", views.home, name="home"),
path("", views.lbp, name="grayscale"),
]+ static(settings.MEDIA_URL, document_root=settings.MEDIA_ROOT)

178
RoboSoil/Robo_Soil/views.py Normal file
View File

@ -0,0 +1,178 @@
from django.shortcuts import render
import cv2
import numpy as np
from matplotlib import pyplot as plt
def home(request):
context={}
return render(request, "Structures/home.html", context)
def compute_lbp(image):
lbp_image = np.zeros_like(image)
for i in range(1, image.shape[0] - 1):
for j in range(1, image.shape[1] - 1):
center = image[i, j]
code = 0
code |= (image[i - 1, j - 1] > center) << 7
code |= (image[i - 1, j] > center) << 6
code |= (image[i - 1, j + 1] > center) << 5
code |= (image[i, j + 1] > center) << 4
code |= (image[i + 1, j + 1] > center) << 3
code |= (image[i + 1, j] > center) << 2
code |= (image[i + 1, j - 1] > center) << 1
code |= (image[i, j - 1] > center) << 0
lbp_image[i, j] = code
return lbp_image
def lbp(request):
# Crop Image
image = cv2.imread('media/image1.png')
width, height = 640, 480
original_height, original_width = image.shape[:2]
center_x, center_y = original_width // 2, original_height // 2
top_left_x = center_x - (width // 2)
top_left_y = center_y - (height // 2)
bottom_right_x = center_x + (width // 2)
bottom_right_y = center_y + (height // 2)
cropped_image = image[top_left_y:bottom_right_y, top_left_x:bottom_right_x]
resized_image = cv2.resize(cropped_image, (width, height))
cv2.imwrite('media/hasil_pemangkasan.jpg', resized_image)
# cv2.imshow('Hasil Pemangkasan', resized_image)
# GrayScale
# img = cv2.imread('media/hasil_pemangkasan.jpg')
# gray = cv2.cvtColor(img, cv2.COLOR_BGR2GRAY)
# cv2.imwrite('media/grayscale.jpg',gray)
img = cv2.imread('media/hasil_pemangkasan.jpg', cv2.IMREAD_GRAYSCALE)
equalized_image = cv2.equalizeHist(img)
kernel = np.array([ [1, 2, 1],
[2, 4, 2],
[1, 2, 1] ]) / 16.0
filtered_image = cv2.filter2D(equalized_image, -1, kernel)
lbp_result = compute_lbp(filtered_image)
lbp_histogram, _ = np.histogram(lbp_result, bins=np.arange(257), range=(0, 256))
min_val = min(lbp_histogram)
max_val = max(lbp_histogram)
normalized_histogram = [(x - min_val) / (max_val - min_val) for x in lbp_histogram]
print("Histogram LBP (Setelah Normalisasi):")
print(normalized_histogram)
# Atau menyimpannya ke file
np.savetxt('media/histogram_lbp_normalized.txt', normalized_histogram)
print("Histogram LBP:")
print(lbp_histogram)
print(normalized_histogram)
mode_value = max(lbp_histogram)
print("Nilai tertinggi dalam histogram LBP adalah:", mode_value)
cv2.imwrite('media/hasil_lbp.jpg', lbp_result)
cv2.imshow('Hasil LBP', lbp_result)
cv2.waitKey(0)
cv2.destroyAllWindows()
# cv2.imwrite('hasil_equalisasi_dan_tapis.jpg', filtered_image)
# cv2.imshow('Hasil Equalisasi dan Tapis', filtered_image)
# cv2.waitKey(0)
# cv2.destroyAllWindows()
# cv2.imshow('GrayScale', gray)
# cv2.waitKey(0)
# cv2.destroyAllWindows()
# def get_pixel(img, center, x, y):
# new_value = 0
# try:
# # If local neighbourhood pixel
# # value is greater than or equal
# # to center pixel values then
# # set it to 1
# if img[x][y] >= center:
# new_value = 1
# except:
# # Exception is required when
# # neighbourhood value of a center
# # pixel value is null i.e. values
# # present at boundaries.
# pass
# return new_value
# Function for calculating LBP
# def lbp_calculated_pixel(img, x, y):
# center = img[x][y]
# val_ar = []
# # top_left
# val_ar.append(get_pixel(img, center, x-1, y-1))
# # top
# val_ar.append(get_pixel(img, center, x-1, y))
# # top_right
# val_ar.append(get_pixel(img, center, x-1, y + 1))
# # right
# val_ar.append(get_pixel(img, center, x, y + 1))
# # bottom_right
# val_ar.append(get_pixel(img, center, x + 1, y + 1))
# # bottom
# val_ar.append(get_pixel(img, center, x + 1, y))
# # bottom_left
# val_ar.append(get_pixel(img, center, x + 1, y-1))
# # left
# val_ar.append(get_pixel(img, center, x, y-1))
# # Now, we need to convert binary
# # values to decimal
# power_val = [1, 2, 4, 8, 16, 32, 64, 128]
# val = 0
# for i in range(len(val_ar)):
# val += val_ar[i] * power_val[i]
# return val
# def lbp(request):
# path = 'media/foto-aerial-kuk.jpeg'
# img_bgr = cv2.imread(path, 1)
# height, width, _ = img_bgr.shape
# # We need to convert RGB image
# # into gray one because gray
# # image has one channel only.
# img_gray = cv2.cvtColor(img_bgr,
# cv2.COLOR_BGR2GRAY)
# # Create a numpy array as
# # the same height and width
# # of RGB image
# img_lbp = np.zeros((height, width),
# np.uint8)
# for i in range(0, height):
# for j in range(0, width):
# img_lbp[i, j] = lbp_calculated_pixel(img_gray, i, j)
# plt.imshow(img_bgr)
# plt.show()
# plt.imshow(img_lbp, cmap ="gray")
# plt.show()
# print("LBP Program is finished")

BIN
RoboSoil/db.sqlite3 Normal file

Binary file not shown.

22
RoboSoil/manage.py Normal file
View File

@ -0,0 +1,22 @@
#!/usr/bin/env python
"""Django's command-line utility for administrative tasks."""
import os
import sys
def main():
"""Run administrative tasks."""
os.environ.setdefault('DJANGO_SETTINGS_MODULE', 'RoboSoil.settings')
try:
from django.core.management import execute_from_command_line
except ImportError as exc:
raise ImportError(
"Couldn't import Django. Are you sure it's installed and "
"available on your PYTHONPATH environment variable? Did you "
"forget to activate a virtual environment?"
) from exc
execute_from_command_line(sys.argv)
if __name__ == '__main__':
main()

Binary file not shown.

After

Width:  |  Height:  |  Size: 258 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 69 KiB

View File

@ -0,0 +1,256 @@
4.451170298627925570e-01
2.223567393058918651e-02
2.623083131557707795e-02
6.037126715092816509e-02
6.481033091202582919e-02
3.631961259079902887e-04
1.012913640032284124e-01
3.299435028248587365e-01
2.780468119451170311e-02
5.246166263115415763e-04
7.667473769168683994e-04
5.246166263115415763e-04
9.487489911218724425e-02
7.667473769168683994e-04
3.107344632768361814e-01
5.147699757869249604e-01
2.005649717514124131e-02
6.860371267150928640e-04
1.614205004035512605e-04
6.860371267150928640e-04
6.053268765133172202e-04
0.000000000000000000e+00
5.246166263115415763e-04
2.824858757062146991e-04
6.339790153349475488e-02
7.667473769168683994e-04
8.474576271186440432e-04
1.251008878127522154e-03
3.382970137207425565e-01
4.035512510088781106e-04
5.345439870863599729e-01
1.256255044390637565e-01
3.430185633575463799e-02
4.439063761097659325e-04
4.519774011299435186e-03
3.470540758676352033e-03
1.331719128329297798e-03
0.000000000000000000e+00
3.793381759483454609e-03
4.277643260694108038e-03
8.878127522195318651e-04
0.000000000000000000e+00
4.035512510088781513e-05
4.035512510088781513e-05
4.439063761097659325e-04
0.000000000000000000e+00
2.098466505246166305e-03
6.860371267150928640e-04
6.836158192090395491e-02
8.474576271186440432e-04
4.116222760290557184e-03
2.340597255851493020e-03
2.421307506053268881e-03
0.000000000000000000e+00
4.519774011299435186e-03
1.573849878934624729e-03
4.443099273607747923e-01
1.049233252623083153e-03
3.914447134786117749e-03
3.995157384987893176e-03
8.422114608555286708e-01
1.210653753026634386e-04
2.387812752219531931e-01
3.789346246973365750e-02
7.578692493946731501e-02
6.860371267150928640e-04
1.331719128329297798e-03
2.703793381759483309e-03
2.582728006456820168e-03
0.000000000000000000e+00
1.008878127522195222e-03
6.456820016142050421e-04
1.251008878127522154e-03
0.000000000000000000e+00
0.000000000000000000e+00
0.000000000000000000e+00
1.049233252623083153e-03
0.000000000000000000e+00
5.649717514124293983e-04
8.071025020177563026e-05
6.053268765133172202e-04
0.000000000000000000e+00
0.000000000000000000e+00
0.000000000000000000e+00
0.000000000000000000e+00
0.000000000000000000e+00
0.000000000000000000e+00
0.000000000000000000e+00
1.977401129943502731e-03
0.000000000000000000e+00
0.000000000000000000e+00
0.000000000000000000e+00
4.439063761097659325e-04
0.000000000000000000e+00
4.035512510088781513e-05
0.000000000000000000e+00
1.132364810330911964e-01
6.053268765133172202e-04
3.551251008878127460e-03
5.246166263115415763e-03
1.210653753026634440e-03
0.000000000000000000e+00
1.129943502824858797e-03
5.649717514124293983e-04
8.474576271186440432e-04
0.000000000000000000e+00
4.035512510088781513e-05
0.000000000000000000e+00
1.291364003228410084e-03
0.000000000000000000e+00
1.331719128329297798e-03
8.071025020177563026e-05
3.852703793381759279e-01
2.824858757062146991e-04
4.358353510895883465e-03
1.856335754640839374e-03
7.667473769168683994e-04
0.000000000000000000e+00
9.281678773204196870e-04
1.210653753026634386e-04
9.265940274414851130e-01
8.071025020177563026e-05
2.945924132364810457e-03
9.685230024213075089e-04
9.895076674737691980e-02
0.000000000000000000e+00
1.682808716707021729e-02
8.071025020177562213e-04
3.728813559322034094e-02
7.195318805488297442e-02
8.071025020177562213e-04
4.131154156577885317e-01
1.533494753833736799e-03
2.017756255044390445e-03
6.456820016142050421e-04
7.854721549636803912e-01
3.268765133171913032e-03
4.479418886198547473e-03
8.071025020177563026e-05
4.963680387409200902e-03
3.712671509281678748e-03
4.882970137207425475e-03
1.452784503631961155e-03
2.389426957223567405e-01
5.649717514124293983e-04
7.263922518159805775e-04
0.000000000000000000e+00
7.263922518159805775e-04
0.000000000000000000e+00
0.000000000000000000e+00
0.000000000000000000e+00
4.035512510088781513e-05
4.560129136400322900e-03
2.098466505246166305e-03
4.035512510088781513e-05
4.196933010492332611e-03
4.882970137207425475e-03
1.896690879741727304e-03
8.878127522195318651e-04
4.132364810330912269e-02
1.089588377723970866e-03
9.281678773204196870e-04
0.000000000000000000e+00
4.600484261501210613e-03
4.035512510088781513e-05
0.000000000000000000e+00
8.071025020177563026e-05
1.775625504439063730e-03
0.000000000000000000e+00
4.035512510088781513e-05
0.000000000000000000e+00
1.210653753026634386e-04
0.000000000000000000e+00
0.000000000000000000e+00
8.071025020177563026e-05
1.533494753833736799e-03
7.667473769168683994e-04
1.694915254237288086e-03
0.000000000000000000e+00
3.188054882970137172e-03
0.000000000000000000e+00
0.000000000000000000e+00
0.000000000000000000e+00
6.860371267150928640e-04
4.923325262308313188e-03
3.954802259887005463e-03
1.614205004035512605e-04
1.404358353510895899e-02
2.380952380952381167e-03
1.089588377723970866e-03
1.533494753833736799e-03
4.479418886198547473e-02
1.174737691686844193e-01
3.994753833736884308e-01
4.842615012106537544e-04
1.000000000000000000e+00
1.452784503631961155e-03
6.053268765133172202e-04
9.685230024213075089e-04
9.588377723970943622e-02
3.631961259079903321e-03
3.591606133979015174e-03
0.000000000000000000e+00
2.219531880548829880e-03
8.474576271186440432e-04
6.053268765133172202e-04
1.372074253430185728e-03
1.727199354317998301e-02
6.053268765133172202e-04
3.228410008071025210e-04
0.000000000000000000e+00
8.071025020177563026e-05
0.000000000000000000e+00
0.000000000000000000e+00
0.000000000000000000e+00
0.000000000000000000e+00
5.528652138821630625e-03
2.380952380952381167e-03
4.035512510088781513e-05
1.170298627925746510e-03
3.631961259079902887e-04
8.071025020177563026e-05
1.614205004035512605e-04
6.456820016142050421e-04
3.593220338983050821e-01
6.280468119451170228e-01
1.735270379338176017e-03
2.719935431799838654e-01
4.439063761097659325e-04
0.000000000000000000e+00
1.493139628732849085e-03
1.711057304277643215e-02
1.815980629539951660e-03
7.667473769168683994e-04
0.000000000000000000e+00
1.735270379338176017e-03
1.372074253430185728e-03
2.421307506053268772e-04
3.672316384180791034e-03
1.384180790960451955e-02
6.185230024213075328e-01
1.525020177562550483e-01
7.667473769168683994e-04
4.624697336561743588e-02
8.071025020177563026e-05
0.000000000000000000e+00
2.017756255044390553e-04
1.049233252623083153e-03
2.650121065375302676e-01
5.048426150121065187e-02
1.775625504439063730e-03
4.717514124293785416e-02
1.747376916868442417e-02
8.071025020177562213e-04
1.396287328490718356e-02
3.139628732849071568e-02

BIN
RoboSoil/media/image1.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 152 KiB

BIN
RoboSoil/media/lahan.jpeg Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 198 KiB