mirror of
https://github.com/pjreddie/darknet.git
synced 2023-08-10 21:13:14 +03:00
.NET/C# support integration
Add logic for .NET/C# integration (DllImport)
This commit is contained in:
@ -22,6 +22,51 @@ extern "C" {
|
|||||||
|
|
||||||
#define FRAMES 3
|
#define FRAMES 3
|
||||||
|
|
||||||
|
int max_objects() { return C_SHARP_MAX_OBJECTS; }
|
||||||
|
|
||||||
|
static Detector* detector;
|
||||||
|
//static std::unique_ptr<Detector> detector;
|
||||||
|
|
||||||
|
int init(const char *configurationFilename, const char *weightsFilename, int gpu) {
|
||||||
|
std::string configurationFilenameString;
|
||||||
|
configurationFilenameString = configurationFilename;
|
||||||
|
std::string weightsFilenameString;
|
||||||
|
weightsFilenameString = weightsFilename;
|
||||||
|
|
||||||
|
detector = new Detector(configurationFilenameString, weightsFilenameString, gpu);
|
||||||
|
return 1;
|
||||||
|
}
|
||||||
|
|
||||||
|
int detect_image(const char *filename, bbox_t_container &container) {
|
||||||
|
std::string filenameString;
|
||||||
|
filenameString = filename;
|
||||||
|
|
||||||
|
std::vector<bbox_t> detection = detector->detect(filenameString);
|
||||||
|
for (size_t i = 0; i < detection.size() && i < C_SHARP_MAX_OBJECTS; ++i)
|
||||||
|
container.candidates[i] = detection[i];
|
||||||
|
return detection.size();
|
||||||
|
}
|
||||||
|
|
||||||
|
int detect_image2(const uint8_t* data, const size_t data_length, bbox_t_container &container) {
|
||||||
|
#ifdef OPENCV
|
||||||
|
std::vector<char> vdata(data, data + data_length);
|
||||||
|
cv::Mat image = imdecode(cv::Mat(vdata), 1);
|
||||||
|
|
||||||
|
std::vector<bbox_t> detection = detector->detect(image);
|
||||||
|
for (size_t i = 0; i < detection.size() && i < C_SHARP_MAX_OBJECTS; ++i)
|
||||||
|
container.candidates[i] = detection[i];
|
||||||
|
return detection.size();
|
||||||
|
#else
|
||||||
|
return -1;
|
||||||
|
#endif // OPENCV
|
||||||
|
}
|
||||||
|
|
||||||
|
int dispose() {
|
||||||
|
detector->~Detector();
|
||||||
|
//detector.reset();
|
||||||
|
return 1;
|
||||||
|
}
|
||||||
|
|
||||||
#ifdef GPU
|
#ifdef GPU
|
||||||
void check_cuda(cudaError_t status) {
|
void check_cuda(cudaError_t status) {
|
||||||
if (status != cudaSuccess) {
|
if (status != cudaSuccess) {
|
||||||
|
@ -28,6 +28,11 @@ struct image_t {
|
|||||||
float *data; // pointer to the image data
|
float *data; // pointer to the image data
|
||||||
};
|
};
|
||||||
|
|
||||||
|
#define C_SHARP_MAX_OBJECTS 1000
|
||||||
|
struct bbox_t_container {
|
||||||
|
bbox_t candidates[C_SHARP_MAX_OBJECTS];
|
||||||
|
};
|
||||||
|
|
||||||
#ifdef __cplusplus
|
#ifdef __cplusplus
|
||||||
#include <memory>
|
#include <memory>
|
||||||
#include <vector>
|
#include <vector>
|
||||||
@ -40,6 +45,12 @@ struct image_t {
|
|||||||
#include "opencv2/imgproc/imgproc_c.h" // C
|
#include "opencv2/imgproc/imgproc_c.h" // C
|
||||||
#endif // OPENCV
|
#endif // OPENCV
|
||||||
|
|
||||||
|
extern "C" __declspec(dllexport) int max_objects();
|
||||||
|
extern "C" __declspec(dllexport) int init(const char *configurationFilename, const char *weightsFilename, int gpu);
|
||||||
|
extern "C" __declspec(dllexport) int detect_image(const char *filename, bbox_t_container &container);
|
||||||
|
extern "C" __declspec(dllexport) int detect_image2(const uint8_t* data, const size_t data_length, bbox_t_container &container);
|
||||||
|
extern "C" __declspec(dllexport) int dispose();
|
||||||
|
|
||||||
class Detector {
|
class Detector {
|
||||||
std::shared_ptr<void> detector_gpu_ptr;
|
std::shared_ptr<void> detector_gpu_ptr;
|
||||||
std::deque<std::vector<bbox_t>> prev_bbox_vec_deque;
|
std::deque<std::vector<bbox_t>> prev_bbox_vec_deque;
|
||||||
|
Reference in New Issue
Block a user