Skip to content
This repository has been archived by the owner on Aug 5, 2022. It is now read-only.

Get Intel Caffe working with OpenCV4 when building with CMake #240

Open
wants to merge 2 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
4 changes: 2 additions & 2 deletions include/caffe/layers/video_data_layer.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -39,11 +39,11 @@ OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
#define CAFFE_VIDEO_DATA_LAYER_HPP_

#ifdef USE_OPENCV
#if OPENCV_VERSION == 3
#if OPENCV_VERSION >= 3
#include <opencv2/videoio.hpp>
#else
#include <opencv2/opencv.hpp>
#endif // OPENCV_VERSION == 3
#endif // OPENCV_VERSION >= 3

#include <string>
#include <vector>
Expand Down
9 changes: 8 additions & 1 deletion src/caffe/layers/image_data_layer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,14 @@ OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.

#ifdef USE_OPENCV
#include <opencv2/core/core.hpp>

#if CV_VERSION_MAJOR == 4
#include <opencv2/imgproc.hpp>
#define CV_BGR2RGB cv::COLOR_BGR2RGB
#define CV_FILLED cv::FILLED
#else
#include <opencv2/imgproc/imgproc.hpp>
#endif

#include <fstream> // NOLINT(readability/streams)
#include <iostream> // NOLINT(readability/streams)
Expand Down Expand Up @@ -237,7 +244,7 @@ void ImageDataLayer<Dtype>::load_batch(Batch<Dtype>* batch) {
Blob<Dtype> tmp_data;
tmp_data.Reshape(top_shape);
tmp_data.set_cpu_data(prefetch_data + offset);
this->data_transformer_->Transform(cv_img, &tmp_data,
this->data_transformer_->Transform(cv_img, &tmp_data,
precalculated_rand_numbers);
}
#endif
Expand Down
5 changes: 5 additions & 0 deletions src/caffe/layers/video_data_layer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,11 @@ OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
#include "caffe/layers/video_data_layer.hpp"
#include "caffe/util/benchmark.hpp"

#if CV_VERSION_MAJOR == 4
#define CV_CAP_PROP_POS_FRAMES cv::CAP_PROP_POS_FRAMES
#define CV_CAP_PROP_FRAME_COUNT cv::CAP_PROP_FRAME_COUNT
#endif

namespace caffe {

template <typename Dtype>
Expand Down
21 changes: 14 additions & 7 deletions src/caffe/util/bbox_util.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,13 @@ OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
#include "boost/iterator/counting_iterator.hpp"

#include "caffe/util/bbox_util.hpp"
#ifdef USE_OPENCV
#if CV_VERSION_MAJOR == 4
#include <opencv2/videoio/videoio_c.h>
#define CV_FILLED cv::FILLED
#endif
#endif

#ifdef ENABLE_NMS_OPTIMIZATION
#include <immintrin.h>
#include "omp.h"
Expand Down Expand Up @@ -96,13 +103,13 @@ static inline float min(float a, float b) { return (a) < (b) ? (a) : (b); }
#define MASK_ELEM(x, y) \
((uint64_t*)((char*)mask_tbl + x * blocks * sizeof(uint64_t)) + y)

void cpu_nms_avx512_parallize_inner(int* __restrict keep_out,
int* __restrict num_out,
void cpu_nms_avx512_parallize_inner(int* __restrict keep_out,
int* __restrict num_out,
const float* __restrict x1,
const float* __restrict y1,
const float* __restrict x2,
const float* __restrict x2,
const float* __restrict y2,
int64_t boxes_num,
int64_t boxes_num,
float thresh_f)
{
const int blocks = DIVUP(boxes_num, 64);
Expand Down Expand Up @@ -179,7 +186,7 @@ void cpu_nms_avx512_parallize_inner(int* __restrict keep_out,

__m512 Sb_w = _mm512_sub_ps(x2_b, x1_b);
__m512 Sb_h = _mm512_sub_ps(y2_b, y1_b);

__m512 Sb = _mm512_mul_ps(Sb_w, Sb_h);

__m512 ovr = _mm512_add_ps(Sa, Sb);
Expand Down Expand Up @@ -1844,7 +1851,7 @@ void GetConfidenceScores(const Dtype* conf_data, const int num,
}
}
#ifdef _OPENMP
#pragma omp parallel for
#pragma omp parallel for
#endif
for (int i = 0; i < num; i++) {
// #pragma omp parallel
Expand Down Expand Up @@ -2185,7 +2192,7 @@ void GetPriorBBoxes(const Dtype* prior_data, const int num_priors,
}

vector<float> var(4, 0);

for (int i = 0; i < num_priors; ++i) {
for (int j = 0; j < 4; ++j) {
var.at(j) = (prior_data[(num_priors + i) * 4 + j]);
Expand Down
8 changes: 7 additions & 1 deletion src/caffe/util/im_transforms.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
#ifdef USE_OPENCV
#include <opencv2/highgui/highgui.hpp>

#if CV_VERSION_MAJOR == 3
#if CV_VERSION_MAJOR >= 3
#include <opencv2/imgcodecs/imgcodecs.hpp>
#define CV_GRAY2BGR cv::COLOR_GRAY2BGR
#define CV_BGR2GRAY cv::COLOR_BGR2GRAY
Expand All @@ -48,6 +48,12 @@ OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
#define CV_LOAD_IMAGE_COLOR cv::IMREAD_COLOR
#define CV_THRESH_BINARY_INV cv::THRESH_BINARY_INV
#define CV_THRESH_OTSU cv::THRESH_OTSU
#if CV_VERSION_MAJOR == 4
#define CV_BGR2HSV cv::COLOR_BGR2HSV
#define CV_BGR2Lab cv::COLOR_BGR2Lab
#define CV_BGR2HSV cv::COLOR_BGR2HSV
#define CV_HSV2BGR cv::COLOR_HSV2BGR
#endif
#endif
#endif // USE_OPENCV

Expand Down