Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Feature] 可自定义滑窗和步长 & [Improve] 修改孔洞处理显示逻辑 #47

Merged
merged 24 commits into from
Oct 31, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
24 commits
Select commit Hold shift + click to select a range
1bca1c0
后端支持自定义滑窗和步长
jscslld Oct 21, 2022
2e01b6e
滑窗大小进行校验
jscslld Oct 24, 2022
fc59790
孔洞处理合并进入变化检测,无需手动指定
jscslld Oct 24, 2022
04f8014
Merge branch 'PaddleCV-SIG:develop' into feature/window
jscslld Oct 24, 2022
b3c271b
Merge pull request #15 from jscslld/feature/window
yibaikuai Oct 24, 2022
1ae90f5
Merge branch 'PaddleCV-SIG:develop' into feature/hole
yibaikuai Oct 26, 2022
080bc98
添加动画效果
yibaikuai Oct 26, 2022
2b30733
同步更新可拖拽框内信息
yibaikuai Oct 26, 2022
4dcf706
孔洞处理渲染
jscslld Oct 27, 2022
d1b93cc
限制window_size和stride
jscslld Oct 27, 2022
c83d124
Merge remote-tracking branch 'origin/feature/window' into feature/window
jscslld Oct 27, 2022
a144cf8
Merge pull request #16 from jscslld/feature/window
yibaikuai Oct 27, 2022
482d40d
变化检测功能实现自定义滑窗和步长
yibaikuai Oct 27, 2022
c521239
异步加载百度地图,改变ak编码形式
yibaikuai Oct 27, 2022
770432e
异步加载百度地图,改变ak编码形式
yibaikuai Oct 27, 2022
f868243
支持自定义端口号
jscslld Oct 28, 2022
91d0255
更新Readme
jscslld Oct 28, 2022
327e632
Merge pull request #17 from jscslld/pr/47_fix
yibaikuai Oct 28, 2022
5ab2074
Revert "更新Readme"
jscslld Oct 31, 2022
09d4dcd
修改错误的提示信息
jscslld Oct 31, 2022
e2627b8
Merge pull request #19 from jscslld/pr/47_fix
yibaikuai Oct 31, 2022
47d4687
统一模型名称
jscslld Oct 31, 2022
f9761b9
Merge pull request #20 from jscslld/pr/47_fix
yibaikuai Oct 31, 2022
97d8e22
修改模型命名,设置窗口和步长限制关系
yibaikuai Oct 31, 2022
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 5 additions & 3 deletions backend/app.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,9 @@ def error_handler(e):
with open('../config.yaml') as file:
config = yaml.load(file.read(), Loader=yaml.FullLoader)
with open("../frontend/.env", 'w') as file:
file.write("VUE_APP_BACKEND_PORT = {}\nVUE_APP_BACKEND_IP = {}".format(
config["port"]["backend"], config["host"]["backend"]
if config["host"]["backend"] != "0.0.0.0" else "127.0.0.1"))
file.write(
"VUE_APP_BACKEND_PORT = {}\nVUE_APP_BACKEND_IP = {}\nVUE_APP_BAIDU_MAP_ACCESS_KEY = {}".
format(config["port"]["backend"], config["host"]["backend"]
if config["host"]["backend"] != "0.0.0.0" else "127.0.0.1",
config["baidu_map"]["access_key"]))
app.run(host=config["host"]["backend"], port=config["port"]["backend"])
53 changes: 7 additions & 46 deletions backend/applications/api/analysis.py
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,12 @@ def show_result(type):
def change_detection_api():
req_json = request.json
model_path = req_json["model_path"]
window_size = int(req_json.get("window_size", 256))
stride = int(req_json.get("stride", 128))
if window_size <= 0 or stride <= 0:
return fail_api("步长和窗口大小必须大于0")
if window_size < stride:
jscslld marked this conversation as resolved.
Show resolved Hide resolved
return fail_api("步长必须小于等于窗口大小")
try:
model_info = get_model_info(model_path)
if model_info["_Attributes"]["model_type"] != "change_detector":
Expand All @@ -75,7 +81,7 @@ def change_detection_api():
print("----------------->change_detection" + json.dumps(req_json))
type_ = 1
change_detection(model_path, up_dir, generate_dir, list_, step1_, step2_,
type_)
type_, window_size, stride)
return success_api()


Expand Down Expand Up @@ -255,48 +261,3 @@ def image_pre():
for i, img in enumerate(imgs):
imgs[i] = generate_url + img
return success_api(data=imgs)


"""
孔洞处理
"""


@analysis_api.post('/hole')
def hole_handle1():
req_json = request.json
analysis_id = req_json["id"]
if analysis_id is None:
return fail_api("参数异常")

analysis = Analysis.query.filter_by(id=analysis_id, type=1).first()
if not analysis:
return fail_api("这一组分析记录不存在")
if analysis.type != 1:
return fail_api("类型错误")
if analysis.is_hole:
return fail_api("这一组分析记录已经孔洞处理过")
temps = list()
temps.append(analysis.after_img)
after_img, data = hole_handle(generate_dir, generate_dir, temps)
old_data = json.loads(analysis.data)
old_data.update(data)
mask, count = draw_masks(
os.path.join(generate_dir, os.path.basename(after_img)))
cv2.imwrite(
os.path.join(
generate_dir,
os.path.splitext(os.path.basename(after_img))[0] + "_mask.png"),
mask)
old_data["mask"] = generate_url + os.path.splitext(
os.path.basename(after_img))[0] + "_mask.png"
old_data["count"] = count
old_data["fractional_variation"] = compute_variation(
os.path.join(generate_dir, os.path.basename(after_img)))
Analysis.query.filter_by(id=analysis_id).update({
"after_img": after_img,
"data": json.dumps(old_data),
"is_hole": True
})
db.session.commit()
return success_api()
4 changes: 2 additions & 2 deletions backend/applications/api/model.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,10 +11,10 @@
@model_api.get('/list/<string:model_type>')
def get_model_list(model_type):
types_list = {
"change_detector": "change_detector",
"change_detection": "change_detector",
"classification": "classifier",
"image_restoration": "restorer",
"object_detector": "detector",
"object_detection": "detector",
"semantic_segmentation": "segmenter"
}
if model_type not in types_list:
Expand Down
5 changes: 3 additions & 2 deletions backend/applications/image_processing/render.py
Original file line number Diff line number Diff line change
Expand Up @@ -50,11 +50,12 @@ def render(name, data_dir, save_dir,


# 批量渲染
def batch_render(data_dir, save_dir, imgs):
def batch_render(data_dir, save_dir, imgs, prefix):
temps = list()
for img in imgs:
maps = dict()
for i in range(4):
maps[i] = generate_url + render(img, data_dir, save_dir, i)
maps[i] = generate_url + (prefix + "/" if prefix != "" else ""
) + render(img, data_dir, save_dir, i)
temps.append(maps)
return temps
53 changes: 44 additions & 9 deletions backend/applications/interface/analysis.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
import cv2

from applications.common.path_global import fun_type_1, fun_type_2, fun_type_3, fun_type_4, fun_type_5, \
fun_type_6, fun_type_7, generate_url, fun_type_8, up_url
fun_type_6, fun_type_7, generate_url, fun_type_8, up_url, generate_dir
from applications.common.utils.upload import img_url_handle
from applications.extensions import db
from applications.image_processing import histogram_match
Expand Down Expand Up @@ -47,13 +47,22 @@ def save_analysis(type_,
db.session.commit()


def change_detection(model_path, data_path, out_dir, names, step1, step2,
type_):
def change_detection(model_path,
data_path,
out_dir,
names,
step1,
step2,
type_,
window_size=256,
stride=128):
"""
变化检测
:param model_path: 静态图模型路径
:param data_path: 图片数据路径,路径中有名称为A和B的两个文件夹分别存储不同时相的图片(1024,1024),且相应图片名称相同
:param out_dir:图片保存路径
:param window_size:滑窗大小
:param stride:步长
:return:
"""
print("变化检测----------------->start")
Expand Down Expand Up @@ -87,7 +96,13 @@ def change_detection(model_path, data_path, out_dir, names, step1, step2,
pair["second"] = resizes1[i]
i += 1
# 3.检测对比,带地址的文件名,纯文件名
retPics, filenames = CD.execute(model_path, data_path, out_dir, names)
retPics, filenames = CD.execute(
model_path,
data_path,
out_dir,
names,
window_size=window_size,
stride=stride)
# 4.检测渲染
res = handle(fun_type_6, filenames, out_dir, out_dir)
# 5.入库
Expand All @@ -101,19 +116,39 @@ def change_detection(model_path, data_path, out_dir, names, step1, step2,
cv2.imwrite(
os.path.join(out_dir,
os.path.splitext(filenames[i])[0] + "_mask.png"), mask)
res[i]["mask"] = generate_url + os.path.splitext(filenames[i])[
res[i]["mask"] = out_dir + os.path.splitext(filenames[i])[
0] + "_mask.png"
res[i]["count"] = count
res[i]["fractional_variation"] = compute_variation(
os.path.join(out_dir, filenames[i]))
after_img, data = hole_handle(out_dir, out_dir + "hole/", [retPic])
res[i]["hole"] = after_img
res[i]["hole_style"] = handle(
fun_type_6, [os.path.basename(after_img)],
out_dir + "hole/",
out_dir + "hole/",
prefix="hole")[0]
mask, count = draw_masks(
os.path.join(out_dir + "hole/", os.path.basename(after_img)))
cv2.imwrite(
os.path.join(
out_dir + "hole/",
os.path.splitext(os.path.basename(after_img))[0] + "_mask.png"),
mask)
res[i]["mask_hole"] = out_dir + "hole/" + os.path.splitext(
os.path.basename(after_img))[0] + "_mask.png"
res[i]["count_hole"] = count
res[i]["fractional_variation_hole"] = compute_variation(
os.path.join(generate_dir + "hole/", os.path.basename(after_img)))
data = json.dumps(res[i])
save_analysis(
type_,
first_,
retPic,
pic2=second_,
data=data,
checked=str(step1) + "," + str(step2))
checked=str(step1) + "," + str(step2),
is_hole=True)
i += 1
print("变化检测----------------->end")

Expand All @@ -124,7 +159,7 @@ def hole_handle(data_path, out_dir, names):
res = handle(fun_type_8, names, data_path, out_dir)
# 4.检测渲染
res1 = handle(fun_type_6, res, out_dir, out_dir)
return generate_url + res[0], res1[0]
return generate_url + "hole/" + res[0], res1[0]


def url_handle(imgs):
Expand Down Expand Up @@ -271,7 +306,7 @@ def image_restoration(model_path, data_path, out_dir, names, type_):
print("图像复原----------------->end")


def handle(fun_type, imgs, src_dir, save_dir):
def handle(fun_type, imgs, src_dir, save_dir, prefix=""):
"""

:param fun_type:
Expand Down Expand Up @@ -305,7 +340,7 @@ def handle(fun_type, imgs, src_dir, save_dir):
elif fun_type == fun_type_5:
temps = gaussian_blur(src_dir, save_dir, imgs)
elif fun_type == fun_type_6:
temps = batch_render(src_dir, save_dir, imgs)
temps = batch_render(src_dir, save_dir, imgs, prefix)
elif fun_type == fun_type_7:
temps = batch_render_seg(src_dir, save_dir, imgs)
elif fun_type == fun_type_8:
Expand Down
Empty file.
4 changes: 3 additions & 1 deletion config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -3,4 +3,6 @@ port:
frontend: 3000
host:
backend: 0.0.0.0
frontend: 0.0.0.0
frontend: 0.0.0.0
baidu_map:
access_key: <ACCESS_KEY>
3 changes: 2 additions & 1 deletion frontend/.env
Original file line number Diff line number Diff line change
@@ -1,2 +1,3 @@
VUE_APP_BACKEND_PORT = 5008
VUE_APP_BACKEND_IP = 127.0.0.1
VUE_APP_BACKEND_IP = 127.0.0.1
VUE_APP_BAIDU_MAP_ACCESS_KEY = <ACCESS_KEY>
1 change: 1 addition & 0 deletions frontend/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
},
"dependencies": {
"@vueuse/core": "^8.5.0",
"animate.css": "^4.1.1",
"axios": "^0.26.1",
"core-js": "^3.8.3",
"element-plus": "2.1.10",
Expand Down
1 change: 0 additions & 1 deletion frontend/public/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@
<meta name="viewport" content="width=device-width,initial-scale=1.0">
<link rel="icon" type="image/x-icon" href="<%= BASE_URL %>logo.svg">
<title>PP-GeoView智能遥感解译平台</title>
<script type="text/javascript" src="http://api.map.baidu.com/api?v=3.0&ak=LBgFajzXhdHS09BAfSQYLM6akvzr71QM"></script>
</head>

<body>
Expand Down
2 changes: 0 additions & 2 deletions frontend/src/App.vue
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,6 @@
<script>
export default {
name: 'App',

}
</script>


7 changes: 0 additions & 7 deletions frontend/src/api/upload.js
Original file line number Diff line number Diff line change
Expand Up @@ -30,13 +30,6 @@ export function histogramUpload(data){
})
}

export function holeHandle(data){
return request({
method:'POST',
url:'api/analysis/hole',
data
})
}

export function prePhotoHandle(data){
return request({
Expand Down
1 change: 1 addition & 0 deletions frontend/src/main.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import './assets/css/normalize.css'
import '@/assets/css/app.css'
import '@/assets/css/font.css'
import 'element-plus/theme-chalk/display.css'
import 'animate.css';

import JSZIP from "jszip"
import zhCn from 'element-plus/es/locale/lang/zh-cn'
Expand Down
17 changes: 17 additions & 0 deletions frontend/src/utils/loadMap.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
export default function loadBMap(ak) {
return new Promise(function(resolve, reject) {
if (typeof BMap !== 'undefined') {
resolve(BMap)
return true
}
window.onBMapCallback = function() {
resolve(BMap)
}
let script = document.createElement('script')
script.type = 'text/javascript'
script.src =
'http://api.map.baidu.com/api?v=3.0&ak=' + ak + '&callback=onBMapCallback'
script.onerror = reject
document.head.appendChild(script)
})
}
Loading