|
@@ -26,8 +26,6 @@
|
|
</el-icon>
|
|
</el-icon>
|
|
</el-button>
|
|
</el-button>
|
|
</el-button-group>
|
|
</el-button-group>
|
|
- <!-- <div class="page-tool-item" @click="prePage">上一页</div>
|
|
|
|
- <div class="page-tool-item" @click="nextPage">下一页</div> -->
|
|
|
|
<div class="page-tool-item">{{ state.pageNum }}/{{ state.numPages }}</div>
|
|
<div class="page-tool-item">{{ state.pageNum }}/{{ state.numPages }}</div>
|
|
<el-container>
|
|
<el-container>
|
|
<el-input type="number" v-model="pdf_page"></el-input>
|
|
<el-input type="number" v-model="pdf_page"></el-input>
|
|
@@ -52,10 +50,20 @@
|
|
<el-button type="danger" @click="submitBug" disabled>提交bug</el-button>
|
|
<el-button type="danger" @click="submitBug" disabled>提交bug</el-button>
|
|
</el-row>
|
|
</el-row>
|
|
<div>
|
|
<div>
|
|
- <el-scrollbar height="600px">
|
|
|
|
|
|
+ <h2>图片</h2>
|
|
|
|
+ <el-scrollbar height="auto">
|
|
<ul>
|
|
<ul>
|
|
- <li v-for="(item, index) in recArr" :key="index" @click="handleClick(index, item)"
|
|
|
|
- :style="index == selectedItem ? 'color: blue' : ''">
|
|
|
|
|
|
+ <li v-for="(item, index) in figureArr" :key="index" @click="figureHandleClick(index, item, figure_rects)"
|
|
|
|
+ :style="index == figureSelectedItem ? 'color: blue' : ''">
|
|
|
|
+ {{ item }}
|
|
|
|
+ </li>
|
|
|
|
+ </ul>
|
|
|
|
+ </el-scrollbar>
|
|
|
|
+ <h2>表格</h2>
|
|
|
|
+ <el-scrollbar height="auto">
|
|
|
|
+ <ul>
|
|
|
|
+ <li v-for="(item, index) in tableArr" :key="index" @click="tableHandleClick(index, item, table_rects)"
|
|
|
|
+ :style="index == tableSelectedItem ? 'color: blue' : ''">
|
|
{{ item }}
|
|
{{ item }}
|
|
</li>
|
|
</li>
|
|
</ul>
|
|
</ul>
|
|
@@ -81,7 +89,6 @@ import {
|
|
} from '@element-plus/icons-vue'
|
|
} from '@element-plus/icons-vue'
|
|
|
|
|
|
let loadingTask: any;
|
|
let loadingTask: any;
|
|
-
|
|
|
|
const is_pdf = ref(false);
|
|
const is_pdf = ref(false);
|
|
const pdf_page = ref(1);
|
|
const pdf_page = ref(1);
|
|
const pdf_img: any = ref("")
|
|
const pdf_img: any = ref("")
|
|
@@ -89,7 +96,6 @@ const pdf_img: any = ref("")
|
|
const state = reactive({
|
|
const state = reactive({
|
|
source: "", //预览pdf文件地址
|
|
source: "", //预览pdf文件地址
|
|
pageNum: 1, //当前页面
|
|
pageNum: 1, //当前页面
|
|
- // scale: 4, // 缩放比例
|
|
|
|
numPages: 0, // 总页数
|
|
numPages: 0, // 总页数
|
|
});
|
|
});
|
|
|
|
|
|
@@ -113,11 +119,9 @@ function getPdfImage(index: number) {
|
|
const viewport = page.getViewport({ scale: 4.0 })
|
|
const viewport = page.getViewport({ scale: 4.0 })
|
|
canvas.value.height = viewport.height;
|
|
canvas.value.height = viewport.height;
|
|
canvas.value.width = viewport.width;
|
|
canvas.value.width = viewport.width;
|
|
- // 画布的dom大小, 设置移动端,宽度设置铺满整个屏幕
|
|
|
|
- // const clientWidth = document.body.clientWidth;
|
|
|
|
const destWidth = 398;
|
|
const destWidth = 398;
|
|
canvas.value.style.width = destWidth + 'px';
|
|
canvas.value.style.width = destWidth + 'px';
|
|
- // 根据pdf每页的宽高比例设置canvas的高度
|
|
|
|
|
|
+
|
|
canvas.value.style.height = destWidth * (viewport.height / viewport.width) + 'px';
|
|
canvas.value.style.height = destWidth * (viewport.height / viewport.width) + 'px';
|
|
const ctx = canvas.value.getContext('2d');
|
|
const ctx = canvas.value.getContext('2d');
|
|
page.render({
|
|
page.render({
|
|
@@ -129,7 +133,8 @@ function getPdfImage(index: number) {
|
|
const showImg = document.getElementById("show-img") as HTMLImageElement;
|
|
const showImg = document.getElementById("show-img") as HTMLImageElement;
|
|
showImg.src = canvas.value.toDataURL('images/png', 1.0);
|
|
showImg.src = canvas.value.toDataURL('images/png', 1.0);
|
|
fa_canvas = new fabric.Canvas(canvas.value);
|
|
fa_canvas = new fabric.Canvas(canvas.value);
|
|
- rects.splice(0)
|
|
|
|
|
|
+ figure_rects.splice(0)
|
|
|
|
+ table_rects.splice(0)
|
|
});
|
|
});
|
|
})
|
|
})
|
|
});
|
|
});
|
|
@@ -189,16 +194,14 @@ let show_predict = ref(false)
|
|
let predictTime = ref(0)
|
|
let predictTime = ref(0)
|
|
const fileName = ref(null);
|
|
const fileName = ref(null);
|
|
const canvas = ref(null as unknown as HTMLCanvasElement);
|
|
const canvas = ref(null as unknown as HTMLCanvasElement);
|
|
|
|
+let figureSelectedItem = ref(-1)
|
|
|
|
+let tableSelectedItem = ref(-1)
|
|
|
|
|
|
-let selectedItem = ref(-1)
|
|
|
|
-
|
|
|
|
-let recArr: any = ref([])
|
|
|
|
|
|
+let figureArr: any = ref([])
|
|
|
|
+let tableArr: any = ref([])
|
|
|
|
|
|
let fa_canvas: any = null;
|
|
let fa_canvas: any = null;
|
|
-const rec_result = ref("");
|
|
|
|
let bugId = ref("");
|
|
let bugId = ref("");
|
|
-
|
|
|
|
-const activeName = ref('2')
|
|
|
|
const json_result = ref("");
|
|
const json_result = ref("");
|
|
|
|
|
|
interface iRect {
|
|
interface iRect {
|
|
@@ -208,7 +211,8 @@ interface iRect {
|
|
height: number
|
|
height: number
|
|
}
|
|
}
|
|
|
|
|
|
-let rects: any = []
|
|
|
|
|
|
+let figure_rects: any = []
|
|
|
|
+let table_rects: any = []
|
|
|
|
|
|
onMounted(async () => {
|
|
onMounted(async () => {
|
|
canvas.value = document.getElementById("canvas") as HTMLCanvasElement;
|
|
canvas.value = document.getElementById("canvas") as HTMLCanvasElement;
|
|
@@ -232,7 +236,6 @@ const uploadImg = () => {
|
|
fa_canvas ? fa_canvas.clear() : 0;
|
|
fa_canvas ? fa_canvas.clear() : 0;
|
|
if (post_ == ".pdf") {
|
|
if (post_ == ".pdf") {
|
|
state.pageNum = 1;
|
|
state.pageNum = 1;
|
|
- // state.scale = 4;
|
|
|
|
state.source = URL.createObjectURL(file);
|
|
state.source = URL.createObjectURL(file);
|
|
is_pdf.value = true
|
|
is_pdf.value = true
|
|
loadingTask = createLoadingTask(state.source);
|
|
loadingTask = createLoadingTask(state.source);
|
|
@@ -243,13 +246,14 @@ const uploadImg = () => {
|
|
canvas.value.width = showImg.width;
|
|
canvas.value.width = showImg.width;
|
|
canvas.value.height = showImg.height;
|
|
canvas.value.height = showImg.height;
|
|
fa_canvas = new fabric.Canvas(canvas.value);
|
|
fa_canvas = new fabric.Canvas(canvas.value);
|
|
- rects.splice(0)
|
|
|
|
- selectedItem.value = -1;
|
|
|
|
|
|
+ figure_rects.splice(0)
|
|
|
|
+ table_rects.splice(0)
|
|
|
|
+ figureSelectedItem.value = -1;
|
|
|
|
+ tableSelectedItem.value = -1;
|
|
}
|
|
}
|
|
is_pdf.value = false
|
|
is_pdf.value = false
|
|
} else {
|
|
} else {
|
|
alert('不支持的文件格式!')
|
|
alert('不支持的文件格式!')
|
|
- // fileName.value = null
|
|
|
|
}
|
|
}
|
|
};
|
|
};
|
|
reader.readAsDataURL(file);
|
|
reader.readAsDataURL(file);
|
|
@@ -277,7 +281,6 @@ function CreateRect(canvas: any, i: number, left: number, top: number, width: nu
|
|
}) as RectWithId;
|
|
}) as RectWithId;
|
|
rect.set('id', i);
|
|
rect.set('id', i);
|
|
canvas.add(rect);
|
|
canvas.add(rect);
|
|
- // canvas.renderAll();
|
|
|
|
}
|
|
}
|
|
|
|
|
|
const predict = async () => {
|
|
const predict = async () => {
|
|
@@ -287,7 +290,8 @@ const predict = async () => {
|
|
}
|
|
}
|
|
|
|
|
|
fa_canvas.clear()
|
|
fa_canvas.clear()
|
|
- rects.splice(0)
|
|
|
|
|
|
+ figure_rects.splice(0)
|
|
|
|
+ table_rects.splice(0)
|
|
|
|
|
|
const img = document.getElementById("show-img") as HTMLImageElement;
|
|
const img = document.getElementById("show-img") as HTMLImageElement;
|
|
const inputElement = document
|
|
const inputElement = document
|
|
@@ -300,32 +304,40 @@ const predict = async () => {
|
|
|
|
|
|
if (is_pdf.value) {
|
|
if (is_pdf.value) {
|
|
const file: any = convertCanvasToFile(canvas.value, "pdf.png").then(result => {
|
|
const file: any = convertCanvasToFile(canvas.value, "pdf.png").then(result => {
|
|
- data.append('images', result);
|
|
|
|
|
|
+ data.append('image', result);
|
|
Detection(data).then(res => {
|
|
Detection(data).then(res => {
|
|
console.log(res.code)
|
|
console.log(res.code)
|
|
json_result.value = JSON.stringify(res.data, null, 4);
|
|
json_result.value = JSON.stringify(res.data, null, 4);
|
|
console.log(res.data);
|
|
console.log(res.data);
|
|
- recArr.value.splice(0);
|
|
|
|
- let tmp_text = res.data.labels;
|
|
|
|
- if (tmp_text.length == 0) {
|
|
|
|
- recArr.value.push("no result!");
|
|
|
|
|
|
+ figureArr.value.splice(0);
|
|
|
|
+ tableArr.value.splice(0);
|
|
|
|
+ let tmp_labels = res.data.labels;
|
|
|
|
+ if (tmp_labels.length == 0) {
|
|
|
|
+ alert("no result!");
|
|
} else {
|
|
} else {
|
|
- for (let i = 0; i < tmp_text.length; i++) {
|
|
|
|
- recArr.value.push(tmp_text[i]);
|
|
|
|
|
|
+ let tmp_boxes = res.data.boxes;
|
|
|
|
+ const h_radio = img.height / img.naturalHeight;
|
|
|
|
+ const w_radio = img.width / img.naturalWidth;
|
|
|
|
+
|
|
|
|
+ for (let i = 0; i < tmp_labels.length; i++) {
|
|
|
|
+ let left = w_radio * tmp_boxes[i][0];
|
|
|
|
+ let top = h_radio * tmp_boxes[i][1];
|
|
|
|
+ let width = w_radio * (tmp_boxes[i][2] - tmp_boxes[i][0]);
|
|
|
|
+ let height = h_radio * (tmp_boxes[i][3] - tmp_boxes[i][1]);
|
|
|
|
+ const rect: iRect = { left, top, width, height };
|
|
|
|
+ if (tmp_labels[i] == "Figure") {
|
|
|
|
+ figureArr.value.push("图片" + String(figureArr.value.length + 1));
|
|
|
|
+ figure_rects.push(rect);
|
|
|
|
+ } else if (tmp_labels[i] == "Table_0" || tmp_labels[i] == "Table_std") {
|
|
|
|
+ tableArr.value.push("表格" + String(tableArr.value.length + 1));
|
|
|
|
+ table_rects.push(rect);
|
|
|
|
+ }
|
|
|
|
+ CreateRect(fa_canvas, i, left, top, width, height, false);
|
|
}
|
|
}
|
|
- }
|
|
|
|
- let tmp_boxes = res.data.boxes;
|
|
|
|
- // fa_canvas = new fabric.Canvas(canvas.value);
|
|
|
|
- const h_radio = img.height / img.naturalHeight;
|
|
|
|
- const w_radio = img.width / img.naturalWidth;
|
|
|
|
- for (let i = 0; i < tmp_boxes.length; i++) {
|
|
|
|
- let left = w_radio * tmp_boxes[i][0];
|
|
|
|
- let top = h_radio * tmp_boxes[i][1];
|
|
|
|
- let width = w_radio * (tmp_boxes[i][2] - tmp_boxes[i][0]);
|
|
|
|
- let height = h_radio * (tmp_boxes[i][3] - tmp_boxes[i][1]);
|
|
|
|
- const rect: iRect = { left, top, width, height };
|
|
|
|
- rects.push(rect);
|
|
|
|
- CreateRect(fa_canvas, i, left, top, width, height, false);
|
|
|
|
|
|
+ // if (figureArr.value.length == 0)
|
|
|
|
+ // figureArr.value.push("无");
|
|
|
|
+ // if (tableArr.value.length == 0)
|
|
|
|
+ // tableArr.value.push("无");
|
|
}
|
|
}
|
|
predictTime.value = res.data.cost;
|
|
predictTime.value = res.data.cost;
|
|
loading.value = !loading.value;
|
|
loading.value = !loading.value;
|
|
@@ -339,34 +351,42 @@ const predict = async () => {
|
|
});
|
|
});
|
|
})
|
|
})
|
|
} else {
|
|
} else {
|
|
- data.append('images', file);
|
|
|
|
|
|
+ data.append('image', file);
|
|
|
|
|
|
Detection(data).then(res => {
|
|
Detection(data).then(res => {
|
|
console.log(res.code)
|
|
console.log(res.code)
|
|
json_result.value = JSON.stringify(res.data, null, 4);
|
|
json_result.value = JSON.stringify(res.data, null, 4);
|
|
console.log(res.data);
|
|
console.log(res.data);
|
|
// rec_result.value = res.data.text.reduce((total: any, cur: any) => total + `<p>${cur}</p>`);
|
|
// rec_result.value = res.data.text.reduce((total: any, cur: any) => total + `<p>${cur}</p>`);
|
|
- recArr.value.splice(0);
|
|
|
|
- let tmp_text = res.data.labels;
|
|
|
|
- if (tmp_text.length == 0) {
|
|
|
|
- alert('未检测到结果!');
|
|
|
|
|
|
+ figureArr.value.splice(0);
|
|
|
|
+ tableArr.value.splice(0);
|
|
|
|
+ let tmp_labels = res.data.labels;
|
|
|
|
+ if (tmp_labels.length == 0) {
|
|
|
|
+ alert("no result!");
|
|
} else {
|
|
} else {
|
|
- for (let i = 0; i < tmp_text.length; i++) {
|
|
|
|
- recArr.value.push(tmp_text[i]);
|
|
|
|
|
|
+ let tmp_boxes = res.data.boxes;
|
|
|
|
+ const h_radio = img.height / img.naturalHeight;
|
|
|
|
+ const w_radio = img.width / img.naturalWidth;
|
|
|
|
+
|
|
|
|
+ for (let i = 0; i < tmp_labels.length; i++) {
|
|
|
|
+ let left = w_radio * tmp_boxes[i][0];
|
|
|
|
+ let top = h_radio * tmp_boxes[i][1];
|
|
|
|
+ let width = w_radio * (tmp_boxes[i][2] - tmp_boxes[i][0]);
|
|
|
|
+ let height = h_radio * (tmp_boxes[i][3] - tmp_boxes[i][1]);
|
|
|
|
+ const rect: iRect = { left, top, width, height };
|
|
|
|
+ if (tmp_labels[i] == "Figure") {
|
|
|
|
+ figureArr.value.push("图片" + String(figureArr.value.length + 1));
|
|
|
|
+ figure_rects.push(rect);
|
|
|
|
+ } else if (tmp_labels[i] == "Table_0" || tmp_labels[i] == "Table_std") {
|
|
|
|
+ tableArr.value.push("表格" + String(tableArr.value.length + 1));
|
|
|
|
+ table_rects.push(rect);
|
|
|
|
+ }
|
|
|
|
+ CreateRect(fa_canvas, i, left, top, width, height, false);
|
|
}
|
|
}
|
|
- }
|
|
|
|
- let tmp_boxes = res.data.boxes;
|
|
|
|
- // fa_canvas = new fabric.Canvas(canvas.value);
|
|
|
|
- const h_radio = img.height / img.naturalHeight;
|
|
|
|
- const w_radio = img.width / img.naturalWidth;
|
|
|
|
- for (let i = 0; i < tmp_boxes.length; i++) {
|
|
|
|
- let left = w_radio * tmp_boxes[i][0];
|
|
|
|
- let top = h_radio * tmp_boxes[i][1];
|
|
|
|
- let width = w_radio * (tmp_boxes[i][2] - tmp_boxes[i][0]);
|
|
|
|
- let height = h_radio * (tmp_boxes[i][3] - tmp_boxes[i][1]);
|
|
|
|
- const rect: iRect = { left, top, width, height };
|
|
|
|
- rects.push(rect);
|
|
|
|
- CreateRect(fa_canvas, i, left, top, width, height, false);
|
|
|
|
|
|
+ // if (figureArr.value.length == 0)
|
|
|
|
+ // figureArr.value.push("无");
|
|
|
|
+ // if (tableArr.value.length == 0)
|
|
|
|
+ // tableArr.value.push("无");
|
|
}
|
|
}
|
|
predictTime.value = res.data.cost;
|
|
predictTime.value = res.data.cost;
|
|
loading.value = !loading.value;
|
|
loading.value = !loading.value;
|
|
@@ -387,7 +407,6 @@ const submitBug = async () => {
|
|
return;
|
|
return;
|
|
}
|
|
}
|
|
|
|
|
|
-
|
|
|
|
SubmitBug(bugId.value).then(res => {
|
|
SubmitBug(bugId.value).then(res => {
|
|
console.log(res.code, res.data)
|
|
console.log(res.code, res.data)
|
|
}).catch(function (err) {
|
|
}).catch(function (err) {
|
|
@@ -396,8 +415,23 @@ const submitBug = async () => {
|
|
});
|
|
});
|
|
};
|
|
};
|
|
|
|
|
|
-async function handleClick(index: any, item: any) {
|
|
|
|
- selectedItem.value = index;
|
|
|
|
|
|
+async function figureHandleClick(index: any, item: any, rects: any) {
|
|
|
|
+ figureSelectedItem.value = index;
|
|
|
|
+ tableSelectedItem.value = -1;
|
|
|
|
+ let objects = fa_canvas.getObjects();
|
|
|
|
+ for (let i = 0; i < objects.length; i++) {
|
|
|
|
+ if (objects[i].name === 'high') {
|
|
|
|
+ // 找到名为 rectName 的矩形元素,执行删除操作等
|
|
|
|
+ fa_canvas.remove(objects[i]);
|
|
|
|
+ break;
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+ CreateRect(fa_canvas, index, rects[index].left, rects[index].top, rects[index].width, rects[index].height, true);
|
|
|
|
+}
|
|
|
|
+
|
|
|
|
+async function tableHandleClick(index: any, item: any, rects: any) {
|
|
|
|
+ tableSelectedItem.value = index;
|
|
|
|
+ figureSelectedItem.value = -1;
|
|
let objects = fa_canvas.getObjects();
|
|
let objects = fa_canvas.getObjects();
|
|
for (let i = 0; i < objects.length; i++) {
|
|
for (let i = 0; i < objects.length; i++) {
|
|
if (objects[i].name === 'high') {
|
|
if (objects[i].name === 'high') {
|