diff --git a/.github/workflows/cmake.yml b/.github/workflows/cmake.yml index 73f6ce8..10b423a 100644 --- a/.github/workflows/cmake.yml +++ b/.github/workflows/cmake.yml @@ -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' diff --git a/camera_lib/README.md b/camera_lib/README.md index 86809b9..cf110f4 100644 --- a/camera_lib/README.md +++ b/camera_lib/README.md @@ -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: diff --git a/camera_lib/example/CMakeLists.txt b/camera_lib/example/CMakeLists.txt index ab82d8c..a13f48d 100644 --- a/camera_lib/example/CMakeLists.txt +++ b/camera_lib/example/CMakeLists.txt @@ -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 $ $) +if(WIN32) + add_custom_command(TARGET camera_example POST_BUILD + COMMAND ${CMAKE_COMMAND} -E copy $ $) -# 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} + $) + 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} - $) -endforeach() \ No newline at end of file + COMMAND ${CMAKE_COMMAND} -E copy $ $) +endif() \ No newline at end of file diff --git a/camera_lib/lib/linux/libopencv_core.so b/camera_lib/lib/linux/libopencv_core.so new file mode 100644 index 0000000..53c5652 Binary files /dev/null and b/camera_lib/lib/linux/libopencv_core.so differ diff --git a/camera_lib/lib/linux/libopencv_highgui.so b/camera_lib/lib/linux/libopencv_highgui.so new file mode 100644 index 0000000..46aea89 Binary files /dev/null and b/camera_lib/lib/linux/libopencv_highgui.so differ diff --git a/camera_lib/lib/linux/libopencv_imgcodecs.so b/camera_lib/lib/linux/libopencv_imgcodecs.so new file mode 100644 index 0000000..7a27f11 Binary files /dev/null and b/camera_lib/lib/linux/libopencv_imgcodecs.so differ diff --git a/camera_lib/lib/linux/libopencv_imgproc.so b/camera_lib/lib/linux/libopencv_imgproc.so new file mode 100644 index 0000000..fdb6fb6 Binary files /dev/null and b/camera_lib/lib/linux/libopencv_imgproc.so differ diff --git a/camera_lib/lib/linux/libopencv_videoio.so b/camera_lib/lib/linux/libopencv_videoio.so new file mode 100644 index 0000000..40454f8 Binary files /dev/null and b/camera_lib/lib/linux/libopencv_videoio.so differ diff --git a/camera_lib/lib/opencv_core480.dll b/camera_lib/lib/windows/opencv_core480.dll similarity index 100% rename from camera_lib/lib/opencv_core480.dll rename to camera_lib/lib/windows/opencv_core480.dll diff --git a/camera_lib/lib/opencv_core480.lib b/camera_lib/lib/windows/opencv_core480.lib similarity index 100% rename from camera_lib/lib/opencv_core480.lib rename to camera_lib/lib/windows/opencv_core480.lib diff --git a/camera_lib/lib/opencv_highgui480.dll b/camera_lib/lib/windows/opencv_highgui480.dll similarity index 100% rename from camera_lib/lib/opencv_highgui480.dll rename to camera_lib/lib/windows/opencv_highgui480.dll diff --git a/camera_lib/lib/opencv_highgui480.lib b/camera_lib/lib/windows/opencv_highgui480.lib similarity index 100% rename from camera_lib/lib/opencv_highgui480.lib rename to camera_lib/lib/windows/opencv_highgui480.lib diff --git a/camera_lib/lib/opencv_imgcodecs480.dll b/camera_lib/lib/windows/opencv_imgcodecs480.dll similarity index 100% rename from camera_lib/lib/opencv_imgcodecs480.dll rename to camera_lib/lib/windows/opencv_imgcodecs480.dll diff --git a/camera_lib/lib/opencv_imgcodecs480.lib b/camera_lib/lib/windows/opencv_imgcodecs480.lib similarity index 100% rename from camera_lib/lib/opencv_imgcodecs480.lib rename to camera_lib/lib/windows/opencv_imgcodecs480.lib diff --git a/camera_lib/lib/opencv_imgproc480.dll b/camera_lib/lib/windows/opencv_imgproc480.dll similarity index 100% rename from camera_lib/lib/opencv_imgproc480.dll rename to camera_lib/lib/windows/opencv_imgproc480.dll diff --git a/camera_lib/lib/opencv_imgproc480.lib b/camera_lib/lib/windows/opencv_imgproc480.lib similarity index 100% rename from camera_lib/lib/opencv_imgproc480.lib rename to camera_lib/lib/windows/opencv_imgproc480.lib diff --git a/camera_lib/lib/opencv_videoio480.dll b/camera_lib/lib/windows/opencv_videoio480.dll similarity index 100% rename from camera_lib/lib/opencv_videoio480.dll rename to camera_lib/lib/windows/opencv_videoio480.dll diff --git a/camera_lib/lib/opencv_videoio480.lib b/camera_lib/lib/windows/opencv_videoio480.lib similarity index 100% rename from camera_lib/lib/opencv_videoio480.lib rename to camera_lib/lib/windows/opencv_videoio480.lib diff --git a/camera_lib/src/CMakeLists.txt b/camera_lib/src/CMakeLists.txt index 2375674..907effe 100644 --- a/camera_lib/src/CMakeLists.txt +++ b/camera_lib/src/CMakeLists.txt @@ -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)