Commit 99945b14 authored by IT19959856_UdeshikaWGA's avatar IT19959856_UdeshikaWGA

Merge branch 'IT19959856-Member1-Feeding_decision_making' into 'master'

It19959856 member1 feeding decision making

See merge request !3
parents 7c697d29 f8ecd53d
This diff is collapsed.
<!DOCTYPE html>
<html lang="en">
<head>
<style>
body{
display: flex;
align-items: center;
justify-content: center;
min-height: 100vh;
background: #6990F2;
}
.wrapper{
width: 430px;
background: #fff;
border-radius: 5px;
padding: 30px;
box-shadow: 7px 7px 12px rgba(0,0,0,0.05);
}
</style>
<title>Water Quality Demo</title>
</head>
<body>
<div class="wrapper">
<header>Water Quality Demo</header>
<p>Water Specifications: </p>
<p>{{ variable }}</p>
</div>
</body>
</html>
\ No newline at end of file
Data set link: https://docs.google.com/spreadsheets/d/1RU-wECrp6m4QdEn9xeznG4zQH66YqsT6EF_kfJAmzDM/edit?usp=sharing
\ No newline at end of file
from fastapi import FastAPI, Request
from fastapi.middleware.cors import CORSMiddleware
from fastapi.responses import HTMLResponse
from fastapi.staticfiles import StaticFiles
from fastapi.templating import Jinja2Templates
from uvicorn import run
import cv2
import numpy as np
from PIL import Image
import shutil
import shutil
import os
app = FastAPI()
origins = ["*"]
methods = ["*"]
headers = ["*"]
app.add_middleware(
CORSMiddleware,
allow_origins = origins,
allow_credentials = True,
allow_methods = methods,
allow_headers = headers
)
origin = r"C:\xampp\htdocs\wcolor\php\files\fishwatercolor.jpg"
target = r"D:\Lectures\4thYear2ndSem\RP\Water\watercolor\fishwatercolor.jpg"
app.mount("/static", StaticFiles(directory="static"), name="static")
templates = Jinja2Templates(directory="templates")
blue_range = np.array([[100, 50, 50], [130, 255, 255]])
green_range = np.array([[40, 50, 50], [80, 255, 255]])
red_range1 = np.array([[0, 50, 50], [10, 255, 255]])
red_range2 = np.array([[170, 50, 50], [180, 255, 255]])
def show_water_color():
shutil.copy(origin,target)
# Get the image from the frontend
# image_file = request.files['image']
# img = Image.open(image_file)
img = Image.open("fishwatercolor.jpg")
# Convert the image to the HSV color space
hsv_img = cv2.cvtColor(np.array(img), cv2.COLOR_RGB2HSV)
# Calculate the percentage of blue pixels in the image
blue_mask = cv2.inRange(hsv_img, blue_range[0], blue_range[1])
blue_pixels = np.sum(blue_mask == 255)
total_pixels = blue_mask.shape[0] * blue_mask.shape[1]
blue_percent = blue_pixels / total_pixels * 100
# Calculate the percentage of green pixels in the image
green_mask = cv2.inRange(hsv_img, green_range[0], green_range[1])
green_pixels = np.sum(green_mask == 255)
green_percent = green_pixels / total_pixels * 100
# Calculate the percentage of red pixels in the image
red_mask1 = cv2.inRange(hsv_img, red_range1[0], red_range1[1])
red_mask2 = cv2.inRange(hsv_img, red_range2[0], red_range2[1])
red_mask = cv2.addWeighted(red_mask1, 1.0, red_mask2, 1.0, 0.0)
red_pixels = np.sum(red_mask == 255)
red_percent = red_pixels / total_pixels * 100
# Determine the dominant color of the image
colors, counts = np.unique(hsv_img.reshape(-1, hsv_img.shape[-1]), axis=0, return_counts=True)
max_count_index = np.argmax(counts)
dominant_color = colors[max_count_index]
# Process the water color
if green_percent > 10:
water_color = 'green'
elif green_percent < 1:
water_color = 'brown'
else:
water_color = 'normal'
# Return the results as JSON
# results = {
# 'image_name': image_file.filename,
# 'blue_pixels_percent': blue_percent,
# 'green_pixels_percent': green_percent,
# 'red_pixels_percent': red_percent,
# 'dominant_color': dominant_color.tolist(),
# 'water_color': water_color
# }
results = {
'water_color': water_color
}
return results
@app.get("/getResult")
async def send_image_get_prediction(request: Request):
rt = show_water_color()
return templates.TemplateResponse("Saveimage.html", {"request": request, "variable": rt})
if __name__ == "__main__":
port = int(os.environ.get('PORT', 5000))
run(app, host="0.0.0.0", port=port)
\ No newline at end of file
<?php
$file_name = $_FILES['file']['name'];
$tmp_name = $_FILES['file']['tmp_name'];
$file_up_name = time().$file_name;
move_uploaded_file($tmp_name, "files/".$file_up_name);
?>
\ No newline at end of file
const form = document.querySelector("form"),
fileInput = document.querySelector(".file-input"),
progressArea = document.querySelector(".progress-area"),
uploadedArea = document.querySelector(".uploaded-area");
form.addEventListener("click", () =>{
fileInput.click();
});
fileInput.onchange = ({target})=>{
let file = target.files[0];
if(file){
let fileName = file.name;
if(fileName.length >= 12){
let splitName = fileName.split('.');
fileName = splitName[0].substring(0, 13) + "... ." + splitName[1];
}
uploadFile(fileName);
}
}
function uploadFile(name){
let xhr = new XMLHttpRequest();
xhr.open("POST", "php/upload.php");
xhr.upload.addEventListener("progress", ({loaded, total}) =>{
let fileLoaded = Math.floor((loaded / total) * 100);
let fileTotal = Math.floor(total / 1000);
let fileSize;
(fileTotal < 1024) ? fileSize = fileTotal + " KB" : fileSize = (loaded / (1024*1024)).toFixed(2) + " MB";
let progressHTML = `<li class="row">
<i class="fas fa-file-alt"></i>
<div class="content">
<div class="details">
<span class="name">${name} • Uploading</span>
<span class="percent">${fileLoaded}%</span>
</div>
<div class="progress-bar">
<div class="progress" style="width: ${fileLoaded}%"></div>
</div>
</div>
</li>`;
uploadedArea.classList.add("onprogress");
progressArea.innerHTML = progressHTML;
if(loaded == total){
progressArea.innerHTML = "";
let uploadedHTML = `<li class="row">
<div class="content upload">
<i class="fas fa-file-alt"></i>
<div class="details">
<span class="name">${name} • Uploaded</span>
<span class="size">${fileSize}</span>
</div>
</div>
<i class="fas fa-check"></i>
</li>`;
uploadedArea.classList.remove("onprogress");
uploadedArea.insertAdjacentHTML("afterbegin", uploadedHTML);
}
});
let data = new FormData(form);
xhr.send(data);
}
\ No newline at end of file
/* Import Google font - Poppins */
@import url('https://fonts.googleapis.com/css2?family=Poppins:wght@400;500;600&display=swap');
*{
margin: 0;
padding: 0;
box-sizing: border-box;
font-family: "Poppins", sans-serif;
}
body{
display: flex;
align-items: center;
justify-content: center;
min-height: 100vh;
background: #6990F2;
}
::selection{
color: #fff;
background: #6990F2;
}
.wrapper{
width: 430px;
background: #fff;
border-radius: 5px;
padding: 30px;
box-shadow: 7px 7px 12px rgba(0,0,0,0.05);
}
.wrapper header{
color: #6990F2;
font-size: 27px;
font-weight: 600;
text-align: center;
}
.wrapper form{
height: 167px;
display: flex;
cursor: pointer;
margin: 30px 0;
align-items: center;
justify-content: center;
flex-direction: column;
border-radius: 5px;
border: 2px dashed #6990F2;
}
form :where(i, p){
color: #6990F2;
}
form i{
font-size: 50px;
}
form p{
margin-top: 15px;
font-size: 16px;
}
section .row{
margin-bottom: 10px;
background: #E9F0FF;
list-style: none;
padding: 15px 20px;
border-radius: 5px;
display: flex;
align-items: center;
justify-content: space-between;
}
section .row i{
color: #6990F2;
font-size: 30px;
}
section .details span{
font-size: 14px;
}
.progress-area .row .content{
width: 100%;
margin-left: 15px;
}
.progress-area .details{
display: flex;
align-items: center;
margin-bottom: 7px;
justify-content: space-between;
}
.progress-area .content .progress-bar{
height: 6px;
width: 100%;
margin-bottom: 4px;
background: #fff;
border-radius: 30px;
}
.content .progress-bar .progress{
height: 100%;
width: 0%;
background: #6990F2;
border-radius: inherit;
}
.uploaded-area{
max-height: 232px;
overflow-y: scroll;
}
.uploaded-area.onprogress{
max-height: 150px;
}
.uploaded-area::-webkit-scrollbar{
width: 0px;
}
.uploaded-area .row .content{
display: flex;
align-items: center;
}
.uploaded-area .row .details{
display: flex;
margin-left: 15px;
flex-direction: column;
}
.uploaded-area .row .details .size{
color: #404040;
font-size: 11px;
}
.uploaded-area i.fa-check{
font-size: 16px;
}
\ No newline at end of file
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment