-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
34d09a2
commit 284e916
Showing
20 changed files
with
234 additions
and
3 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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() |
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.