diff --git a/CMakeLists.txt b/CMakeLists.txt index fcb839851787fe71d23ce2accd58bc3e4693f70f..c9cdfc2c2bb53ca1bb761d2db174e7590b00437b 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -43,6 +43,7 @@ option(WITH_SWIG_PY "Compile PaddlePaddle with py PaddlePaddle prediction api" $ option(ON_TRAVIS "Running test on travis-ci or not." OFF) option(ON_COVERALLS "Generating code coverage data on coveralls or not." OFF) option(COVERALLS_UPLOAD "Uploading the generated coveralls json." ON) +option(USE_OPENCV "Compile PaddlePaddle with opencv" OFF) if(NOT CMAKE_BUILD_TYPE) set(CMAKE_BUILD_TYPE "RelWithDebInfo" CACHE STRING diff --git a/plugin/opencv/CMakeLists.txt b/plugin/opencv/CMakeLists.txt index bc0a6e635475bec67cbcf2b08c75ef3e72631a03..7a6b22c89929a587018c6db3b24de5b9a76d4cc8 100644 --- a/plugin/opencv/CMakeLists.txt +++ b/plugin/opencv/CMakeLists.txt @@ -42,3 +42,6 @@ add_library(DeJpeg SHARED ${DEJPEG_SOURCES}) target_compile_options(DeJpeg BEFORE PRIVATE ${BUILD_PRIVATE_FLAGS}) target_link_libraries(DeJpeg ${DEJPEG_LINKER_LIBS}) set_target_properties(DeJpeg PROPERTIES PREFIX "") + +add_style_check_target(DeJpeg ${DEJPEG_SOURCES}) +add_style_check_target(DeJpeg ${DEJPEG_HEADER}) diff --git a/plugin/opencv/DataTransformer.cpp b/plugin/opencv/DataTransformer.cpp index d9e8883443c7db49057f77d4eb4641122266b324..dd123639f4f64766714edaf4fc3498949a4ce73f 100644 --- a/plugin/opencv/DataTransformer.cpp +++ b/plugin/opencv/DataTransformer.cpp @@ -51,7 +51,7 @@ DataTransformer::DataTransformer(int threadNum, } numThreads_ = threadNum; - syncThreadPool_.reset(new SyncThreadPool(numThreads_, false)); + syncThreadPool_.reset(new paddle::SyncThreadPool(numThreads_, false)); } void DataTransformer::loadMean(float* values) { @@ -66,7 +66,7 @@ void DataTransformer::loadMean(float* values) { void DataTransformer::startFetching(const char* src, const int size, float* trg) { - vector imbuf(src, src + size); + std::vector imbuf(src, src + size); int cvFlag = (isColor_ ? CV_LOAD_IMAGE_COLOR : CV_LOAD_IMAGE_GRAYSCALE); cv::Mat im = cv::imdecode(cv::Mat(imbuf), cvFlag); if (!im.data) { @@ -83,7 +83,7 @@ int DataTransformer::Rand(int min, int max) { return dist(rng); } -void DataTransformer::transform(Mat& cvImgOri, float* target) { +void DataTransformer::transform(cv::Mat& cvImgOri, float* target) { const int imgChannels = cvImgOri.channels(); const int imgHeight = cvImgOri.rows; const int imgWidth = cvImgOri.cols; @@ -152,7 +152,9 @@ void DataTransformer::transform(Mat& cvImgOri, float* target) { } // target: BGR } -void DataTransformer::start(vector& data, int* datalen, int* labels) { +void DataTransformer::start(std::vector& data, + int* datalen, + int* labels) { auto job = [&](int tid, int numThreads) { for (size_t i = tid; i < data.size(); i += numThreads) { DataTypePtr ret = prefetchFree_.dequeue(); diff --git a/plugin/opencv/DataTransformer.h b/plugin/opencv/DataTransformer.h index 52abab928b0514ea37964443c0d17d8efc6d9ad2..603cea30596bc2e12a2b817cb45c45cc42890ee7 100644 --- a/plugin/opencv/DataTransformer.h +++ b/plugin/opencv/DataTransformer.h @@ -12,6 +12,9 @@ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License. */ +#ifndef DATATRANSFORMER_H_ +#define DATATRANSFORMER_H_ + #include #include #include @@ -21,9 +24,6 @@ limitations under the License. */ #include "paddle/utils/Thread.h" -using namespace cv; -using namespace paddle; - /** * This is an image processing module with OpenCV, such as * resizing, scaling, mirroring, substracting the image mean... @@ -57,7 +57,7 @@ public: * @param data Data containing the image string to be transformed. * @param label The label of input image. */ - void start(vector& data, int* datalen, int* labels); + void start(std::vector& data, int* datalen, int* labels); /** * @brief Applies the transformation on one image Mat. @@ -65,7 +65,7 @@ public: * @param img The input img to be transformed. * @param target target is used to save the transformed data. */ - void transform(Mat& img, float* target); + void transform(cv::Mat& img, float* target); /** * @brief Decode the image string, then calls transform() function. @@ -114,8 +114,9 @@ private: typedef std::pair DataType; typedef std::shared_ptr DataTypePtr; std::vector prefetch_; - std::unique_ptr syncThreadPool_; - BlockingQueue prefetchFree_; - BlockingQueue prefetchFull_; - + std::unique_ptr syncThreadPool_; + paddle::BlockingQueue prefetchFree_; + paddle::BlockingQueue prefetchFull_; }; // class DataTransformer + +#endif // DATATRANSFORMER_H_ diff --git a/plugin/opencv/PyDecodejpeg.cpp b/plugin/opencv/PyDecodejpeg.cpp index 66054302f881bbf6e4b06a26780b70da8f2d806b..a32e6430e193a533023c1a7084d6f6c88345f8a4 100644 --- a/plugin/opencv/PyDecodejpeg.cpp +++ b/plugin/opencv/PyDecodejpeg.cpp @@ -23,8 +23,6 @@ limitations under the License. */ #include "DataTransformer.h" -using namespace boost::python; - /** * DecodeJpeg is an image processing API for interfacing Python and C++ * code DataTransformer, which used OpenCV and multi-threads to accelerate @@ -83,7 +81,7 @@ public: * It's type is numpy.array with int32. */ void start(boost::python::list& pysrc, PyObject* pydlen, PyObject* pylabel) { - vector data; + std::vector data; int num = len(pysrc); for (int t = 0; t < num; ++t) { char* src = boost::python::extract(pysrc[t]); @@ -169,8 +167,9 @@ static void initPython() { */ BOOST_PYTHON_MODULE(DeJpeg) { initPython(); - class_("DecodeJpeg", - init()) + boost::python::class_( + "DecodeJpeg", + boost::python::init()) .def("start", &DecodeJpeg::start) .def("get", &DecodeJpeg::get); };