Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions src/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -98,10 +98,12 @@ set(OPENSHOT_CV_SOURCES
CVStabilization.cpp
ClipProcessingJobs.cpp
CVObjectDetection.cpp
CVObjectMask.cpp
TrackedObjectBBox.cpp
effects/Stabilizer.cpp
effects/Tracker.cpp
effects/ObjectDetection.cpp
effects/ObjectMask.cpp
effects/Outline.cpp
./sort_filter/sort.cpp
./sort_filter/Hungarian.cpp
Expand Down
38 changes: 33 additions & 5 deletions src/CVObjectDetection.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,13 @@

#include "CVObjectDetection.h"
#include "Exceptions.h"
#include "ZmqLogger.h"

#define int64 int64_t
#define uint64 uint64_t
#include <opencv2/core/ocl.hpp>
#undef uint64
#undef int64
#include "objdetectdata.pb.h"
#include <google/protobuf/util/time_util.h>

Expand Down Expand Up @@ -256,23 +262,45 @@ std::string CVObjectDetection::ValidateONNXModel(std::string modelPath)
}

void CVObjectDetection::setProcessingDevice(){
if(processingDevice == "GPU"){
const std::string requestedDevice = processingDevice;
if (processingDevice == "CPU") {
net.setPreferableBackend(cv::dnn::DNN_BACKEND_OPENCV);
net.setPreferableTarget(cv::dnn::DNN_TARGET_CPU);
ZmqLogger::Instance()->Log("Object Detection DNN device: requested CPU, selected CPU");
return;
}

if(processingDevice == "GPU" || processingDevice == "GPU_AUTO" || processingDevice == "GPU_CUDA"){
try {
const std::vector<cv::dnn::Target> targets = cv::dnn::getAvailableTargets(cv::dnn::DNN_BACKEND_CUDA);
if (std::find(targets.begin(), targets.end(), cv::dnn::DNN_TARGET_CUDA) != targets.end()) {
net.setPreferableBackend(cv::dnn::DNN_BACKEND_CUDA);
net.setPreferableTarget(cv::dnn::DNN_TARGET_CUDA);
ZmqLogger::Instance()->Log("Object Detection DNN device: requested " + requestedDevice + ", selected CUDA");
return;
}
} catch (const cv::Exception&) {
}
processingDevice = "CPU";
}

if(processingDevice == "CPU"){
net.setPreferableBackend(cv::dnn::DNN_BACKEND_OPENCV);
net.setPreferableTarget(cv::dnn::DNN_TARGET_CPU);
if(processingDevice == "GPU_OPENCL"){
try {
const std::vector<cv::dnn::Target> targets = cv::dnn::getAvailableTargets(cv::dnn::DNN_BACKEND_OPENCV);
if (std::find(targets.begin(), targets.end(), cv::dnn::DNN_TARGET_OPENCL) != targets.end()) {
cv::ocl::setUseOpenCL(true);
net.setPreferableBackend(cv::dnn::DNN_BACKEND_OPENCV);
net.setPreferableTarget(cv::dnn::DNN_TARGET_OPENCL);
ZmqLogger::Instance()->Log("Object Detection DNN device: requested " + requestedDevice + ", selected OpenCL");
return;
}
} catch (const cv::Exception&) {
}
}

processingDevice = "CPU";
net.setPreferableBackend(cv::dnn::DNN_BACKEND_OPENCV);
net.setPreferableTarget(cv::dnn::DNN_TARGET_CPU);
ZmqLogger::Instance()->Log("Object Detection DNN device: requested " + requestedDevice + ", selected CPU");
}

void CVObjectDetection::detectObjectsClip(openshot::Clip &video, size_t _start, size_t _end, bool process_interval)
Expand Down
Loading
Loading