Skip to content

Commit fe89a34

Browse files
committed
python wrapper basic functionality ready
1 parent e547049 commit fe89a34

File tree

6 files changed

+63
-8
lines changed

6 files changed

+63
-8
lines changed

.gitignore

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,3 +11,5 @@ bad.list
1111
Makefile
1212
CMakeCache.txt
1313
*.swp
14+
darknet
15+
darknet_cpp

app/darknet++/CMakeLists.txt

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,8 @@ include_directories(${CUDA_INCLUDE_DIRS})
66

77
find_package(PythonLibs 2.7 REQUIRED)
88
find_package(Boost COMPONENTS python REQUIRED)
9+
include_directories(${PYTHON_INCLUDE_DIRS})
10+
include_directories(${Boost_INCLUDE_DIR})
911

1012
add_executable(darknet_cpp darknet++.cpp)
1113
target_link_libraries(

yolo++/CMakeLists.txt

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -25,9 +25,9 @@ find_package(PythonLibs 2.7 REQUIRED)
2525
include_directories(${PYTHON_INCLUDE_DIRS})
2626
find_package(Boost COMPONENTS python REQUIRED)
2727
include_directories(${Boost_INCLUDE_DIR})
28-
add_library(greet_ext SHARED greet_ext.cpp)
29-
target_link_libraries(greet_ext ${Boost_LIBRARIES} ${MODULENAME})
30-
set_target_properties(greet_ext PROPERTIES PREFIX "")
28+
add_library(yolopy SHARED yolopy.cpp)
29+
target_link_libraries(yolopy ${Boost_LIBRARIES} ${MODULENAME})
30+
set_target_properties(yolopy PROPERTIES PREFIX "")
3131

3232

3333

yolo++/yolo.cpp

Lines changed: 34 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3,11 +3,41 @@
33

44
#include <opencv2/highgui/highgui.hpp>
55

6-
std::string greet(float val, std::string str)
6+
YoloPython::YoloPython(){
7+
yolo = new Yolo();
8+
yolo->setConfigFilePath("../../cfg/tiny-yolo-tayse.cfg");
9+
yolo->setDataFilePath("../../cfg/tayse.data");
10+
yolo->setWeightFilePath("/home/yildirim/Dropbox/tayse/models/tiny-yolo-tayse_16000.weights");
11+
yolo->setAlphabetPath("../../data/labels/");
12+
yolo->setNameListFile("../../data/tayse.names");
13+
yolo->setThreshold(0.16);
14+
}
15+
16+
void YoloPython::setThreshold(float val){
17+
yolo->setThreshold(val);
18+
}
19+
20+
int YoloPython::detect(std::string path) {
21+
cv::Mat img = cv::imread(path.c_str());
22+
cv::resize(img, img, cv::Size(412,412));
23+
yolo->detect(img, objects);
24+
return objects.size();
25+
}
26+
27+
float YoloPython::getComponent(int bb_idx, int component_idx)
728
{
8-
Yolo yolo;
9-
yolo.setThreshold(val);
10-
return std::to_string(yolo.getThreshold());
29+
if( bb_idx < 0 || bb_idx >= objects.size())
30+
return 0.0;
31+
32+
if( component_idx == 0 )
33+
return objects[bb_idx].bounding_box.x;
34+
if( component_idx == 1 )
35+
return objects[bb_idx].bounding_box.y;
36+
if( component_idx == 2 )
37+
return objects[bb_idx].bounding_box.width;
38+
if( component_idx == 3 )
39+
return objects[bb_idx].bounding_box.height;
40+
return 0.0f;
1141
}
1242

1343
Yolo::Yolo() : thresh(.24f),

yolo++/yolo.h

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,8 +13,9 @@
1313
#include <image.h>
1414

1515
#include <object.h>
16+
#include <opencv2/highgui/highgui.hpp>
1617

17-
std::string greet(float val, std::string path);
18+
#include <boost/python/numeric.hpp>
1819

1920
class Yolo {
2021
public:
@@ -59,5 +60,14 @@ class Yolo {
5960
Yolo(const Yolo& copy);
6061
};
6162

63+
struct YoloPython{
64+
YoloPython();
65+
void setThreshold(float val);
66+
int detect(std::string path);
67+
float getComponent(int bb_idx, int component_idx);
68+
Yolo* yolo;
69+
std::vector<DetectedObject> objects;
70+
};
71+
6272

6373
#endif //DARKNET_YOLO_H

yolo++/yolopy.cpp

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
#include "yolo.h"
2+
#include <boost/python.hpp>
3+
4+
BOOST_PYTHON_MODULE(yolopy)
5+
{
6+
using namespace boost::python;
7+
class_<YoloPython>("YoloPython")
8+
.def("set_thresh", &YoloPython::setThreshold)
9+
.def("comp", &YoloPython::getComponent)
10+
.def("detect", &YoloPython::detect);
11+
}

0 commit comments

Comments
 (0)