AlexeyAB / darknet

YOLOv4 / Scaled-YOLOv4 / YOLO - Neural Networks for Object Detection (Windows and Linux version of Darknet )
http://pjreddie.com/darknet/
Other
21.65k stars 7.96k forks source link

Darknet C++ API #3919

Open stephanecharette opened 5 years ago

stephanecharette commented 5 years ago

I don't know where to leave this, but in case it is useful I've written a C++ class to access libdarknet.so. I've published it using the MIT license so anyone can use it, even in commercial apps. At the very least, it might also be useful for people who want to use libdarknet.so but find the documentation lacking.

Both doc and source can be downloaded from here: https://www.ccoderun.ca/DarkHelp/api/Summary.html

AlexeyAB commented 5 years ago

@stephanecharette Hi, thanks

There is already C++ file that uses libdarknet.so: https://github.com/AlexeyAB/darknet/blob/master/src/yolo_console_dll.cpp

Just compile with LIBSO=1 in the Makefile and use ./uselib instead of ./darknet https://github.com/AlexeyAB/darknet#how-to-compile-on-linux

vinjn commented 5 years ago

Yes, I've also used darknet DLL in feature-viz project and dancing-gaga project.

LukeAI commented 4 years ago

is there any disadvantage to using the .so as opposed to directly integrating the raw code? maybe a small speed cost or something because the compiler can't integrate and optimise everything?

HanLiii commented 4 years ago

I don't know where to leave this, but in case it is useful I've written a C++ class to access libdarknet.so. I've published it using the MIT license so anyone can use it, even in commercial apps. At the very least, it might also be useful for people who want to use libdarknet.so but find the documentation lacking.

Both doc and source can be downloaded from here: https://www.ccoderun.ca/DarkHelp/api/Summary.html

Hi,i have downloaded darkhelp and generate the darkhelp.deb file.What more should i do to compile and run the codes you mentioned in darkhelp website:

include

int main() { const std::string config_file = "stone_barcodes_yolov3-tiny.cfg"; const std::string weights_file = "stone_barcodes_yolov3-tiny_final.weights"; const std::string names_file = "stone_barcodes.names";

// load the neural network (config, weights, and class names)
DarkHelp darkhelp(config_file, weights_file, names_file);

// run the neural network predictions on an image, and save the output
darkhelp.predict("barcode_7.jpg");
cv::Mat image = darkhelp.annotate();

// use standard OpenCV calls to write the annotated image to disk
cv::imwrite("output.jpg", image, {cv::IMWRITE_JPEG_QUALITY, 65});

return 0;

}

stephanecharette commented 4 years ago

Hi,i have downloaded darkhelp and generate the darkhelp.deb file.What more should i do to compile and run the codes you mentioned in darkhelp website:

If you generated the .deb file and installed it, then there is nothing more to do. Now you can use it in your C++ application. That code you quoted is an example showing how it can be used. Or you can run DarkHelp from the command line. Try running "DarkHelp" without any parameters, or "DarkHelp --help" to get the full list.

The command line parameters are explained here: https://www.ccoderun.ca/darkhelp/api/Parameters.html

HanLiii commented 4 years ago

Hi,i have downloaded darkhelp and generate the darkhelp.deb file.What more should i do to compile and run the codes you mentioned in darkhelp website:

If you generated the .deb file and installed it, then there is nothing more to do. Now you can use it in your C++ application. That code you quoted is an example showing how it can be used. Or you can run DarkHelp from the command line. Try running "DarkHelp" without any parameters, or "DarkHelp --help" to get the full list.

The command line parameters are explained here: https://www.ccoderun.ca/darkhelp/api/Parameters.h

Hi,i have downloaded darkhelp and generate the darkhelp.deb file.What more should i do to compile and run the codes you mentioned in darkhelp website:

If you generated the .deb file and installed it, then there is nothing more to do. Now you can use it in your C++ application. That code you quoted is an example showing how it can be used. Or you can run DarkHelp from the command line. Try running "DarkHelp" without any parameters, or "DarkHelp --help" to get the full list.

The command line parameters are explained here: https://www.ccoderun.ca/darkhelp/api/Parameters.html

Thanks.I want to use the predict and annotate function in my project,so i create a test.cpp file to have a test.I copied the code below in it and modified cfg and weights' path.Then i use command "g++ test.cpp" but it can't pass.Should i add something more to make it works?

stephanecharette commented 4 years ago

Thanks.I want to use the predict and annotate function in my project,so i create a test.cpp file to have a test.I copied the code below in it and modified cfg and weights' path.Then i use command "g++ test.cpp" but it can't pass.Should i add something more to make it works?

Yes, like any normal C or C++ application, you must ensure you link against the correct libraries. In this case, you need to link against OpenCV, libdarknet, and libdarkhelp.

How you do this depends on the tools you are using. It is unlikely you should be doing it by hand. You'll want to use something like CMake, or pkg-config, especially when it comes to OpenCV which is quite extensive.

To get an idea of the parameters you need to provide to g++, run pkg-config --libs --cflags opencv, in addition to -l for both libdarknet.so and libdarkhelp.so.

HanLiii commented 4 years ago

Thanks.I want to use the predict and annotate function in my project,so i create a test.cpp file to have a test.I copied the code below in it and modified cfg and weights' path.Then i use command "g++ test.cpp" but it can't pass.Should i add something more to make it works?

Yes, like any normal C or C++ application, you must ensure you link against the correct libraries. In this case, you need to link against OpenCV, libdarknet, and libdarkhelp.

How you do this depends on the tools you are using. It is unlikely you should be doing it by hand. You'll want to use something like CMake, or pkg-config, especially when it comes to OpenCV which is quite extensive.

To get an idea of the parameters you need to provide to g++, run pkg-config --libs --cflags opencv, in addition to -l for both libdarknet.so and libdarkhelp.so.

Great appreciation for your work and suggestion,i work it out!