将检测任务迁移python
This commit is contained in:
@@ -2,130 +2,121 @@ package com.ruoyi.video.utils;
|
||||
|
||||
import org.springframework.web.multipart.MultipartFile;
|
||||
|
||||
import java.io.*;
|
||||
import java.io.ByteArrayInputStream;
|
||||
import java.io.File;
|
||||
import java.io.FileInputStream;
|
||||
import java.io.IOException;
|
||||
import java.io.InputStream;
|
||||
|
||||
/**
|
||||
* File包装成MultipartFile
|
||||
* @Author: orange
|
||||
* @CreateTime: 2025-01-16
|
||||
* 自定义MultipartFile实现,用于文件上传
|
||||
*/
|
||||
public class CustomMultipartFile implements MultipartFile {
|
||||
// 定义一个File类型的变量file
|
||||
private final File file;
|
||||
// 定义一个String类型的变量contentType
|
||||
private final String name;
|
||||
private final String originalFilename;
|
||||
private final String contentType;
|
||||
|
||||
// 构造方法,传入一个File类型的变量file和一个String类型的变量contentType
|
||||
public CustomMultipartFile(File file, String contentType) {
|
||||
/**
|
||||
* 构造函数 - 从File创建
|
||||
*
|
||||
* @param file 文件
|
||||
* @param filename 文件名
|
||||
* @param contentType 内容类型
|
||||
*/
|
||||
public CustomMultipartFile(File file, String filename, String contentType) {
|
||||
this.file = file;
|
||||
this.name = filename;
|
||||
this.originalFilename = filename;
|
||||
this.contentType = contentType;
|
||||
}
|
||||
|
||||
// 获取文件名
|
||||
/**
|
||||
* 构造函数 - 从字节数组创建
|
||||
*
|
||||
* @param bytes 文件字节数组
|
||||
* @param filename 文件名
|
||||
* @param contentType 内容类型
|
||||
*/
|
||||
public CustomMultipartFile(byte[] bytes, String filename, String contentType) {
|
||||
this.file = null;
|
||||
this.name = filename;
|
||||
this.originalFilename = filename;
|
||||
this.contentType = contentType;
|
||||
}
|
||||
|
||||
/**
|
||||
* 构造函数 - 从File创建,指定Content-Type
|
||||
*
|
||||
* @param file 文件
|
||||
* @param contentType 内容类型
|
||||
*/
|
||||
public CustomMultipartFile(File file, String contentType) {
|
||||
this.file = file;
|
||||
this.name = file.getName();
|
||||
this.originalFilename = file.getName();
|
||||
this.contentType = contentType;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getName() {
|
||||
return this.file.getName();
|
||||
return name;
|
||||
}
|
||||
|
||||
// 获取原始文件名
|
||||
@Override
|
||||
public String getOriginalFilename() {
|
||||
return this.file.getName();
|
||||
return originalFilename;
|
||||
}
|
||||
|
||||
// 获取文件类型
|
||||
@Override
|
||||
public String getContentType() {
|
||||
return this.contentType;
|
||||
return contentType;
|
||||
}
|
||||
|
||||
// 判断文件是否为空
|
||||
@Override
|
||||
public boolean isEmpty() {
|
||||
return this.file.length() == 0L;
|
||||
return getSize() == 0;
|
||||
}
|
||||
|
||||
// 获取文件大小
|
||||
@Override
|
||||
public long getSize() {
|
||||
return this.file.length();
|
||||
if (file != null) {
|
||||
return file.length();
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
// 获取文件的字节数组
|
||||
@Override
|
||||
public byte[] getBytes() throws IOException {
|
||||
// 创建一个FileInputStream对象,传入file
|
||||
InputStream inputStream = new FileInputStream(this.file);
|
||||
|
||||
byte[] var2;
|
||||
try {
|
||||
// 读取所有字节数组
|
||||
var2 = inputStream.readAllBytes();
|
||||
} catch (Throwable var5) {
|
||||
try {
|
||||
// 关闭输入流
|
||||
inputStream.close();
|
||||
} catch (Throwable var4) {
|
||||
var5.addSuppressed(var4);
|
||||
if (file != null) {
|
||||
try (InputStream is = new FileInputStream(file)) {
|
||||
return is.readAllBytes();
|
||||
}
|
||||
|
||||
throw var5;
|
||||
}
|
||||
|
||||
// 关闭输入流
|
||||
inputStream.close();
|
||||
return var2;
|
||||
return new byte[0];
|
||||
}
|
||||
|
||||
// 获取文件的输入流
|
||||
@Override
|
||||
public InputStream getInputStream() throws IOException {
|
||||
return new FileInputStream(this.file);
|
||||
if (file != null) {
|
||||
return new FileInputStream(file);
|
||||
}
|
||||
return new ByteArrayInputStream(new byte[0]);
|
||||
}
|
||||
|
||||
// 将文件传输到指定的文件
|
||||
@Override
|
||||
public void transferTo(File dest) throws IOException, IllegalStateException {
|
||||
// 如果目标文件不存在,则创建
|
||||
if (!dest.exists()) {
|
||||
dest.createNewFile();
|
||||
}
|
||||
|
||||
// 创建一个FileInputStream对象,传入file
|
||||
InputStream inputStream = new FileInputStream(this.file);
|
||||
|
||||
try {
|
||||
// 创建一个FileOutputStream对象,传入dest
|
||||
OutputStream outputStream = new FileOutputStream(dest);
|
||||
|
||||
try {
|
||||
// 创建一个字节数组,大小为1024
|
||||
byte[] buffer = new byte[1024];
|
||||
|
||||
int bytesRead;
|
||||
// 循环读取文件,直到读取完毕
|
||||
while((bytesRead = inputStream.read(buffer)) != -1) {
|
||||
// 将读取的字节数组写入目标文件
|
||||
outputStream.write(buffer, 0, bytesRead);
|
||||
if (file != null) {
|
||||
try (FileInputStream fis = new FileInputStream(file)) {
|
||||
try (java.io.FileOutputStream fos = new java.io.FileOutputStream(dest)) {
|
||||
byte[] buffer = new byte[8192];
|
||||
int bytesRead;
|
||||
while ((bytesRead = fis.read(buffer)) != -1) {
|
||||
fos.write(buffer, 0, bytesRead);
|
||||
}
|
||||
}
|
||||
} catch (Throwable var8) {
|
||||
try {
|
||||
// 关闭输出流
|
||||
outputStream.close();
|
||||
} catch (Throwable var7) {
|
||||
var8.addSuppressed(var7);
|
||||
}
|
||||
|
||||
throw var8;
|
||||
}
|
||||
|
||||
// 关闭输出流
|
||||
outputStream.close();
|
||||
} catch (Throwable var9) {
|
||||
try {
|
||||
// 关闭输入流
|
||||
inputStream.close();
|
||||
} catch (Throwable var6) {
|
||||
var9.addSuppressed(var6);
|
||||
}
|
||||
|
||||
throw var9;
|
||||
}
|
||||
|
||||
// 关闭输入流
|
||||
inputStream.close();
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -11,11 +11,11 @@ public final class Overlay {
|
||||
|
||||
public static void draw(List<Detection> dets, Mat frame) {
|
||||
for (Detection d : dets) {
|
||||
Rect r = d.box();
|
||||
int bgr = d.colorBGR();
|
||||
Rect r = d.getRect();
|
||||
int bgr = d.getColorBGR();
|
||||
Scalar c = new Scalar(bgr & 0xFF, (bgr >> 8) & 0xFF, (bgr >> 16) & 0xFF, 0);
|
||||
rectangle(frame, r, c, 2, LINE_8, 0);
|
||||
String label = d.cls()+" "+String.format("%.2f", d.conf());
|
||||
String label = d.getLabel()+" "+String.format("%.2f", d.getConfidence());
|
||||
int[] baseline = new int[1];
|
||||
Size t = getTextSize(label, FONT_HERSHEY_SIMPLEX, 0.5, 1, baseline);
|
||||
int x = Math.max(0, r.x());
|
||||
|
||||
Reference in New Issue
Block a user