Darknet: C++ port for this windows port

Created on 9 Feb 2017  路  15Comments  路  Source: AlexeyAB/darknet

First off, great effort in porting this code to windows development environment.

I would like to know if there is a c++ port for this code, I plan to use it on VS2015. There are c++ ports for the linux env : like this one : https://github.com/for-aiur/yolo_cpp .

What do you think ?

Most helpful comment

@bassamarshad

I added support to use Yolo v2 as C++ yolo_cpp_dll.dll-file: https://github.com/AlexeyAB/darknet#how-to-use-yolo-as-dll

  • You simple should build build\darknet\yolo_cpp_dll.sln to create yolo_cpp_dll.dll-file

  • And build simple C++-example which uses this yolo_cpp_dll.dll - open & build build\darknet\yolo_console_dll.sln


Class Detector has constructor and 3 detect()-functions:

  • std::vector<bbox_t> detect(std::string image_filename, float thresh = 0.2); - takes the image file name
  • std::vector<bbox_t> detect(image_t img, float thresh = 0.2); - takes already loaded image image_t
  • std::vector<bbox_t> detect(cv::Mat mat, float thresh = 0.2); - takes already loaded image of type cv::Mat by using OpenCV-function cv::imread(filename);
class Detector {
public:
    Detector(std::string cfg_filename, std::string weight_filename, int gpu_id = 0);
    ~Detector();

    std::vector<bbox_t> detect(std::string image_filename, float thresh = 0.2);
    std::vector<bbox_t> detect(image_t img, float thresh = 0.2);

#ifdef OPENCV
    std::vector<bbox_t> detect(cv::Mat mat, float thresh = 0.2);
#endif
};

console_yolo_dll

All 15 comments

@bassamarshad

I added support to use Yolo v2 as C++ yolo_cpp_dll.dll-file: https://github.com/AlexeyAB/darknet#how-to-use-yolo-as-dll

  • You simple should build build\darknet\yolo_cpp_dll.sln to create yolo_cpp_dll.dll-file

  • And build simple C++-example which uses this yolo_cpp_dll.dll - open & build build\darknet\yolo_console_dll.sln


Class Detector has constructor and 3 detect()-functions:

  • std::vector<bbox_t> detect(std::string image_filename, float thresh = 0.2); - takes the image file name
  • std::vector<bbox_t> detect(image_t img, float thresh = 0.2); - takes already loaded image image_t
  • std::vector<bbox_t> detect(cv::Mat mat, float thresh = 0.2); - takes already loaded image of type cv::Mat by using OpenCV-function cv::imread(filename);
class Detector {
public:
    Detector(std::string cfg_filename, std::string weight_filename, int gpu_id = 0);
    ~Detector();

    std::vector<bbox_t> detect(std::string image_filename, float thresh = 0.2);
    std::vector<bbox_t> detect(image_t img, float thresh = 0.2);

#ifdef OPENCV
    std::vector<bbox_t> detect(cv::Mat mat, float thresh = 0.2);
#endif
};

console_yolo_dll

@AlexeyAB Amazing! Highly appreciated.

@AlexeyAB

Thank you very very much.

@AlexeyAB

is it possible to use this DLL in other platforms such as .Net (VB.net)? because we can use .Net internal commands to draw rectangles or bounding boxes or similar.

@VanitarNordic
In general yes: https://msdn.microsoft.com/en-us/library/dt232c9t.aspx
But I don't know, is it possible to use class from DLL in VB.net.

@AlexeyAB

Suppose we have an unknown Windows machine and we want that our .exe file run as it runs in our system, then what prerequisite should be installed on the target machine?

@AlexeyAB

And also is it possible to draw a different color for each detected class object? for example green for class A, blue for Class B ... and so on. also printing the class name and its detection confidence number above bounding box (optional)

@VanitarNordic

Suppose we have an unknown Windows machine and we want that our .exe file run as it runs in our system, then what prerequisite should be installed on the target machine?

Requires:

  1. yolo_cpp_dll.dll

  2. Put all required dll-s (bottom): https://github.com/AlexeyAB/darknet#how-to-compile-custom

pthreadVC2.dll, pthreadGC2.dll from \3rdparty\dll\x64

cusolver64_80.dll, curand64_80.dll, cudart64_80.dll, cublas64_80.dll - 80 for CUDA 8.0 or your version, from C:\Program Files\NVIDIA GPU Computing Toolkit\CUDA\v8.0\bin

opencv_core249.dll, opencv_highgui249.dll and opencv_ffmpeg249_64.dll in C:\opencv_2.4.9\opencv\build\x64\vc12\bin or vc14\bin


To change color see this line where cv::Scalar is color: https://github.com/AlexeyAB/darknet/blob/a6cbaeecde40f91ddc3ea09aa26a03ab5bbf8ba8/src/yolo_console_dll.cpp#L17

int blue = (i.obj_id*123) % 255;
int green = (i.obj_id*321) % 255;
int red = (i.obj_id*25) % 255;
cv::rectangle(mat_img, cv::Rect(i.x, i.y, i.w, i.h), cv::Scalar(blue, green, red), 3);

To change color see this line where cv::Scalar is color: https://github.com/AlexeyAB/darknet/blob/a6cbaeecde40f91ddc3ea09aa26a03ab5bbf8ba8/src/yolo_console_dll.cpp#L17

Does this applies for all classes or can I apply a color for a Class, for example Green for Class0, Yellow for Class1 and ....

@VanitarNordic You can implement it: http://www.rubydoc.info/github/gonzedge/ruby-opencv/OpenCV/CvScalar

cv::Scalar color;

switch (obj_id) {
 case 0: color = cv::Scalar(0x0,0x80,0x0); break; // green
 case 1: color = cv::Scalar(0x0,0xff,0xff); break; // yellow

 default: color = cv::Scalar(0, 0, 0); 
}
cv::rectangle(mat_img, cv::Rect(i.x, i.y, i.w, i.h), color, 3);

@AlexeyAB

Which parameters reflect the "class name" and confidence?

@AlexeyAB could you show me how to get detected object number? I'm fail by using
int obj_num = result_vec.size;
and also the code of tracking, how to use another tracker.
Thank you in advance.

@sqyangg
int obj_num = result_vec.size();

What do you mean about "another tracking"?
You can change this function YOLODLL_API std::vector<bbox_t> Detector::tracking(std::vector<bbox_t> cur_bbox_vec, int const frames_story) in the file yolo_v2_class.cpp:
https://github.com/AlexeyAB/darknet/blob/master/src/yolo_v2_class.cpp#L220

@AlexeyAB Thank you very very much. That is what I want exactly.

Was this page helpful?
0 / 5 - 0 ratings

Related issues

Jacky3213 picture Jacky3213  路  3Comments

kebundsc picture kebundsc  路  3Comments

jasleen137 picture jasleen137  路  3Comments

shootingliu picture shootingliu  路  3Comments

Yumin-Sun-00 picture Yumin-Sun-00  路  3Comments