diff --git a/src/pages/components/PointsBlur.js b/src/pages/components/PointsBlur.js index 1819e03..1f0a501 100644 --- a/src/pages/components/PointsBlur.js +++ b/src/pages/components/PointsBlur.js @@ -232,6 +232,9 @@ const PointBlurImageComponent = ({ imageSrc, blurredRegions, loaded, setLoaded, {isOpen && (
+
+ Select label +
{listLabel?.map((el, i) => (
@@ -255,7 +258,7 @@ const PointBlurImageComponent = ({ imageSrc, blurredRegions, loaded, setLoaded, setIsOpen(false); redrawCanvas(); }} - style={{ backgroundColor: "#ff0000", marginTop: "5px", marginBottom: "5px", width: "150px", color: "#000" }}> + style={{ backgroundColor: "#ff0000", marginBottom: "10px", width: "150px", color: "#fff" }}> Delete
diff --git a/src/pages/index.js b/src/pages/index.js index 620a2b4..b355301 100644 --- a/src/pages/index.js +++ b/src/pages/index.js @@ -11,13 +11,11 @@ const Main = () => { const [imageName, setImageName] = useState(""); const handleFileChange = async (event) => { - console.log(event.target.files); const file = event.target.files[0]; if (!file) return; const formData = new FormData(); formData.append("image", file); - // setImageSrc(URL.createObjectURL(file)); blurredRegions.current = []; setLoaded(false); try { @@ -56,37 +54,39 @@ const Main = () => { }; const handleSave = async () => { - let arrPoints = ""; - blurredRegions.current?.forEach((points) => { - const img_w = infoImage?.width; - const img_h = infoImage?.height; + if (blurredRegions.current?.length > 0) { + let arrPoints = ""; + blurredRegions.current?.forEach((points) => { + const img_w = infoImage?.width; + const img_h = infoImage?.height; - // Get bounding box - const x_min = Math.min(...points.map((p) => p.x)); - const y_min = Math.min(...points.map((p) => p.y)); - const x_max = Math.max(...points.map((p) => p.x)); - const y_max = Math.max(...points.map((p) => p.y)); + // Get bounding box + const x_min = Math.min(...points.map((p) => p.x)); + const y_min = Math.min(...points.map((p) => p.y)); + const x_max = Math.max(...points.map((p) => p.x)); + const y_max = Math.max(...points.map((p) => p.y)); - const x_center = (x_min + x_max) / 2 / img_w; - const y_center = (y_min + y_max) / 2 / img_h; - const width = (x_max - x_min) / img_w; - const height = (y_max - y_min) / img_h; + const x_center = (x_min + x_max) / 2 / img_w; + const y_center = (y_min + y_max) / 2 / img_h; + const width = (x_max - x_min) / img_w; + const height = (y_max - y_min) / img_h; - // Get class ID - const class_id = listLabel.find((label) => label?.name === points[0].label)?.id || "0"; + // Get class ID + const class_id = listLabel.find((label) => label?.name === points[0].label)?.id || "0"; - const yolo_label = `${class_id} ${x_center.toFixed(6)} ${y_center.toFixed(6)} ${width.toFixed(6)} ${height.toFixed(6)}`; + const yolo_label = `${class_id} ${x_center.toFixed(6)} ${y_center.toFixed(6)} ${width.toFixed(6)} ${height.toFixed(6)}`; - arrPoints += yolo_label + "\n"; - }); - const url = "http://localhost:5000/save"; - const formData = new FormData(); - formData.append("list", arrPoints); - formData.append("imageName", imageName); - await fetch(url, { - method: "POST", - body: formData, - }); + arrPoints += yolo_label + "\n"; + }); + const url = "http://localhost:5000/save"; + const formData = new FormData(); + formData.append("list", arrPoints); + formData.append("imageName", imageName); + await fetch(url, { + method: "POST", + body: formData, + }); + } }; return ( diff --git a/src/server/images/detect_image_250226_142652.png b/src/server/images/detect_image_250226_142652.png new file mode 100644 index 0000000..b5aa62b Binary files /dev/null and b/src/server/images/detect_image_250226_142652.png differ diff --git a/src/server/label/detect_image_250226_142652.txt b/src/server/label/detect_image_250226_142652.txt new file mode 100644 index 0000000..8edd0d2 --- /dev/null +++ b/src/server/label/detect_image_250226_142652.txt @@ -0,0 +1,20 @@ +1 0.846875 0.679733 0.102500 0.046706 +1 0.399687 0.411593 0.091875 0.032527 +1 0.394375 0.494579 0.096250 0.036697 +1 0.380000 0.703086 0.107500 0.041701 +1 0.384062 0.592160 0.104375 0.041701 +0 0.751563 0.582152 0.038125 0.031693 +0 0.302187 0.718098 0.043125 0.031693 +0 0.324688 0.505421 0.038125 0.028357 +0 0.725938 0.486239 0.036875 0.028357 +0 0.334375 0.416597 0.035000 0.025855 +0 0.774687 0.688907 0.039375 0.036697 +1 0.399375 0.333194 0.090000 0.032527 +0 0.310000 0.603003 0.038750 0.031693 +0 0.697187 0.325271 0.033125 0.020017 +0 0.703125 0.401168 0.032500 0.025021 +0 0.336875 0.337364 0.035000 0.022519 +1 0.792500 0.481234 0.092500 0.033361 +1 0.820937 0.572560 0.100625 0.040867 +1 0.759687 0.325271 0.080000 0.028357 +1 0.766250 0.399917 0.076875 0.032527 diff --git a/src/server/main.py b/src/server/main.py index 715d63b..6507c06 100644 --- a/src/server/main.py +++ b/src/server/main.py @@ -73,8 +73,8 @@ def get_image(filename): @app.route('/save', methods=['POST']) def save_data(): # Get form data - arr_points = request.form.get("list") # This will be a string - image_name = request.form.get("imageName") # This will be a string + arr_points = request.form.get("list") + image_name = request.form.get("imageName") if not arr_points or not image_name: return jsonify({"error": "Missing required fields"}), 400