Commit 416813c8 authored by Matteo's avatar Matteo
Browse files

update

parent b9bc6ead
PerformanceResults.xlsx PerformanceResults.xlsx
README.md README.md
.DS_Store .DS_Store
.vscode .vscode
\ No newline at end of file build/
bin/
\ No newline at end of file
...@@ -5,3 +5,5 @@ ...@@ -5,3 +5,5 @@
bin/ bin/
build/ build/
log.txt log.txt
venv/
__pycache__/
\ No newline at end of file
...@@ -9,15 +9,10 @@ LINK_DIRECTORIES(/usr/local/lib) ...@@ -9,15 +9,10 @@ LINK_DIRECTORIES(/usr/local/lib)
add_library(analyser_lib add_library(analyser_lib
src/lib/colors.h src/lib/colors.h
src/lib/Irregularity.cpp
src/lib/IrregularityFile.cpp
src/lib/Irregularity.h
src/lib/parser.cpp src/lib/parser.cpp
src/lib/parser.h src/lib/parser.h
src/lib/time.cpp src/lib/time.cpp
src/lib/time.h src/lib/time.h
src/lib/validation.cpp
src/lib/validation.h
) )
FIND_PACKAGE(OpenCV REQUIRED) FIND_PACKAGE(OpenCV REQUIRED)
......
FROM ubuntu:22.04 FROM matteospanio/opencv:latest
LABEL maintainer="Matteo Spanio" LABEL maintainer="Matteo Spanio"
...@@ -6,16 +6,10 @@ WORKDIR /app ...@@ -6,16 +6,10 @@ WORKDIR /app
COPY . ./ COPY . ./
RUN apt update && apt install libboost-program-options-dev git build-essential cmake g++ wget unzip python3 python3-pip libgtk-3-dev libavcodec-dev libavformat-dev libswscale-dev libv4l-dev libjpeg-dev libpng-dev python3-dev libavdevice-dev libdc1394-dev libgstreamer-opencv1.0-0 libavutil-dev ffmpeg -y RUN bash build.sh
RUN mkdir opencv_source && cd ./opencv_source && wget -O opencv.zip https://github.com/opencv/opencv/archive/4.5.4.zip && wget -O opencv_contrib.zip https://github.com/opencv/opencv_contrib/archive/4.5.4.zip && unzip opencv.zip && unzip opencv_contrib.zip && mkdir -p build && cd ./build && cmake -D OPENCV_GENERATE_PKGCONFIG=YES -D WITH_FFMPEG=ON -D WITH_V4L=ON -D WITH_PNG=ON -D WITH_GSTREAMER=ON -D BUILD_opencv_video=ON -D BUILD_opencv_videoio=ON -D OPENCV_ENABLE_NONFREE=ON -DOPENCV_EXTRA_MODULES_PATH=../opencv_contrib-4.5.4/modules ../opencv-4.5.4 && make -j4 && make install && cd /app RUN pip install --no-cache-dir -r requirements.txt
RUN git clone https://github.com/nlohmann/json.git VOLUME [ "/data" ]
RUN cd ./json && mkdir build && cd ./build && cmake .. && make && make install && cd /app CMD [ "python3", "server.py" ]
\ No newline at end of file
RUN rm -r opencv_source json
RUN cd ./build && cmake .. && make && cd /app
VOLUME [ "/data" ]
\ No newline at end of file
{ {
"WorkingPath": "/home/matteo/Scrivania/Projects/workflow/data", "WorkingPath": "/home/matteo/Scrivania/Projects/workflow/data",
"FilesName": "BERIO052.mov", "FilesName": "BERIO100.mov",
"Brands": true, "Brands": true,
"Speed": 7.5, "Speed": 7.5,
"TapeThresholdPercentual": 80, "TapeThresholdPercentual": 80,
......
appdirs==1.4.4
audioread==3.0.0
certifi==2022.12.7
cffi==1.15.1
charset-normalizer==3.1.0
decorator==5.1.1
grpcio==1.53.0
grpcio-tools==1.53.0
idna==3.4
joblib==1.2.0
lazy_loader==0.2
librosa==0.10.0.post2
llvmlite==0.39.1
markdown-it-py==2.2.0
mdurl==0.1.2
mpai-cae-arp==0.3.2
msgpack==1.0.5
numba==0.56.4
numpy==1.23.3
packaging==23.1
pooch==1.6.0
protobuf==4.22.3
pycparser==2.21
pydantic==1.10.7
Pygments==2.15.0
PyYAML==6.0
requests==2.28.2
rich==13.3.4
scikit-learn==1.2.2
scipy==1.10.1
soundfile==0.12.1
soxr==0.3.5
threadpoolctl==3.1.0
typing_extensions==4.5.0
urllib3==1.26.15
import os import os
import subprocess
from concurrent import futures from concurrent import futures
from typing import Any, Callable from typing import Any, Callable
import grpc import grpc
...@@ -6,7 +7,6 @@ from grpc import StatusCode ...@@ -6,7 +7,6 @@ from grpc import StatusCode
from rich.console import Console from rich.console import Console
from mpai_cae_arp.files import File, FileType from mpai_cae_arp.files import File, FileType
from mpai_cae_arp.types.irregularity import IrregularityFile, Source
from mpai_cae_arp.network import arp_pb2_grpc as arp_pb2_grpc from mpai_cae_arp.network import arp_pb2_grpc as arp_pb2_grpc
from mpai_cae_arp.network.arp_pb2 import ( from mpai_cae_arp.network.arp_pb2 import (
JobRequest, JobRequest,
...@@ -79,44 +79,48 @@ class VideoAnalyserServicer(arp_pb2_grpc.AIMServicer): ...@@ -79,44 +79,48 @@ class VideoAnalyserServicer(arp_pb2_grpc.AIMServicer):
files_name: str = request.files_name files_name: str = request.files_name
index: int = request.index index: int = request.index
video_src = os.path.join(working_dir, "PreservationAudioVisualFile", f"{files_name}.mov")
temp_dir = os.path.join(working_dir, "temp", files_name) working_dir = os.path.abspath(working_dir)
audio_irreg_1 = os.path.join(temp_dir, "AudioAnalyser_IrregularityFileOutput_1.json")
video_irreg_1 = os.path.join(temp_dir, "VideoAnalyser_IrregularityFileOutput_1.json")
video_irreg_2 = os.path.join(temp_dir, "VideoAnalyser_IrregularityFileOutput_2.json")
response, _ = try_or_error_response(
context=context,
func=os.makedirs,
args=[temp_dir],
on_success_message="Folders created successfully",
on_error_message="Unable to create temporary directory, output path already exists",
on_error_status=StatusCode.ALREADY_EXISTS,
)
yield response
try: prog = [
File(audio_irreg_1, FileType.JSON).write_content(irreg1.to_json()) 'bin/video_analyser',
context.set_code(StatusCode.OK) '--working-path', working_dir,
yield JobResponse(status="success", message="Irregularity file 1 saved to disk") '--files-name', files_name,
except: '--brands', 'true',
yield error_response(context, StatusCode.INTERNAL, "Failed to save irregularity file 1") '--speed', '7.5'
]
process = subprocess.run(prog, stdout=subprocess.PIPE, stderr=subprocess.PIPE, check=True)
File(audio_irreg_2, FileType.JSON).write_content(irreg2.to_json())
yield JobResponse(status="success", message="Irregularity file 2 created") console.print(process.stderr)
for line in process.stdout:
message = line.decode('utf-8').strip()
console.log(message)
yield JobResponse(status="success", message=message)
def serve(console): def serve(console):
server = grpc.server(futures.ThreadPoolExecutor(max_workers=10)) server = grpc.server(futures.ThreadPoolExecutor(max_workers=10))
arp_pb2_grpc.add_AIMServicer_to_server(VideoAnalyserServicer(console), server) arp_pb2_grpc.add_AIMServicer_to_server(VideoAnalyserServicer(console), server)
server.add_insecure_port('[::]:50051') server.add_insecure_port('[::]:50052')
server.start() server.start()
server.wait_for_termination() server.wait_for_termination()
if __name__ == '__main__': if __name__ == '__main__':
console = Console() console = Console()
console.print('Server started at localhost:50051 :satellite:') console.print('Server started at localhost:50052 :satellite:')
serve(console) serve(console)
# working_dir = os.path.abspath('../data')
# prog = [
# 'bin/video_analyser',
# '--working-path', working_dir,
# '--files-name', 'BERIO100.mov',
# '--brands', 'true',
# '--speed', '7.5'
# ]
# process = subprocess.run(prog, check=True)
This diff is collapsed.
[tool.poetry]
name = "server"
version = "0.1.0"
description = ""
authors = ["Matteo <spartacus990@gmail.com>"]
readme = "README.md"
[tool.poetry.dependencies]
python = "^3.10"
mpai-cae-arp = "^0.3.2"
grpcio-tools = "^1.53.0"
[build-system]
requires = ["poetry-core"]
build-backend = "poetry.core.masonry.api"
#include "Irregularity.h"
Irregularity::Irregularity()
{
}
Irregularity Irregularity::fromJSON(json irregularityJSON)
{
Irregularity irregularity;
return irregularity;
}
json Irregularity::toJSON()
{
json irregularityJSON;
return irregularityJSON;
}
\ No newline at end of file
#include <nlohmann/json.hpp>
using json = nlohmann::json;
#ifndef IRREGULARITY_H
#define IRREGULARITY_H
class Irregularity
{
public:
Irregularity();
static Irregularity fromJSON(json irregularityJSON);
json toJSON();
};
#endif // IRREGULARITY_H
\ No newline at end of file
#include "IrregularityFile.h"
IrregularityFile::IrregularityFile(/* args */)
{
}
IrregularityFile::~IrregularityFile()
{
}
#ifndef IRREGULARITYFILE_H
#define IRREGULARITYFILE_H
class IrregularityFile
{
private:
/* data */
public:
IrregularityFile(/* args */);
~IrregularityFile();
};
#endif // IRREGULARITYFILE_H
\ No newline at end of file
#include <iostream>
#include <fstream>
#include "validation.h"
#include "colors.h"
using namespace std;
namespace fs = std::filesystem;
int checkJSON(fs::path irregularityFileInputPath, float speed, int tapeThresholdPercentual, int capstanThresholdPercentual) {
// Input JSON check
ifstream iJSON(irregularityFileInputPath);
if (iJSON.fail()) {
cerr << RED << BOLD << "config.json error!" << END << endl << RED << irregularityFileInputPath.string() << " cannot be found or opened." << END << endl;
return -1;
}
if (speed != 7.5 && speed != 15) {
cerr << RED << BOLD << "config.json error!" << END << endl << RED << "Speed parameter must be 7.5 or 15 ips." << END << endl;
return -1;
}
if (tapeThresholdPercentual < 0 || tapeThresholdPercentual > 100) {
cerr << RED << BOLD << "config.json error!" << END << endl << RED << "TapeThresholdPercentual parameter must be a percentage value." << END << endl;
return -1;
}
if (capstanThresholdPercentual < 0 || capstanThresholdPercentual > 100) {
cerr << RED << BOLD << "config.json error!" << END << endl << RED << "CapstanThresholdPercentual parameter must be a percentage value." << END << endl;
return -1;
}
return 0;
}
\ No newline at end of file
#include <stdlib.h>
#include <filesystem>
int checkJSON(std::filesystem::path irregularityFileInputPath);
\ No newline at end of file
...@@ -165,6 +165,13 @@ bool getArguments(int argc, char** argv) { ...@@ -165,6 +165,13 @@ bool getArguments(int argc, char** argv) {
return false; return false;
} }
po::notify(vm); po::notify(vm);
// Access the stored options
config.workingPath = fs::path(vm["working-path"].as<string>());
config.filesName = vm["files-name"].as<string>();
config.brands = vm["brands"].as<bool>();
config.speed = vm["speed"].as<float>();
} catch (po::invalid_command_line_syntax& e) { } catch (po::invalid_command_line_syntax& e) {
cerr << RED << BOLD << "The command line syntax is invalid: " << END << RED << e.what() << END << endl; cerr << RED << BOLD << "The command line syntax is invalid: " << END << RED << e.what() << END << endl;
return false; return false;
...@@ -352,11 +359,7 @@ bool findProcessingAreas() { ...@@ -352,11 +359,7 @@ bool findProcessingAreas() {
} }
}; };
ofstream outputFile; saveFile(fs::path("./" + fileName + ".json"), autoJSON.dump(4), false);
string outputFileName = "/Users/nadir/Documents/MPAI-CAE/AreaJSONs/Auto/" + fileName + ".json";
outputFile.open(outputFileName);
outputFile << autoJSON << endl;
outputFile.close();
/*********************************************************************************************/ /*********************************************************************************************/
/************************************* CAPSTAN DETECTION *************************************/ /************************************* CAPSTAN DETECTION *************************************/
...@@ -999,13 +1002,13 @@ int main(int argc, char** argv) { ...@@ -999,13 +1002,13 @@ int main(int argc, char** argv) {
/*********************************************************************************************/ /*********************************************************************************************/
fs::path outputFile1Name = outputPath / "VideoAnalyser_IrregularityFileOutput1.json"; fs::path outputFile1Name = outputPath / "VideoAnalyser_IrregularityFileOutput1.json";
saveFile(outputFile1Name, irregularityFileOutput1, false); saveFile(outputFile1Name, irregularityFileOutput1.dump(4), false);
// Irregularities to extract for the AudioAnalyser and to the TapeIrregularityClassifier // Irregularities to extract for the AudioAnalyser and to the TapeIrregularityClassifier
extractIrregularityImagesForAudio(outputPath, videoPath, irregularityFileInput, irregularityFileOutput2); extractIrregularityImagesForAudio(outputPath, videoPath, irregularityFileInput, irregularityFileOutput2);
fs::path outputFile2Name = outputPath / "VideoAnalyser_IrregularityFileOutput2.json"; fs::path outputFile2Name = outputPath / "VideoAnalyser_IrregularityFileOutput2.json";
saveFile(outputFile2Name, irregularityFileOutput2, false); saveFile(outputFile2Name, irregularityFileOutput2.dump(4), false);
return 0; return 0;
} }
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment