Skip to content

Commit

Permalink
Added opencv libs for Linux
Browse files Browse the repository at this point in the history
  • Loading branch information
yushulx committed Jun 18, 2024
1 parent f94bbd7 commit a71653a
Show file tree
Hide file tree
Showing 19 changed files with 38 additions and 49 deletions.
35 changes: 0 additions & 35 deletions .github/workflows/cmake.yml
Original file line number Diff line number Diff line change
Expand Up @@ -71,41 +71,6 @@ jobs:

steps:
- uses: actions/checkout@v3

# Download OpenCV source code
- name: Download OpenCV source code
run: |
git clone https://github.com/opencv/opencv.git
cd opencv
git checkout 4.x # Or specify a specific version
# Configure and build OpenCV
- name: Configure OpenCV
run: |
cmake -S opencv -B opencv/build -DBUILD_SHARED_LIBS=ON -DBUILD_opencv_world=OFF -DBUILD_opencv_apps=OFF -DBUILD_opencv_calib3d=OFF -DBUILD_opencv_dnn=OFF -DBUILD_opencv_features2d=OFF -DBUILD_opencv_flann=OFF -DBUILD_opencv_gapi=OFF -DBUILD_opencv_ml=OFF -DBUILD_opencv_objdetect=OFF -DBUILD_opencv_photo=OFF -DBUILD_opencv_stitching=OFF -DBUILD_opencv_video=OFF -DBUILD_TESTS=OFF -DBUILD_PERF_TESTS=OFF -DBUILD_EXAMPLES=OFF -DBUILD_DOCS=OFF -DCMAKE_BUILD_TYPE=${{ env.BUILD_TYPE }}
- name: Build OpenCV
run: cmake --build opencv/build --config ${{ env.BUILD_TYPE }}

# Package the built shared libraries
- name: Package Shared Libraries
run: |
mkdir -p packages/${{ matrix.os }}
cp -r opencv/build/lib packages/${{ matrix.os }}/
if: runner.os == 'Linux' || runner.os == 'macOS'

- name: Package Shared Libraries for Windows
run: |
mkdir -p packages/${{ matrix.os }}
cp -r opencv/build/Release/*.dll packages/${{ matrix.os }}/
if: runner.os == 'Windows'

# Upload artifacts
- name: Upload Shared Libraries
uses: actions/upload-artifact@v2
with:
name: shared-libraries-${{ matrix.os }}
path: packages/${{ matrix.os }}

- name: Set up QEMU
if: runner.os == 'Linux'
Expand Down
8 changes: 7 additions & 1 deletion camera_lib/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,13 @@
6. Configure `src/CMakeLists.txt` to link against the OpenCV library.

```cmake
target_link_libraries(camera_lib opencv_core480 opencv_highgui480 opencv_videoio480 opencv_imgproc480)
if(WIN32)
link_directories(${CMAKE_CURRENT_SOURCE_DIR}/../lib/windows)
set(OPENCV_LIBS opencv_core480 opencv_highgui480 opencv_videoio480 opencv_imgproc480)
elseif(UNIX)
link_directories(${CMAKE_CURRENT_SOURCE_DIR}/../lib/linux)
set(OPENCV_LIBS opencv_core opencv_highgui opencv_videoio opencv_imgproc)
endif()
```
7. Build the camera application:

Expand Down
32 changes: 21 additions & 11 deletions camera_lib/example/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,22 +1,32 @@
cmake_minimum_required(VERSION 3.10)
project(camera_example)

link_directories(${CMAKE_CURRENT_SOURCE_DIR}/../lib)
if(WIN32)
link_directories(${CMAKE_CURRENT_SOURCE_DIR}/../lib/windows)
file(GLOB DLL_FILES "${CMAKE_CURRENT_SOURCE_DIR}/../lib/windows/*.dll")
elseif(UNIX)
link_directories(${CMAKE_CURRENT_SOURCE_DIR}/../lib/linux)
endif()

# Create the executable
add_executable(camera_example main.cpp)
target_include_directories(camera_example PUBLIC ${CMAKE_CURRENT_SOURCE_DIR}/../include)
target_link_libraries(camera_example camera_lib)

add_custom_command(TARGET camera_example POST_BUILD
COMMAND ${CMAKE_COMMAND} -E copy $<TARGET_FILE:camera_lib> $<TARGET_FILE_DIR:camera_example>)
if(WIN32)
add_custom_command(TARGET camera_example POST_BUILD
COMMAND ${CMAKE_COMMAND} -E copy $<TARGET_FILE:camera_lib> $<TARGET_FILE_DIR:camera_example>)

# Find all DLL files in the specified directory
file(GLOB DLL_FILES "${CMAKE_CURRENT_SOURCE_DIR}/../lib/*.dll")
# Copy the DLL files to the executable directory
foreach(DLL_FILE ${DLL_FILES})
add_custom_command(TARGET camera_example POST_BUILD
COMMAND ${CMAKE_COMMAND} -E copy_if_different
${DLL_FILE}
$<TARGET_FILE_DIR:camera_example>)
endforeach()
endif()

# Copy the DLL files to the executable directory
foreach(DLL_FILE ${DLL_FILES})
if(UNIX)
add_custom_command(TARGET camera_example POST_BUILD
COMMAND ${CMAKE_COMMAND} -E copy_if_different
${DLL_FILE}
$<TARGET_FILE_DIR:camera_example>)
endforeach()
COMMAND ${CMAKE_COMMAND} -E copy $<TARGET_FILE:camera_lib> $<TARGET_FILE_DIR:camera_example>)
endif()
Binary file added camera_lib/lib/linux/libopencv_core.so
Binary file not shown.
Binary file added camera_lib/lib/linux/libopencv_highgui.so
Binary file not shown.
Binary file added camera_lib/lib/linux/libopencv_imgcodecs.so
Binary file not shown.
Binary file added camera_lib/lib/linux/libopencv_imgproc.so
Binary file not shown.
Binary file added camera_lib/lib/linux/libopencv_videoio.so
Binary file not shown.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
12 changes: 10 additions & 2 deletions camera_lib/src/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,11 +1,19 @@
cmake_minimum_required(VERSION 3.10)
project(camera_lib)

link_directories(${CMAKE_CURRENT_SOURCE_DIR}/../lib)
# Set the library path based on the operating system
if(WIN32)
link_directories(${CMAKE_CURRENT_SOURCE_DIR}/../lib/windows)
set(OPENCV_LIBS opencv_core480 opencv_highgui480 opencv_videoio480 opencv_imgproc480)
elseif(UNIX)
link_directories(${CMAKE_CURRENT_SOURCE_DIR}/../lib/linux)
set(OPENCV_LIBS opencv_core opencv_highgui opencv_videoio opencv_imgproc)
endif()

# Create the shared library
add_library(camera_lib SHARED camera_lib.cpp)
target_include_directories(camera_lib PUBLIC ${CMAKE_CURRENT_SOURCE_DIR}/../include)
target_link_libraries(camera_lib opencv_core480 opencv_highgui480 opencv_videoio480 opencv_imgproc480)
target_link_libraries(camera_lib ${OPENCV_LIBS})

if(MSVC)
target_compile_definitions(camera_lib PRIVATE CAMERA_LIB_EXPORTS)
Expand Down

0 comments on commit a71653a

Please sign in to comment.