Skip to content

Commit

Permalink
Added error message handling for ClipProcessingJob
Browse files Browse the repository at this point in the history
  • Loading branch information
BrennoCaldato committed Nov 1, 2020
1 parent df154c3 commit 3f63b2c
Show file tree
Hide file tree
Showing 7 changed files with 90 additions and 10 deletions.
26 changes: 24 additions & 2 deletions src/CVObjectDetection.cpp
Expand Up @@ -32,7 +32,6 @@

using namespace openshot;


CVObjectDetection::CVObjectDetection(std::string processInfoJson, ProcessingController &processingController)
: processingController(&processingController), processingDevice("CPU"){
SetJson(processInfoJson);
Expand All @@ -56,6 +55,10 @@ void CVObjectDetection::detectObjectsClip(openshot::Clip &video, size_t _start,

video.Open();

if(error){
return;
}

// Load names of classes
std::ifstream ifs(classesFile.c_str());
std::string line;
Expand Down Expand Up @@ -381,13 +384,32 @@ void CVObjectDetection::SetJsonValue(const Json::Value root) {
processingDevice = (root["processing_device"].asString());
}
if (!root["model_configuration"].isNull()){
modelConfiguration = (root["model_configuration"].asString());
modelConfiguration = (root["model_configuration"].asString());
std::ifstream infile(modelConfiguration);
if(!infile.good()){
processingController->SetError(true, "Incorrect path to model config file");
error = true;
}

}
if (!root["model_weights"].isNull()){
modelWeights= (root["model_weights"].asString());
std::ifstream infile(modelWeights);
if(!infile.good()){
processingController->SetError(true, "Incorrect path to model weight file");
error = true;
}

}
if (!root["classes_file"].isNull()){
classesFile = (root["classes_file"].asString());

std::ifstream infile(classesFile);
if(!infile.good()){
processingController->SetError(true, "Incorrect path to class name file");
error = true;
}

}
}

Expand Down
2 changes: 2 additions & 0 deletions src/CVObjectDetection.h
Expand Up @@ -91,6 +91,8 @@ namespace openshot
size_t start;
size_t end;

bool error = false;

/// Will handle a Thread safely comutication between ClipProcessingJobs and the processing effect classes
ProcessingController *processingController;

Expand Down
26 changes: 21 additions & 5 deletions src/CVTracker.cpp
Expand Up @@ -65,7 +65,6 @@ cv::Ptr<cv::Tracker> CVTracker::selectTracker(std::string trackerType){
void CVTracker::trackClip(openshot::Clip& video, size_t _start, size_t _end, bool process_interval){

video.Open();

if(!json_interval){
start = _start; end = _end;

Expand All @@ -79,7 +78,12 @@ void CVTracker::trackClip(openshot::Clip& video, size_t _start, size_t _end, boo
start = start + video.Start() * video.Reader()->info.fps.ToInt();
end = video.End() * video.Reader()->info.fps.ToInt();
}


if(error){
return;
}

processingController->SetError(false, "");
bool trackerInit = false;

size_t frame;
Expand Down Expand Up @@ -274,6 +278,7 @@ void CVTracker::SetJsonValue(const Json::Value root) {
if (!root["tracker_type"].isNull()){
trackerType = (root["tracker_type"].asString());
}

if (!root["bbox"].isNull()){
double x = root["bbox"]["x"].asDouble();
double y = root["bbox"]["y"].asDouble();
Expand All @@ -282,9 +287,20 @@ void CVTracker::SetJsonValue(const Json::Value root) {
cv::Rect2d prev_bbox(x,y,w,h);
bbox = prev_bbox;
}
if (!root["first_frame"].isNull()){
start = root["first_frame"].asInt64();
json_interval = true;
else{
processingController->SetError(true, "No initial bounding box selected");
error = true;
}

if(root.isMember("first_frame")){
if (!root["first_frame"].isNull()){
start = root["first_frame"].asInt64();
json_interval = true;
}
}
else{
processingController->SetError(true, "No first_frame");
error = true;
}
}

Expand Down
4 changes: 3 additions & 1 deletion src/CVTracker.h
Expand Up @@ -103,10 +103,12 @@ namespace openshot

/// Will handle a Thread safely comutication between ClipProcessingJobs and the processing effect classes
ProcessingController *processingController;

bool json_interval;
size_t start;
size_t end;

bool error = false;

// Initialize the tracker
bool initTracker(cv::Mat &frame, size_t frameId);
Expand Down
16 changes: 15 additions & 1 deletion src/ClipProcessingJobs.cpp
Expand Up @@ -5,7 +5,8 @@ ClipProcessingJobs::ClipProcessingJobs(std::string processingType, std::string p
processingType(processingType), processInfoJson(processInfoJson){
}

void ClipProcessingJobs::processClip(Clip& clip){
void ClipProcessingJobs::processClip(Clip& clip, std::string json){
processInfoJson = json;

// Process clip and save processed data
if(processingType == "Stabilizer"){
Expand Down Expand Up @@ -83,11 +84,13 @@ void ClipProcessingJobs::stabilizeClip(Clip& clip, ProcessingController& control
}
}

// Get processing progress while iterating on the clip
int ClipProcessingJobs::GetProgress(){

return (int)processingController.GetProgress();
}

// Check if processing finished
bool ClipProcessingJobs::IsDone(){

if(processingController.GetFinished()){
Expand All @@ -96,6 +99,17 @@ bool ClipProcessingJobs::IsDone(){
return processingController.GetFinished();
}

// stop preprocessing before finishing it
void ClipProcessingJobs::CancelProcessing(){
processingController.CancelProcessing();
}

// check if there is an error with the config
bool ClipProcessingJobs::GetError(){
return processingController.GetError();
}

// get the error message
std::string ClipProcessingJobs::GetErrorMessage(){
return processingController.GetErrorMessage();
}
5 changes: 4 additions & 1 deletion src/ClipProcessingJobs.h
Expand Up @@ -75,11 +75,14 @@ class ClipProcessingJobs{
// Constructor
ClipProcessingJobs(std::string processingType, std::string processInfoJson);
// Process clip accordingly to processingType
void processClip(Clip& clip);
void processClip(Clip& clip, std::string json);

// Thread related variables and methods
int GetProgress();
bool IsDone();
void CancelProcessing();
bool GetError();
std::string GetErrorMessage();


};
21 changes: 21 additions & 0 deletions src/ProcessingController.h
Expand Up @@ -41,10 +41,13 @@ class ProcessingController{
uint processingProgress;
bool processingFinished;
bool stopProcessing;
bool error = true;
std::string error_message;

std::mutex mtxProgress;
std::mutex mtxFinished;
std::mutex mtxStop;
std::mutex mtxerror;

public:

Expand Down Expand Up @@ -87,6 +90,24 @@ class ProcessingController{
return s;
}

void SetError(bool err, std::string message){
std::lock_guard<std::mutex> lck (mtxerror);
error = err;
error_message = message;
}

bool GetError(){
std::lock_guard<std::mutex> lck (mtxerror);
bool e = error;
return e;
}

std::string GetErrorMessage(){
std::lock_guard<std::mutex> lck (mtxerror);
std::string message = error_message;
return message;
}

};

#endif

0 comments on commit 3f63b2c

Please sign in to comment.