Skip to content

Commit

Permalink
Updated to MONO REPO
Browse files Browse the repository at this point in the history
  • Loading branch information
jaswanthreddy-007 committed Sep 24, 2023
1 parent 34d09a2 commit 284e916
Show file tree
Hide file tree
Showing 20 changed files with 234 additions and 3 deletions.
2 changes: 1 addition & 1 deletion ios/.gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ Flutter/flutter_assets/
Flutter/flutter_export_environment.sh
ServiceDefinitions.json
Runner/GeneratedPluginRegistrant.*

server/crackapp-23e59-firebase-adminsdk-o18mf-aafa26780f.json
# Exceptions to above rules.
!default.mode1v3
!default.mode2v3
Expand Down
4 changes: 2 additions & 2 deletions lib/pages/scan.dart
Original file line number Diff line number Diff line change
Expand Up @@ -66,8 +66,8 @@ class _scanState extends State<scan> {



// final String apiUrl = "https://a48e-203-192-251-182.ngrok.io/imageapi";
final String apiUrl = "http://10.0.2.2:3000/imageapi";
final String apiUrl = "https://5078-119-161-98-148.ngrok-free.app/imageapi";
// final String apiUrl = "http://10.0.2.2:3000/imageapi";
String? b64;

Future sendImage(File imageFile, BuildContext context) async {
Expand Down
Binary file added server/crack.jpg
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 server/dent.jpg
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 server/final.jpg
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 server/images.jpeg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
11 changes: 11 additions & 0 deletions server/requirements.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
firebase_admin==6.1.0
Flask==2.3.2
flask_ngrok==0.0.25
matplotlib==3.5.3
numpy==1.23.2
opencv_contrib_python==4.7.0.72
opencv_python==4.7.0.72
opencv_python_headless==4.6.0.66
Pillow==9.3.0
Pillow==10.0.0
roboflow==1.0.8
102 changes: 102 additions & 0 deletions server/server.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,102 @@
from flask import *
from PIL import Image
import io
import base64
import cv2 as cv
from roboflow import Roboflow
from flask_ngrok import run_with_ngrok
import matplotlib.pyplot as plt
from firebase_admin import credentials, initialize_app, storage
import datetime
import string

cred = credentials.Certificate(
"crackapp-23e59-firebase-adminsdk-o18mf-aafa26780f.json")
initialize_app(
cred, {'storageBucket': 'crackapp-23e59.appspot.com'})
app = Flask(__name__)
# run_with_ngrok(app)



@app.route('/')
def home():
return jsonify({'message': 'hi'})






@app.route('/imageapi', methods=['POST'])
def crack_finder():
image_str = request.json.get('image')
image_bytes = base64.b64decode(image_str)
image_file = io.BytesIO(image_bytes)

image = Image.open(image_file)
image = image.convert("RGB")
image.save("K:/MistralHack/crackapp/server/test.jpg")

rf = Roboflow(api_key="DzJXlBY4OY5a7ohy6WQ2")
#########additional app keys##############
# DzJXlBY4OY5a7ohy6WQ2
# ao0gkNxhFLHpuGLDxLya
# x9uX7YwqY57VddkIXY5L
# ########crack###############
project = rf.workspace().project("crack-shadyar-zhir")
model = project.version(1).model
model.predict("test.jpg").save("crack.jpg")

# ##########dent##############
# project = rf.workspace().project("dentsegmentation")
# model = project.version(2).model
# model.predict("test.jpg").save("dent.jpg")

project = rf.workspace().project("car_dent_scratch_detection-1")
model = project.version(9).model
model.predict("test.jpg").save("dent.jpg")

# project = rf.workspace().project("dent-7ltse")
# model = project.version(2).model
# model.predict("test.jpg").save("dent.jpg")


Pred = Image.open('K:/MistralHack/crackapp/server/crack.jpg')
pred2 = Image.open('K:/MistralHack/crackapp/server/dent.jpg')
t_res = image.resize((250,200))
pred_res = Pred.resize((250,200))
pred_res_2 = pred2.resize((250,200))
final = Image.new("RGB", (790, 200), "white")
final.paste(t_res,(0,0))
final.paste(pred_res,(270,0))
final.paste(pred_res_2, (540, 0))
final.save("K:/MistralHack/crackapp/server/final.jpg")

with open('K:/MistralHack/crackapp/server/final.jpg', 'rb') as f:
image_bytes = f.read()
image_b64 = base64.b64encode(image_bytes).decode('utf-8')
res = Response(image_b64, mimetype='text/plain')
@res.call_on_close
def handle_post_request_completion():
# Code to be executed after the POST request is completed
file_extension = 'jpg'
destination_filename = generate_destination_filename(file_extension)
fileName = "final.jpg"
bucket = storage.bucket()
blob = bucket.blob(destination_filename)
blob.upload_from_filename(fileName)
# Opt : if you want to make public access from the URL
blob.make_public()
return res


def generate_destination_filename(file_extension):
timestamp = datetime.datetime.now().strftime('%Y%m%d%H%M%S')
return f"images/{timestamp}.{file_extension}"



if __name__ == '__main__':
# app.run() # for global deployment
app.run(port=3001) # for local development
Binary file added server/test.jpg
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 server/testing/2.jpeg
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 server/testing/car.jpeg
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 server/testing/car_dent.jpg
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 server/testing/car_dent2.jpeg
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 server/testing/crack.jpg
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 server/testing/crack2.jpg
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 server/testing/dent.jpg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
17 changes: 17 additions & 0 deletions server/testing/img.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
from flask import *
from PIL import Image
import io
import base64
import cv2 as cv
from roboflow import Roboflow
from flask_ngrok import run_with_ngrok
import matplotlib.pyplot as plt
from firebase_admin import credentials, initialize_app, storage
import datetime
import string

rf = Roboflow(api_key="DzJXlBY4OY5a7ohy6WQ2")

project = rf.workspace().project("car_dent_scratch_detection-1")
model = project.version(9).model
model.predict("car_dent.jpg").save("dent.jpg")
Empty file added server/testing/requirements.txt
Empty file.
101 changes: 101 additions & 0 deletions server/testing/t2.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,101 @@
import cv2
import numpy as np


def detect_cracks(image_path):
# Load the image
image = cv2.imread(image_path, cv2.IMREAD_GRAYSCALE)

# Apply image preprocessing (e.g., thresholding, blurring) to enhance crack visibility
blurred = cv2.GaussianBlur(image, (5, 5), 0)
_, thresholded = cv2.threshold(
blurred, 0, 255, cv2.THRESH_BINARY_INV + cv2.THRESH_OTSU)

# Perform morphological operations to fill gaps and reduce noise
kernel = np.ones((3, 3), np.uint8)
dilated = cv2.dilate(thresholded, kernel, iterations=2)
closing = cv2.morphologyEx(dilated, cv2.MORPH_CLOSE, kernel)

# Find contours in the image
contours, _ = cv2.findContours(
closing, cv2.RETR_EXTERNAL, cv2.CHAIN_APPROX_SIMPLE)

# Iterate through the contours and filter out smaller ones (adjust the area threshold as needed)
min_area_threshold = 100
detected_cracks = []
for contour in contours:
area = cv2.contourArea(contour)
if area > min_area_threshold:
# Calculate the bounding rectangle for the contour
x, y, w, h = cv2.boundingRect(contour)
detected_cracks.append((x, y, x + w, y + h))

return detected_cracks


# Example usage
image_path = 'car.jpeg'
image = cv2.imread(image_path, cv2.IMREAD_GRAYSCALE)

cracks = detect_cracks(image_path)
for crack in cracks:
x1, y1, x2, y2 = crack
cv2.rectangle(image, (x1, y1), (x2, y2), (0, 255, 0), 2)

# Display the image with detected cracks
cv2.imshow('Detected Cracks', image)
cv2.waitKey(0)
cv2.destroyAllWindows()





################################### DENT #####################################
# import cv2
# import numpy as np


# def detect_dents(image_path):
# # Load the image
# image = cv2.imread(image_path, cv2.IMREAD_GRAYSCALE)

# # Apply image preprocessing (e.g., thresholding, blurring) to enhance dent visibility
# blurred = cv2.GaussianBlur(image, (5, 5), 0)
# _, thresholded = cv2.threshold(
# blurred, 0, 255, cv2.THRESH_BINARY_INV + cv2.THRESH_OTSU)

# # Perform morphological operations to fill gaps and reduce noise
# kernel = np.ones((3, 3), np.uint8)
# dilated = cv2.dilate(thresholded, kernel, iterations=2)
# closing = cv2.morphologyEx(dilated, cv2.MORPH_CLOSE, kernel)

# # Find contours in the image
# contours, _ = cv2.findContours(
# closing, cv2.RETR_EXTERNAL, cv2.CHAIN_APPROX_SIMPLE)

# # Iterate through the contours and filter out smaller ones (adjust the area threshold as needed)
# min_area_threshold = 100
# detected_dents = []
# for contour in contours:
# area = cv2.contourArea(contour)
# if area > min_area_threshold:
# # Calculate the bounding rectangle for the contour
# x, y, w, h = cv2.boundingRect(contour)
# detected_dents.append((x, y, x + w, y + h))

# return detected_dents


# # Example usage
# image_path = 'car_dent.jpg'
# image = cv2.imread(image_path, cv2.IMREAD_GRAYSCALE)
# dents = detect_dents(image_path)
# for dent in dents:
# x1, y1, x2, y2 = dent
# cv2.rectangle(image, (x1, y1), (x2, y2), (0, 0, 255), 2)

# # Display the image with detected dents
# cv2.imshow('Detected Dents', image)
# cv2.waitKey(0)
# cv2.destroyAllWindows()
Binary file added server/testing/testprediction.jpg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.

0 comments on commit 284e916

Please sign in to comment.