Strategy-M Python Code (Notepad)
Strategy-M Python Code (Notepad)
# Flask setup
app = Flask(__name__)
# Initialize variables
images = {"Top View": None, "Side View": None, "Front View": None}
dimensions_mm = {"Width (mm)": 0, "Height (mm)": 0, "Depth (mm)": 0}
def show_instructions():
"""Display the instructions for accurate results."""
messagebox.showinfo("Instructions", instructions)
def select_image(view):
"""Select and display an image for the given view."""
global canvas, images
img_path = filedialog.askopenfilename(filetypes=[("Image files", "*.jpg *.png
*.jpeg")])
if img_path:
images[view] = img_path
img = Image.open(img_path)
img.thumbnail((300, 300))
img_tk = ImageTk.PhotoImage(img)
canvas[view].create_image(150, 150, image=img_tk)
canvas[view].image = img_tk
def calculate_dimensions():
"""Calculate the dimensions in mm based on all three views."""
global images, dimensions_mm, PIXEL_TO_MM_RATIO, flask_results
# Check if all three views are uploaded
if not all(images.values()):
messagebox.showerror("Error", "Please upload images for all three views!")
return
if not contours:
messagebox.showerror("Error", f"No tooth detected in the {view}
image.")
return
# Display results
result.set(
f"Width: {dimensions_mm['Width (mm)']:.2f} mm\n"
f"Height: {dimensions_mm['Height (mm)']:.2f} mm\n"
f"Depth: {dimensions_mm['Depth (mm)']:.2f} mm\n\n"
f"Estimated Volume: {volume_mm3/1000:.2f} cm³"
)
def generate_barcode(data):
"""Generate a barcode and save it in the specified folder."""
barcode_class = Code128(data, writer=ImageWriter())
img_path = "C:/Users/suhas/OneDrive/Desktop/STRATEGY-M
PROJECT/Generated_Codes/barcode.png.png"
barcode_class.save(img_path)
qr_label.config(image=barcode_img_tk)
qr_label.image = barcode_img_tk
def clear_app():
"""Clear the app's canvas, reset dimensions, and retain the barcode."""
global images, dimensions_mm, flask_results
# Clear images
images = {"Top View": None, "Side View": None, "Front View": None}
# Reset dimensions
dimensions_mm = {"Width (mm)": 0, "Height (mm)": 0, "Depth (mm)": 0}
# Clear canvas
for view in canvas:
canvas[view].delete("all")
qr_label.config(image=barcode_img_tk)
qr_label.image = barcode_img_tk
# Header label
header = tk.Label(root, text="Tooth 3D Dimension Finder", font=("Arial", 18,
"bold"))
header.pack(pady=10)
# Instruction button
instruction_button = tk.Button(root, text="Show Instructions",
command=show_instructions)
instruction_button.pack(pady=5)
canvas = {}
for idx, view in enumerate(["Top View", "Side View", "Front View"]):
frame = tk.Frame(canvas_frame)
frame.grid(row=0, column=idx, padx=10)
# Calculate button
calc_btn = tk.Button(root, text="Calculate Dimensions",
command=calculate_dimensions)
calc_btn.pack(pady=10)
# Display results
result = tk.StringVar()
result.set("Width: 0.00 mm\nHeight: 0.00 mm\nDepth: 0.00 mm\n\nEstimated Volume:
0.00 mm³")
result_label = tk.Label(root, textvariable=result, font=("Arial", 12))
result_label.pack(pady=10)
# Barcode display
qr_label = tk.Label(root)
qr_label.pack(pady=10)
# Clear button
clear_button = tk.Button(root, text="Clear All", command=clear_app)
clear_button.pack(pady=5)
flask_thread = threading.Thread(target=run_flask)
flask_thread.start()