图像处理库(fbc_cv):源自OpenCV代码提取

在实际项目中会经常用到一些基本的图像处理操作,而且经常拿OpenCV进行结果对比,因此这里从OpenCV中提取了一些代码组织成fbc_cv库。项目fbc_cv所有的代码已放到GitHub中,地址为  https://github.com/fengbingchun/OpenCV_Test ,它不依赖任何第三方库,目前包含的算法有:resize, cvtColor, merge, split, remap, warpAffine, rotate, warpPerspective, dilate, erode, morphologyEx, threshold, transpose, flip, dft, idft,后面还会再增加一些。也会将一些算法改为CUDA实现,地址为:https://github.com/fengbingchun/CUDA_Test.  fbc_cv库对应对应的OpenCV版本为3.1。目前已添加的这些算法与OpenCV 3.1的结果完全一致

在编译OpenCV 3.1源码时有一些注意事项:

(1). 在用CMake编译时,关闭OpenCL, CUDA, OpenMP, TBB, SIMD选项;

(2). 调整源码中modules/core/include/opencv2/core/cvdef.h文件,将第167行改为: #if  0

(3). 调整源码中modules/core/include/opencv2/core/fast_math.hpp文件,使其cvFound/cvFloor/cvCeil/cvRound函数执行最后的判断条件。

fbc_cv库既支持在Windows7/10上vs2013编译,也支持在Linux上通过CMake编译,而且两个平台上的结果都与OpenCV 3.1是一致的

vs2013工程截图如下:

图像处理库(fbc_cv):源自OpenCV代码提取_第1张图片

Ubuntu 14.04上编译fbc_cv:

build.sh文件内容如下:

#! /bin/bash

build_mode=release
if [ $# == 1 ]; then
	build_mode=debug
fi
echo "build mode: ${build_mode}"

real_path=$(realpath $0)
dir_name=`dirname "${real_path}"`
echo "real_path: ${real_path}, dir_name: ${dir_name}"

data_dir="test_images"
if [ -d ${dir_name}/${data_dir} ]; then
	rm -rf ${dir_name}/${data_dir}
fi

ln -s ${dir_name}/./../../${data_dir} ${dir_name}

new_dir_name=${dir_name}/build
mkdir -p ${new_dir_name}
cd ${new_dir_name}
cmake .. -DBUILD_MODE=${build_mode}
make

cd -

CMakeLists.txt文件内容如下:

PROJECT(OpenCV_Test)
CMAKE_MINIMUM_REQUIRED(VERSION 3.0)

# support C++11
SET(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -std=c11")
SET(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=c++11")
# support C++14, when gcc version > 5.1, use -std=c++14 instead of c++1y
SET(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=c++1y")

IF (BUILD_MODE STREQUAL "debug")
	MESSAGE(STATUS "****** BUILD MODE: DEBUG ******")
	SET(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -g -Wall -O2")
	SET(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS}  -g -Wall -O2")
ELSE()
	MESSAGE(STATUS "====== BUILD MODE: REALSE ======")
	SET(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -Wall -O2")
	SET(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wall -O2")
ENDIF()

MESSAGE(STATUS "project source dir: ${PROJECT_SOURCE_DIR}")
SET(PATH_TEST_FILES ${PROJECT_SOURCE_DIR}/./../../demo/OpenCV_Test)
SET(PATH_SRC_FILES ${PROJECT_SOURCE_DIR}/./../../src/fbc_cv)
MESSAGE(STATUS "path src files: ${PATH_TEST_FILES}")

# head file search path
INCLUDE_DIRECTORIES(
	${PATH_TEST_FILES}
	${PATH_SRC_FILES}/include
	/opt/opencv3.1/include
)

# find library
FIND_LIBRARY(opencv_core NAMES opencv_core PATHS /opt/opencv3.1/lib NO_DEFAULT_PATH)
FIND_LIBRARY(opencv_imgproc NAMES opencv_imgproc PATHS /opt/opencv3.1/lib NO_DEFAULT_PATH)
FIND_LIBRARY(opencv_highgui NAMES opencv_highgui PATHS /opt/opencv3.1/lib NO_DEFAULT_PATH)
FIND_LIBRARY(opencv_imgcodecs NAMES opencv_imgcodecs PATHS /opt/opencv3.1/lib NO_DEFAULT_PATH)
FIND_LIBRARY(opencv_video NAMES opencv_video PATHS /opt/opencv3.1/lib NO_DEFAULT_PATH)
FIND_LIBRARY(opencv_videoio NAMES opencv_videoio PATHS /opt/opencv3.1/lib NO_DEFAULT_PATH)
MESSAGE(STATUS "opencv libraries: ${opencv_core} ${opencv_imgproc} ${opencv_highgui} ${opencv_imgcodecs} ${opencv_video}" ${opencv_videoio})

# recursive query match files :*.cpp, *c
FILE(GLOB_RECURSE TEST_CPP_LIST ${PATH_TEST_FILES}/*.cpp)
FILE(GLOB_RECURSE TEST_C_LIST ${PATH_TEST_FILES}/*.c)
#MESSAGE(STATUS "cpp list: ${TEST_CPP_LIST} ${TEST_C_LIST}")

FILE(GLOB_RECURSE SRC_CPP_LIST ${PATH_SRC_FILES}/*.cpp)
#MESSAGE(STATUS "src cpp list: ${SRC_CPP_LIST}")

# generate dynamic library for fbc_cv
ADD_LIBRARY(fbc_cv SHARED ${SRC_CPP_LIST})

# build executable program
ADD_EXECUTABLE(OpenCV_Test ${TEST_CPP_LIST} ${TEST_C_LIST})
# add dependent library: static and dynamic
TARGET_LINK_LIBRARIES(OpenCV_Test fbc_cv ${opencv_core} ${opencv_imgproc} ${opencv_highgui} ${opencv_imgcodecs} ${opencv_video} ${opencv_videoio} pthread)

这两个文件的位置在:prj/linux_cmake_OpenCV_Test目录下,编译方法:将终端定位到此目录下,执行:

$ ./build.sh :编译生成release的fbc_cv动态库和OpenCV_Test测试执行文件;

$ ./build.sh 1:bian编译生成debug的fbc_cv动态库和OpenCV_Test测试执行文件。

你可能感兴趣的:(Shell,Image,Processing,OpenCV,CMake/Makefile)