Estiliza pagina de upload externo - responsiva (novo47)
This commit is contained in:
1 parent
05cd7b9c79
commit
d7892c6b64
10 files changed
+1625
-1
No files matched your search
@@ -0,0 +1,51 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
class DocumentProcessor {
|
||||||
|
private $pythonScript;
|
||||||
|
private $pythonPath;
|
||||||
|
|
||||||
|
public function __construct() {
|
||||||
|
$this->pythonScript = __DIR__ . '/document_detector.py';
|
||||||
|
$this->pythonPath = 'python'; // ou 'python3' dependendo do sistema
|
||||||
|
|
||||||
|
if (!file_exists($this->pythonScript)) {
|
||||||
|
throw new Exception('Script Python não encontrado');
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public function processDocument(string $inputPath, string $outputPath): array {
|
||||||
|
if (!file_exists($inputPath)) {
|
||||||
|
throw new Exception('Arquivo de entrada não encontrado');
|
||||||
|
}
|
||||||
|
|
||||||
|
// Escapa argumentos para segurança
|
||||||
|
$inputPath = escapeshellarg($inputPath);
|
||||||
|
$outputPath = escapeshellarg($outputPath);
|
||||||
|
|
||||||
|
// Executa script Python
|
||||||
|
$command = sprintf('%s %s %s %s 2>&1',
|
||||||
|
$this->pythonPath,
|
||||||
|
escapeshellarg($this->pythonScript),
|
||||||
|
$inputPath,
|
||||||
|
$outputPath
|
||||||
|
);
|
||||||
|
|
||||||
|
$result = shell_exec($command);
|
||||||
|
|
||||||
|
if ($result === null) {
|
||||||
|
throw new Exception('Falha ao executar o script Python');
|
||||||
|
}
|
||||||
|
|
||||||
|
$response = json_decode($result, true);
|
||||||
|
|
||||||
|
if (!$response || !isset($response['success'])) {
|
||||||
|
throw new Exception('Resposta inválida do script Python: ' . $result);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!$response['success']) {
|
||||||
|
throw new Exception('Falha no processamento: ' . ($response['message'] ?? 'Erro desconhecido'));
|
||||||
|
}
|
||||||
|
|
||||||
|
return $response;
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,97 @@
|
|||||||
|
import cv2
|
||||||
|
import numpy as np
|
||||||
|
import sys
|
||||||
|
import json
|
||||||
|
from pathlib import Path
|
||||||
|
|
||||||
|
def order_points(pts):
|
||||||
|
rect = np.zeros((4, 2), dtype="float32")
|
||||||
|
s = pts.sum(axis=1)
|
||||||
|
rect[0] = pts[np.argmin(s)]
|
||||||
|
rect[2] = pts[np.argmax(s)]
|
||||||
|
diff = np.diff(pts, axis=1)
|
||||||
|
rect[1] = pts[np.argmin(diff)]
|
||||||
|
rect[3] = pts[np.argmax(diff)]
|
||||||
|
return rect
|
||||||
|
|
||||||
|
def process_document(image_path, output_path):
|
||||||
|
try:
|
||||||
|
# Carrega e verifica a imagem
|
||||||
|
image = cv2.imread(str(image_path))
|
||||||
|
if image is None:
|
||||||
|
raise Exception("Não foi possível carregar a imagem")
|
||||||
|
|
||||||
|
original = image.copy()
|
||||||
|
|
||||||
|
# Pré-processamento
|
||||||
|
gray = cv2.cvtColor(image, cv2.COLOR_BGR2GRAY)
|
||||||
|
blurred = cv2.GaussianBlur(gray, (5, 5), 0)
|
||||||
|
edges = cv2.Canny(blurred, 50, 150)
|
||||||
|
|
||||||
|
# Encontra contornos
|
||||||
|
contours, _ = cv2.findContours(edges, cv2.RETR_EXTERNAL, cv2.CHAIN_APPROX_SIMPLE)
|
||||||
|
if not contours:
|
||||||
|
raise Exception("Nenhum contorno encontrado")
|
||||||
|
|
||||||
|
# Ordena contornos por área
|
||||||
|
contours = sorted(contours, key=cv2.contourArea, reverse=True)
|
||||||
|
doc_corners = None
|
||||||
|
|
||||||
|
# Procura o documento
|
||||||
|
for contour in contours:
|
||||||
|
peri = cv2.arcLength(contour, True)
|
||||||
|
approx = cv2.approxPolyDP(contour, 0.02 * peri, True)
|
||||||
|
if len(approx) == 4:
|
||||||
|
doc_corners = approx
|
||||||
|
break
|
||||||
|
|
||||||
|
if doc_corners is None:
|
||||||
|
raise Exception("Documento não encontrado")
|
||||||
|
|
||||||
|
# Processa cantos e aplica transformação
|
||||||
|
doc_corners = doc_corners.reshape(4, 2)
|
||||||
|
ordered_corners = order_points(doc_corners)
|
||||||
|
|
||||||
|
(tl, tr, br, bl) = ordered_corners
|
||||||
|
widthA = np.linalg.norm(br - bl)
|
||||||
|
widthB = np.linalg.norm(tr - tl)
|
||||||
|
maxWidth = max(int(widthA), int(widthB))
|
||||||
|
|
||||||
|
heightA = np.linalg.norm(tr - br)
|
||||||
|
heightB = np.linalg.norm(tl - bl)
|
||||||
|
maxHeight = max(int(heightA), int(heightB))
|
||||||
|
|
||||||
|
dst = np.array([
|
||||||
|
[0, 0],
|
||||||
|
[maxWidth - 1, 0],
|
||||||
|
[maxWidth - 1, maxHeight - 1],
|
||||||
|
[0, maxHeight - 1]
|
||||||
|
], dtype="float32")
|
||||||
|
|
||||||
|
# Aplica transformação perspectiva
|
||||||
|
matrix = cv2.getPerspectiveTransform(ordered_corners, dst)
|
||||||
|
warped = cv2.warpPerspective(original, matrix, (maxWidth, maxHeight))
|
||||||
|
|
||||||
|
# Salva resultado
|
||||||
|
cv2.imwrite(str(output_path), warped)
|
||||||
|
|
||||||
|
return {
|
||||||
|
"success": True,
|
||||||
|
"message": "Processamento concluído com sucesso",
|
||||||
|
"width": maxWidth,
|
||||||
|
"height": maxHeight
|
||||||
|
}
|
||||||
|
|
||||||
|
except Exception as e:
|
||||||
|
return {
|
||||||
|
"success": False,
|
||||||
|
"message": str(e)
|
||||||
|
}
|
||||||
|
|
||||||
|
if __name__ == "__main__":
|
||||||
|
if len(sys.argv) != 3:
|
||||||
|
print(json.dumps({"success": False, "message": "Argumentos inválidos"}))
|
||||||
|
sys.exit(1)
|
||||||
|
|
||||||
|
result = process_document(Path(sys.argv[1]), Path(sys.argv[2]))
|
||||||
|
print(json.dumps(result))
|
||||||
@@ -0,0 +1,85 @@
|
|||||||
|
<?php
|
||||||
|
if (!isset($_SESSION['user_id'])) {
|
||||||
|
header("Location: login.php");
|
||||||
|
exit();
|
||||||
|
}
|
||||||
|
|
||||||
|
// Conectar ao banco de dados
|
||||||
|
$mysqli = new mysqli("10.15.0.42", "root", "34641747", "valida");
|
||||||
|
|
||||||
|
if ($mysqli->connect_error) {
|
||||||
|
die("Connection failed: " . $mysqli->connect_error);
|
||||||
|
}
|
||||||
|
|
||||||
|
// Buscar histórico de documentos processados
|
||||||
|
$query = "SELECT pd.*, u.username FROM processed_documents pd
|
||||||
|
LEFT JOIN users u ON pd.user_id = u.id
|
||||||
|
ORDER BY pd.created_at DESC";
|
||||||
|
$result = $mysqli->query($query);
|
||||||
|
?>
|
||||||
|
|
||||||
|
<div class="container">
|
||||||
|
<h2>Histórico de Documentos Processados</h2>
|
||||||
|
|
||||||
|
<table class="data-table">
|
||||||
|
<thead>
|
||||||
|
<tr>
|
||||||
|
<th>Data/Hora</th>
|
||||||
|
<th>Usuário</th>
|
||||||
|
<th>Documento Original</th>
|
||||||
|
<th>Documento Processado</th>
|
||||||
|
<th>Ações</th>
|
||||||
|
</tr>
|
||||||
|
</thead>
|
||||||
|
<tbody>
|
||||||
|
<?php while ($row = $result->fetch_assoc()): ?>
|
||||||
|
<tr>
|
||||||
|
<td><?php echo date('d/m/Y H:i:s', strtotime($row['created_at'])); ?></td>
|
||||||
|
<td><?php echo htmlspecialchars($row['username']); ?></td>
|
||||||
|
<td>
|
||||||
|
<a href="<?php echo htmlspecialchars($row['original_path']); ?>" target="_blank">
|
||||||
|
Ver Original
|
||||||
|
</a>
|
||||||
|
</td>
|
||||||
|
<td>
|
||||||
|
<a href="<?php echo htmlspecialchars($row['processed_path']); ?>" target="_blank">
|
||||||
|
Ver Processado
|
||||||
|
</a>
|
||||||
|
</td>
|
||||||
|
<td>
|
||||||
|
<button onclick="deleteDocument(<?php echo $row['id']; ?>)" class="delete-btn">
|
||||||
|
Excluir
|
||||||
|
</button>
|
||||||
|
</td>
|
||||||
|
</tr>
|
||||||
|
<?php endwhile; ?>
|
||||||
|
</tbody>
|
||||||
|
</table>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<script>
|
||||||
|
function deleteDocument(id) {
|
||||||
|
if (confirm('Tem certeza que deseja excluir este documento?')) {
|
||||||
|
fetch('delete_document.php', {
|
||||||
|
method: 'POST',
|
||||||
|
headers: {
|
||||||
|
'Content-Type': 'application/json',
|
||||||
|
},
|
||||||
|
body: JSON.stringify({id: id})
|
||||||
|
})
|
||||||
|
.then(response => response.json())
|
||||||
|
.then(data => {
|
||||||
|
if (data.success) {
|
||||||
|
alert('Documento excluído com sucesso!');
|
||||||
|
location.reload();
|
||||||
|
} else {
|
||||||
|
alert('Erro ao excluir documento: ' + data.message);
|
||||||
|
}
|
||||||
|
})
|
||||||
|
.catch(error => {
|
||||||
|
console.error('Error:', error);
|
||||||
|
alert('Erro ao excluir documento');
|
||||||
|
});
|
||||||
|
}
|
||||||
|
}
|
||||||
|
</script>
|
||||||
File diff suppressed because it is too large.
Load diff
@@ -52,6 +52,10 @@ include 'top_menu.php';
|
|||||||
include 'clientes/edit_note.php';
|
include 'clientes/edit_note.php';
|
||||||
} elseif ($page == 'delete_note' && isset($_POST['id'])) {
|
} elseif ($page == 'delete_note' && isset($_POST['id'])) {
|
||||||
include 'clientes/delete_note.php';
|
include 'clientes/delete_note.php';
|
||||||
|
} elseif ($page == 'process_document') {
|
||||||
|
include 'process_document.php';
|
||||||
|
} elseif ($page == 'document_history') {
|
||||||
|
include 'document_history.php';
|
||||||
} else {
|
} else {
|
||||||
echo "<h2>Bem-vindo ao Sistema de Ferramentas</h2>";
|
echo "<h2>Bem-vindo ao Sistema de Ferramentas</h2>";
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -12,7 +12,7 @@ if (!isset($_SESSION['user_id'])) {
|
|||||||
<li>
|
<li>
|
||||||
<a href="javascript:void(0);" onclick="toggleSubmenu('submenu1')">Autenticador de Provas Digitais</a>
|
<a href="javascript:void(0);" onclick="toggleSubmenu('submenu1')">Autenticador de Provas Digitais</a>
|
||||||
<ul id="submenu1" class="submenu">
|
<ul id="submenu1" class="submenu">
|
||||||
<li><a href="index.php?page=upload">Upload de Arquivos</a></li>
|
<li><a href="/prova/upload_prova.php">Upload de Arquivos</a></li>
|
||||||
<li><a href="index.php?page=status">Ver Status</a></li>
|
<li><a href="index.php?page=status">Ver Status</a></li>
|
||||||
<li><a href="index.php?page=list_files">Lista de Arquivos Processados</a></li>
|
<li><a href="index.php?page=list_files">Lista de Arquivos Processados</a></li>
|
||||||
</ul>
|
</ul>
|
||||||
@@ -24,6 +24,13 @@ if (!isset($_SESSION['user_id'])) {
|
|||||||
<li><a href="index.php?page=list_clients">Listagem de Clientes</a></li>
|
<li><a href="index.php?page=list_clients">Listagem de Clientes</a></li>
|
||||||
</ul>
|
</ul>
|
||||||
</li>
|
</li>
|
||||||
|
<li>
|
||||||
|
<a href="javascript:void(0);" onclick="toggleSubmenu('submenu3')">Processamento de Documentos</a>
|
||||||
|
<ul id="submenu3" class="submenu">
|
||||||
|
<li><a href="index.php?page=process_document">Processar Documento</a></li>
|
||||||
|
<li><a href="index.php?page=document_history">Histórico</a></li>
|
||||||
|
</ul>
|
||||||
|
</li>
|
||||||
<!-- Adicione mais ferramentas aqui -->
|
<!-- Adicione mais ferramentas aqui -->
|
||||||
</ul>
|
</ul>
|
||||||
</div>
|
</div>
|
||||||
+16
@@ -0,0 +1,16 @@
|
|||||||
|
<?php
|
||||||
|
require_once 'DocumentProcessor.php';
|
||||||
|
|
||||||
|
try {
|
||||||
|
$processor = new DocumentProcessor();
|
||||||
|
$result = $processor->processDocument(
|
||||||
|
'caminho/para/imagem/entrada.jpg',
|
||||||
|
'caminho/para/imagem/saida.jpg'
|
||||||
|
);
|
||||||
|
|
||||||
|
echo "Processamento concluído com sucesso!\n";
|
||||||
|
echo "Dimensões do documento: {$result['width']}x{$result['height']} pixels\n";
|
||||||
|
|
||||||
|
} catch (Exception $e) {
|
||||||
|
echo "Erro: " . $e->getMessage() . "\n";
|
||||||
|
}
|
||||||
@@ -0,0 +1,75 @@
|
|||||||
|
<?php
|
||||||
|
require_once 'DocumentProcessor.php';
|
||||||
|
|
||||||
|
// Define diretórios
|
||||||
|
$upload_dir = __DIR__ . '/uploads/';
|
||||||
|
$processed_dir = $upload_dir . 'processed/';
|
||||||
|
|
||||||
|
// Garante que os diretórios existam
|
||||||
|
if (!file_exists($upload_dir)) {
|
||||||
|
mkdir($upload_dir, 0777, true);
|
||||||
|
}
|
||||||
|
if (!file_exists($processed_dir)) {
|
||||||
|
mkdir($processed_dir, 0777, true);
|
||||||
|
}
|
||||||
|
|
||||||
|
$response = ['success' => false, 'message' => '', 'file' => ''];
|
||||||
|
|
||||||
|
try {
|
||||||
|
// Verifica se recebeu um arquivo
|
||||||
|
if (!isset($_FILES['document'])) {
|
||||||
|
throw new Exception('Nenhum arquivo enviado');
|
||||||
|
}
|
||||||
|
|
||||||
|
$file = $_FILES['document'];
|
||||||
|
if ($file['error'] !== UPLOAD_ERR_OK) {
|
||||||
|
throw new Exception('Erro no upload: ' . $file['error']);
|
||||||
|
}
|
||||||
|
|
||||||
|
// Validação do tipo de arquivo
|
||||||
|
$allowed_types = ['image/jpeg', 'image/png'];
|
||||||
|
if (!in_array($file['type'], $allowed_types)) {
|
||||||
|
throw new Exception('Tipo de arquivo não permitido. Use JPG ou PNG.');
|
||||||
|
}
|
||||||
|
|
||||||
|
// Gera nomes únicos para os arquivos
|
||||||
|
$temp_name = uniqid() . '_' . basename($file['name']);
|
||||||
|
$upload_path = $upload_dir . $temp_name;
|
||||||
|
$output_path = $processed_dir . 'proc_' . $temp_name;
|
||||||
|
|
||||||
|
// Move o arquivo enviado
|
||||||
|
if (!move_uploaded_file($file['tmp_name'], $upload_path)) {
|
||||||
|
throw new Exception('Falha ao mover arquivo enviado');
|
||||||
|
}
|
||||||
|
|
||||||
|
// Processa o documento
|
||||||
|
$processor = new DocumentProcessor();
|
||||||
|
$result = $processor->processDocument($upload_path, $output_path);
|
||||||
|
|
||||||
|
// Prepara resposta de sucesso
|
||||||
|
$response = [
|
||||||
|
'success' => true,
|
||||||
|
'message' => 'Documento processado com sucesso',
|
||||||
|
'file' => 'uploads/processed/proc_' . $temp_name,
|
||||||
|
'original' => 'uploads/' . $temp_name
|
||||||
|
];
|
||||||
|
|
||||||
|
} catch (Exception $e) {
|
||||||
|
$response = [
|
||||||
|
'success' => false,
|
||||||
|
'message' => $e->getMessage()
|
||||||
|
];
|
||||||
|
|
||||||
|
// Limpa arquivos em caso de erro
|
||||||
|
if (isset($upload_path) && file_exists($upload_path)) {
|
||||||
|
unlink($upload_path);
|
||||||
|
}
|
||||||
|
if (isset($output_path) && file_exists($output_path)) {
|
||||||
|
unlink($output_path);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// Retorna resposta em JSON
|
||||||
|
header('Content-Type: application/json');
|
||||||
|
echo json_encode($response);
|
||||||
|
?>
|
||||||
@@ -209,3 +209,50 @@ textarea {
|
|||||||
#search-button:hover {
|
#search-button:hover {
|
||||||
background-color: #0056b3;
|
background-color: #0056b3;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/* Estilos para processamento de documentos */
|
||||||
|
.upload-form {
|
||||||
|
max-width: 600px;
|
||||||
|
margin: 20px auto;
|
||||||
|
padding: 20px;
|
||||||
|
background: #f5f5f5;
|
||||||
|
border-radius: 5px;
|
||||||
|
}
|
||||||
|
|
||||||
|
.result-preview {
|
||||||
|
margin-top: 30px;
|
||||||
|
}
|
||||||
|
|
||||||
|
.image-comparison {
|
||||||
|
display: flex;
|
||||||
|
justify-content: space-around;
|
||||||
|
margin-top: 20px;
|
||||||
|
flex-wrap: wrap;
|
||||||
|
}
|
||||||
|
|
||||||
|
.image-comparison img {
|
||||||
|
max-width: 45%;
|
||||||
|
height: auto;
|
||||||
|
margin: 10px;
|
||||||
|
border: 1px solid #ddd;
|
||||||
|
box-shadow: 0 0 5px rgba(0,0,0,0.2);
|
||||||
|
}
|
||||||
|
|
||||||
|
.alert {
|
||||||
|
padding: 15px;
|
||||||
|
margin-bottom: 20px;
|
||||||
|
border: 1px solid transparent;
|
||||||
|
border-radius: 4px;
|
||||||
|
}
|
||||||
|
|
||||||
|
.alert-success {
|
||||||
|
color: #155724;
|
||||||
|
background-color: #d4edda;
|
||||||
|
border-color: #c3e6cb;
|
||||||
|
}
|
||||||
|
|
||||||
|
.alert-error {
|
||||||
|
color: #721c24;
|
||||||
|
background-color: #f8d7da;
|
||||||
|
border-color: #f5c6cb;
|
||||||
|
}
|
||||||
+64
@@ -0,0 +1,64 @@
|
|||||||
|
<!DOCTYPE html>
|
||||||
|
<html lang="pt-BR">
|
||||||
|
<head>
|
||||||
|
<meta charset="UTF-8">
|
||||||
|
<title>Processador de Documentos</title>
|
||||||
|
<style>
|
||||||
|
.preview { max-width: 800px; margin: 20px 0; }
|
||||||
|
.preview img { max-width: 100%; }
|
||||||
|
#result { display: none; }
|
||||||
|
.error { color: red; }
|
||||||
|
</style>
|
||||||
|
</head>
|
||||||
|
<body>
|
||||||
|
<form id="uploadForm" enctype="multipart/form-data">
|
||||||
|
<input type="file" name="document" accept="image/jpeg,image/png" required>
|
||||||
|
<button type="submit">Processar Documento</button>
|
||||||
|
</form>
|
||||||
|
|
||||||
|
<div id="result">
|
||||||
|
<h3>Resultado do Processamento:</h3>
|
||||||
|
<div class="preview">
|
||||||
|
<h4>Documento Original:</h4>
|
||||||
|
<img id="originalImage" src="" alt="Original">
|
||||||
|
</div>
|
||||||
|
<div class="preview">
|
||||||
|
<h4>Documento Processado:</h4>
|
||||||
|
<img id="processedImage" src="" alt="Processado">
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<div id="error" class="error"></div>
|
||||||
|
|
||||||
|
<script>
|
||||||
|
document.getElementById('uploadForm').onsubmit = async (e) => {
|
||||||
|
e.preventDefault();
|
||||||
|
|
||||||
|
const formData = new FormData(e.target);
|
||||||
|
const resultDiv = document.getElementById('result');
|
||||||
|
const errorDiv = document.getElementById('error');
|
||||||
|
|
||||||
|
try {
|
||||||
|
const response = await fetch('process_document.php', {
|
||||||
|
method: 'POST',
|
||||||
|
body: formData
|
||||||
|
});
|
||||||
|
|
||||||
|
const result = await response.json();
|
||||||
|
|
||||||
|
if (result.success) {
|
||||||
|
document.getElementById('originalImage').src = result.original;
|
||||||
|
document.getElementById('processedImage').src = result.file;
|
||||||
|
resultDiv.style.display = 'block';
|
||||||
|
errorDiv.textContent = '';
|
||||||
|
} else {
|
||||||
|
throw new Error(result.message);
|
||||||
|
}
|
||||||
|
} catch (error) {
|
||||||
|
errorDiv.textContent = error.message;
|
||||||
|
resultDiv.style.display = 'none';
|
||||||
|
}
|
||||||
|
};
|
||||||
|
</script>
|
||||||
|
</body>
|
||||||
|
</html>
|
||||||
Reference in new issue
Block a user