Debian || Ubuntu编译安装OpenCV(Only C++ without Python!)

Debian源码编译安装OpenCV C++版本

Only compile opencv c++, without python and java.

  • first step: install dependency.

sudo apt-get install build-essential
sudo apt-get install cmake git libgtk2.0-dev pkg-config libavcodec-dev libavformat-dev libswscale-dev qtbase5-dev libtiff-dev

  • second step: download opencv source code.

In Linux operate system, you can use this command line: wget https://github.com/opencv/opencv/archive/4.1.0.zip, or use git clone https://github.com/opencv/opencv.git

  • third step

Entire the opencv source code directory and make a directory build, and you can also use another name, it’s no matter.

  • forth step: without build python and java model

In CMakeLists.txt file, delete the python model and java model.
Delete python model
Delete Java Model
Entire the directory that you made just a minute ago, and in this directory, execute the following command:
cmake -D CMAKE_BUILD_TYPE=RELEASE -D CMAKE_INSTALL_PREFIX=~/${your_directory}
I suggest the CMAKE_INSTALL_PREFIX opencv in a directory that you want to install and don’t use : /usr/local directory, because if you want to uninstall this version of opencv, you can only delete the directory that you installed opencv.
In this blog, I use the following command to install OpenCV in my laptop:

  • cmake -D CMAKE_BUILD_TYPE=RELEASE -D CMAKE_INSTALL_PREFIX=/home/wangheng/app/opencv4
    Maybe you want to install with CUDA or CUDNN, you can add the string: -D WITH_CUDA=ON and so on.
    在这里插入图片描述
  • finally make -j2 ; make install
  • 2
    点赞
  • 4
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
要在RK3588 Debian 11上编译OpenCV C++程序并使用GPU加速,您需要遵循以下步骤: 1. 安装CUDA和cuDNN 首先,您需要安装CUDA和cuDNN。您可以按照NVIDIA的指南进行安装。建议使用TensorFlow官方支持的版本。例如,如果您使用TensorFlow 2.6,则应安装CUDA 11.2和cuDNN 8.2。 2. 安装OpenCV 安装OpenCV之前,您需要安装一些依赖项: ``` sudo apt-get install build-essential cmake git libgtk2.0-dev pkg-config libavcodec-dev libavformat-dev libswscale-dev ``` 然后,您可以从OpenCV官方网站下载源代码,并按照以下步骤进行编译安装: ``` cd ~/opencv mkdir build cd build cmake -D CMAKE_BUILD_TYPE=RELEASE -D CMAKE_INSTALL_PREFIX=/usr/local -D WITH_CUDA=ON -D CUDA_ARCH_BIN=8.2 -D CUDA_ARCH_PTX="" -D WITH_CUDNN=ON -D OPENCV_DNN_CUDA=ON .. make -j8 sudo make install ``` 请注意,我们在cmake命令中启用了CUDA和cuDNN支持,并指定了CUDA架构版本为8.2。您应该根据您的GPU型号和CUDA版本进行相应的更改。 3. 编写和编译OpenCV C++程序 现在,您可以编写和编译OpenCV C++程序。在编写代码时,请确保使用OpenCV CUDA模块中的函数,例如cv::cuda::GpuMat。在编译代码时,您需要链接OpenCV CUDA模块和CUDA库。以下是一个简单的示例程序: ``` #include <opencv2/opencv.hpp> #include <opencv2/cudaarithm.hpp> #include <opencv2/cudaimgproc.hpp> int main() { cv::Mat image = cv::imread("image.jpg"); cv::cuda::GpuMat gpuImage; gpuImage.upload(image); cv::cuda::GpuMat gpuGrayImage; cv::cuda::cvtColor(gpuImage, gpuGrayImage, cv::COLOR_BGR2GRAY); cv::Mat grayImage; gpuGrayImage.download(grayImage); cv::imshow("Gray Image", grayImage); cv::waitKey(); return 0; } ``` 您可以使用以下命令编译程序: ``` g++ -o program program.cpp `pkg-config opencv4 --cflags --libs` -L/usr/local/cuda/lib64 -lcudart ``` 请注意,我们使用pkg-config命令来获取OpenCV编译选项,并链接CUDA库。您应该根据您的系统进行相应的更改。 希望这可以帮助您在RK3588 Debian 11上编译和运行OpenCV C++程序并使用GPU加速。
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值