Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Opencv4 #1

Open
wants to merge 4 commits into
base: master
Choose a base branch
from
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
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
darknet_ros/yolo_network_config/cfg/yolov4-tiny_dehumid.cfg
50 changes: 31 additions & 19 deletions darknet_ros/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@ project(darknet_ros)
set(CMAKE_CXX_FLAGS "-std=c++11 ${CMAKE_CXX_FLAGS}")
set(CMAKE_C_FLAGS "-Wall -Wno-unused-result -Wno-unknown-pragmas -Wno-unused-variable -Wfatal-errors -fPIC ${CMAKE_C_FLAGS}")
set(CMAKE_EXPORT_COMPILE_COMMANDS ON)
find_package(PkgConfig REQUIRED)
pkg_check_modules(gtk+ REQUIRED gtk+-3.0)

# Define path of darknet folder here.
find_path(DARKNET_PATH
Expand All @@ -23,12 +25,13 @@ if (CUDA_FOUND)
CUDA_NVCC_FLAGS
${CUDA_NVCC_FLAGS};
-O3
-gencode arch=compute_30,code=sm_30
-gencode arch=compute_35,code=sm_35
-gencode arch=compute_50,code=[sm_50,compute_50]
-gencode arch=compute_52,code=[sm_52,compute_52]
-gencode arch=compute_61,code=sm_61
-gencode arch=compute_62,code=sm_62
#-gencode arch=compute_30,code=sm_30
#-gencode arch=compute_35,code=sm_35
#-gencode arch=compute_50,code=[sm_50,compute_50]
#-gencode arch=compute_52,code=[sm_52,compute_52]
#-gencode arch=compute_61,code=sm_61
#-gencode arch=compute_62,code=sm_62
-gencode arch=compute_86,code=[sm_86,compute_86]
)
add_definitions(-DGPU)
else()
Expand Down Expand Up @@ -90,7 +93,8 @@ include_directories(
)

set(PROJECT_LIB_FILES
src/YoloObjectDetector.cpp src/image_interface.c
src/YoloObjectDetector.cpp
src/image_interface.cpp
)

set(DARKNET_CORE_FILES
Expand Down Expand Up @@ -228,20 +232,20 @@ install(DIRECTORY config launch yolo_network_config

# Download yolov2-tiny.weights
set(PATH "${CMAKE_CURRENT_SOURCE_DIR}/yolo_network_config/weights")
set(FILE "${PATH}/yolov2-tiny.weights")
message(STATUS "Checking and downloading yolov2-tiny.weights if needed ...")
if (NOT EXISTS "${FILE}")
message(STATUS "... file does not exist. Downloading now ...")
execute_process(COMMAND wget -q https://github.com/leggedrobotics/darknet_ros/releases/download/1.1.4/yolov2-tiny.weights -P ${PATH})
endif()
#set(FILE "${PATH}/yolov2-tiny.weights")
#message(STATUS "Checking and downloading yolov2-tiny.weights if needed ...")
#if (NOT EXISTS "${FILE}")
# message(STATUS "... file does not exist. Downloading now ...")
# execute_process(COMMAND wget -q https://github.com/leggedrobotics/darknet_ros/releases/download/1.1.4/yolov2-tiny.weights -P ${PATH})
#endif()

# Download yolov3.weights
set(FILE "${PATH}/yolov3.weights")
message(STATUS "Checking and downloading yolov3.weights if needed ...")
if (NOT EXISTS "${FILE}")
message(STATUS "... file does not exist. Downloading now ...")
execute_process(COMMAND wget -q https://github.com/leggedrobotics/darknet_ros/releases/download/1.1.4/yolov3.weights -P ${PATH})
endif()
#set(FILE "${PATH}/yolov3.weights")
#message(STATUS "Checking and downloading yolov3.weights if needed ...")
#if (NOT EXISTS "${FILE}")
# message(STATUS "... file does not exist. Downloading now ...")
# execute_process(COMMAND wget -q https://github.com/leggedrobotics/darknet_ros/releases/download/1.1.4/yolov3.weights -P ${PATH})
#endif()

# Download yolov4.weights
set(FILE "${PATH}/yolov4.weights")
Expand All @@ -251,6 +255,14 @@ if (NOT EXISTS "${FILE}")
execute_process(COMMAND wget -q https://github.com/AlexeyAB/darknet/releases/download/darknet_yolo_v3_optimal/yolov4.weights -P ${PATH})
endif()

# Download yolov4-tiny.weights
set(FILE "${PATH}/yolov4-tiny.weights")
message(STATUS "Checking and downloading yolov4-tiny.weights if needed ...")
if (NOT EXISTS "${FILE}")
message(STATUS "... file does not exist. Downloading now ...")
execute_process(COMMAND wget -q https://github.com/AlexeyAB/darknet/releases/download/darknet_yolo_v4_pre/yolov4-tiny.weights -P ${PATH})
endif()

#############
## Testing ##
#############
Expand Down
2 changes: 1 addition & 1 deletion darknet_ros/config/ros.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,6 @@ publishers:

image_view:

enable_opencv: true
enable_opencv: false
wait_key_delay: 1
enable_console_output: true
90 changes: 90 additions & 0 deletions darknet_ros/config/yolov4-tiny.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,90 @@
yolo_model:

config_file:
name: yolov4-tiny.cfg
weight_file:
name: yolov4-tiny.weights
threshold:
value: 0.3
detection_classes:
names:
- person
- bicycle
- car
- motorbike
- aeroplane
- bus
- train
- truck
- boat
- traffic light
- fire hydrant
- stop sign
- parking meter
- bench
- bird
- cat
- dog
- horse
- sheep
- cow
- elephant
- bear
- zebra
- giraffe
- backpack
- umbrella
- handbag
- tie
- suitcase
- frisbee
- skis
- snowboard
- sports ball
- kite
- baseball bat
- baseball glove
- skateboard
- surfboard
- tennis racket
- bottle
- wine glass
- cup
- fork
- knife
- spoon
- bowl
- banana
- apple
- sandwich
- orange
- broccoli
- carrot
- hot dog
- pizza
- donut
- cake
- chair
- sofa
- pottedplant
- bed
- diningtable
- toilet
- tvmonitor
- laptop
- mouse
- remote
- keyboard
- cell phone
- microwave
- oven
- toaster
- sink
- refrigerator
- book
- clock
- vase
- scissors
- teddy bear
- hair drier
- toothbrush
12 changes: 12 additions & 0 deletions darknet_ros/config/yolov4-tiny_dehumid.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
yolo_model:

config_file:
name: yolov4-tiny_dehumid.cfg
weight_file:
name: yolov4-tiny_dehumid_final2.weights
threshold:
value: 0.8
detection_classes:
names:
- pass
- no_cover
31 changes: 24 additions & 7 deletions darknet_ros/include/darknet_ros/YoloObjectDetector.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -51,16 +51,23 @@ extern "C" {
#include <sys/time.h>
#include "box.h"
#include "cost_layer.h"
#include "darknet_ros/image_interface.h"
#include "detection_layer.h"
#include "network.h"
#include "parser.h"
#include "region_layer.h"
#include "utils.h"

#include "image_opencv.h"
#include "image.h"
#include "darknet.h"

#include "darknet_ros/image_interface.hpp"
}

extern "C" void ipl_into_image(IplImage* src, image im);
extern "C" image ipl_to_image(IplImage* src);
//extern "C" void ipl_into_image(IplImage* src, image im);
//extern "C" image ipl_to_image(IplImage* src);
extern "C" cv::Mat image_to_mat(image im);
extern "C" image mat_to_image(cv::Mat m);
// extern "C" void show_image_cv(image p, const char* name, IplImage* disp);

namespace darknet_ros {
Expand All @@ -71,10 +78,15 @@ typedef struct {
int num, Class;
} RosBox_;

// typedef struct {
// IplImage* image;
// std_msgs::Header header;
// } IplImageWithHeader_;

typedef struct {
IplImage* image;
cv::Mat image;
std_msgs::Header header;
} IplImageWithHeader_;
} CvMatWithHeader_;

class YoloObjectDetector {
public:
Expand Down Expand Up @@ -176,7 +188,8 @@ class YoloObjectDetector {
image buffLetter_[3];
int buffId_[3];
int buffIndex_ = 0;
IplImage* ipl_;
//IplImage* ipl_;
cv::Mat disp_;
float fps_ = 0;
float demoThresh_ = 0;
float demoHier_ = .5;
Expand Down Expand Up @@ -234,15 +247,19 @@ class YoloObjectDetector {
void setupNetwork(char* cfgfile, char* weightfile, char* datafile, float thresh, char** names, int classes, int delay, char* prefix,
int avg_frames, float hier, int w, int h, int frames, int fullscreen);

image** load_alphabet_with_file(char* datafile);

void yolo();

IplImageWithHeader_ getIplImageWithHeader();
//IplImageWithHeader_ getIplImageWithHeader();
CvMatWithHeader_ getCvMatWithHeader();

bool getImageStatus(void);

bool isNodeRunning(void);

void* publishInThread();
void generate_image_cp(image p, cv::Mat& disp);
};

} /* namespace darknet_ros*/
19 changes: 0 additions & 19 deletions darknet_ros/include/darknet_ros/image_interface.h

This file was deleted.

23 changes: 23 additions & 0 deletions darknet_ros/include/darknet_ros/image_interface.hpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
/*
* image_interface.h
*
* Created on: Dec 19, 2016
* Author: Marko Bjelonic
* Institute: ETH Zurich, Robotic Systems Lab
*/

#ifndef IMAGE_INTERFACE_HPP
#define IMAGE_INTERFACE_HPP

#include "opencv2/highgui/highgui_c.h"
#include "opencv2/imgproc/imgproc_c.h"
#include "opencv2/core/version.hpp"

#include "image.h"
//#include "opencv2/core/types_c.h"

static float get_pixel(image m, int x, int y, int c);
//image** load_alphabet_with_file(char* datafile); //Moved to YoloObejctDetector.cpp
void generate_image(image p, cv::Mat& disp);

#endif
2 changes: 1 addition & 1 deletion darknet_ros/launch/yolo_v3.launch
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@

<!-- Use YOLOv3 -->
<arg name="network_param_file" default="$(find darknet_ros)/config/yolov3.yaml"/>
<arg name="image" default="camera/rgb/image_raw" />
<arg name="image" default="usb_cam/image_raw" />


<!-- Include main launch file -->
Expand Down
16 changes: 16 additions & 0 deletions darknet_ros/launch/yolo_v4-tiny.launch
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
<?xml version="1.0" encoding="utf-8"?>

<launch>

<!-- Use YOLOv3 -->
<arg name="network_param_file" default="$(find darknet_ros)/config/yolov4-tiny.yaml"/>
<arg name="image" default="usb_cam/image_raw" />


<!-- Include main launch file -->
<include file="$(find darknet_ros)/launch/darknet_ros.launch">
<arg name="network_param_file" value="$(arg network_param_file)"/>
<arg name="image" value="$(arg image)" />
</include>

</launch>
2 changes: 1 addition & 1 deletion darknet_ros/launch/yolo_v4.launch
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@

<!-- Use YOLOv3 -->
<arg name="network_param_file" default="$(find darknet_ros)/config/yolov4.yaml"/>
<arg name="image" default="camera/rgb/image_raw" />
<arg name="image" default="usb_cam/image_raw" />


<!-- Include main launch file -->
Expand Down
Loading