Browse Source

调整图片路径

gushoubang 7 months ago
parent
commit
804bbcebc3
2 changed files with 29 additions and 24 deletions
  1. 5 3
      change_detect.py
  2. 24 21
      main.py

+ 5 - 3
change_detect.py

@@ -20,7 +20,7 @@ import uuid
 # 下面的语句构建的Predictor对象依赖static_models/目录中存储的部署格式模型,并使用GPU进行推理。
 predictor = Predictor("inference_model_change", use_gpu=True)
 
-def start(image1,image2):
+def start(image1,image2,outputPath):
     # 第二步:调用Predictor的predict()方法执行推理。该方法接受的输入参数如下:
     #     img_file: 对于场景分类、图像复原、目标检测和图像分割任务来说,该参数可为单一图像路径,或是解码后的、排列格式为(H, W, C)
     #         且具有float32类型的图像数据(表示为numpy的ndarray形式),或者是一组图像路径或np.ndarray对象构成的列表;对于变化检测
@@ -49,7 +49,7 @@ def start(image1,image2):
     # plt.axis('off')  # 不显示坐标轴
     # plt.show()
     # TODO: 保存变化图
-    savePath = 'predict/'+str(uuid.uuid4())+'.png'
+    savePath = outputPath+str(uuid.uuid4())+'.png'
     # 保存变化图
     change_map_image.save(savePath)
 
@@ -59,4 +59,6 @@ def start(image1,image2):
     # result = predictor.predict(img_file='test.jpg',
     #                            warmup_iters=100,
     #                            repeats=100)
-    return savePath
+    return savePath
+
+start('test1.jpg','test2.jpg')

+ 24 - 21
main.py

@@ -1,6 +1,6 @@
 from flask import Flask, request, jsonify,send_from_directory,Response
 import uuid
-# from change_detect import start
+from change_detect import start
 import requests
 from PIL import Image
 from io import BytesIO
@@ -9,9 +9,12 @@ from io import BytesIO
 app = Flask(__name__)
 
 # 设置静态文件夹(如果您想指定路径)
-app.config['UPLOAD_FOLDER'] = 'predict'
+app.config['UPLOAD_FOLDER'] = 'predict/output'
 host = 'http://192.168.60.2'
 
+uploadPath = 'predict/upload/'
+outputPath = 'predict/output/'
+
 # GET 请求接口示例
 @app.route('/api/get_data', methods=['GET'])
 def get_data():
@@ -32,8 +35,8 @@ def upload_image():
     img1 = request.files['img1']
     img2 = request.files['img2']
     # 保存文件
-    filePath1 = 'predict/' + str(uuid.uuid4()) + img1.filename
-    filePath2 = 'predict/' + str(uuid.uuid4()) + img2.filename
+    filePath1 = uploadPath + str(uuid.uuid4()) + img1.filename
+    filePath2 = uploadPath + str(uuid.uuid4()) + img2.filename
 
     img1.save(filePath1)
     img2.save(filePath2)
@@ -61,7 +64,7 @@ def save_image():
             }
         })
     img1 = Image.open(BytesIO(response1.content))
-    img1Path = 'predict/' + str(uuid.uuid4()) + '.png'
+    img1Path = uploadPath + str(uuid.uuid4()) + '.png'
     img1.save(img1Path,format='PNG')
 
     response2 = requests.get('http://192.168.60.63'+img2)
@@ -73,7 +76,7 @@ def save_image():
             }
         })
     img2 = Image.open(BytesIO(response2.content))
-    img2Path = 'predict/' + str(uuid.uuid4()) + '.png'
+    img2Path = uploadPath + str(uuid.uuid4()) + '.png'
     img2.save(img2Path,format='PNG')
 
     return jsonify({
@@ -84,20 +87,20 @@ def save_image():
         }
     })
 
-# # POST 分析图片
-# @app.route('/api/detect_image', methods=['POST'])
-# def detect_image():
-#     # 获取图片路径
-#     data = request.get_json()
-#     img1 = data['img1']
-#     img2 = data['img2']
-#     getImgPath=start(img1,img2)
-#     return jsonify({
-#         "message": "分析成功",
-#         "data":{
-#             "img": host+'/predict/'+getImgPath
-#         }
-#     })
+# POST 分析图片
+@app.route('/api/detect_image', methods=['POST'])
+def detect_image():
+    # 获取图片路径
+    data = request.get_json()
+    img1 = data['img1']
+    img2 = data['img2']
+    getImgPath=start(img1,img2,outputPath)
+    return jsonify({
+        "message": "分析成功",
+        "data":{
+            "img": host+getImgPath
+        }
+    })
 
 # 访问静态文件
 @app.route('/predict/<filename>')
@@ -107,7 +110,7 @@ def view_file(filename):
 # 测试转发接口
 # 目标代理服务 URL
 WMS_PROXY_URL = "http://192.168.60.2:9206/proxy/handle/22d38ad36d354a6fb8adc2fb378a66d6/siweiserver/wms"
-@app.route('/proxy/wms', methods=['GET'])
+@app.route('/proxy/handle/22d38ad36d354a6fb8adc2fb378a66d6/siweiserver/wms', methods=['GET'])
 def proxy_wms():
     # 从客户端请求中获取参数
     params = request.args.to_dict()