Centos等Linux配置本地源
挂载本地ISO文件
mkdir /mnt/cdrom
mount -t iso9660 CentOS-7-x86_64-DVD-2003.iso /mnt/cdrom/
将文件CentOS-Base.repo改名为CentOS-Base.repo.old
mv /etc/yum.repos.d/CentOS-Base.repo /etc/yum.repos.d/CentOS-Base.repo.old
请将/etc/yum.repos.d目录下除CentOS-Media.repo之外的所有文件改名。
image.png
修改“vi /etc/yum.repos.d/CentOS-Media.repo”内容如下图:
image.png
输入以下命令安装vim
yum clean all
yum install vim
编译opencv4
安装依赖
sudo yum -y install epel-release
sudo yum -y install git gcc gcc-c++ cmake3
sudo yum -y install qt5-qtbase-devel
sudo yum install -y python34 python34-devel python34-pip
sudo yum install -y python python-devel python-pip
sudo yum -y install python-devel numpy python34-numpy
sudo yum -y install gtk2-devel
sudo yum install -y libpng-devel
sudo yum install -y jasper-devel
sudo yum install -y openexr-devel
sudo yum install -y libwebp-devel
sudo yum -y install libjpeg-turbo-devel
sudo yum install -y freeglut-devel mesa-libGL mesa-libGL-devel
sudo yum -y install libtiff-devel
sudo yum -y install libdc1394-devel
sudo yum -y install tbb-devel eigen3-devel
sudo yum -y install boost boost-thread boost-devel
sudo yum -y install libv4l-devel
sudo yum -y install gstreamer-plugins-base-devel
安装cmake3
sudo yum install epel-release
sudo yum install cmake3
[optional]
sudo yum remove cmake
sudo ln -s /usr/bin/cmake3 /usr/bin/cmake
安装tesseract
# 搜索「tesseract」
yum search tesseract
#安装「tesseract.x86_64」
yum install tesseract.x86_64 tesseract-devel.x86_64
#安装「tesseract-langpack-chi_sim.noarch」中文字库
yum install tesseract-langpack-chi_sim.noarch
#检查「tesseract」支持的语言
tesseract --list-langs
编译opencv4
mkdir ~/opencv_build && cd ~/opencv_build
git clone https://github.com/opencv/opencv.git
git clone https://github.com/opencv/opencv_contrib.git
创建临时编译目录
cd ~/opencv_build/opencv
mkdir build && cd build
使用CMake编译OpenCV(编译命令去除了JAVA和PYTHON)
cmake -D CMAKE_INSTALL_PREFIX=/usr/local \
-D CMAKE_BUILD_TYPE=Release \
-D OPENCV_EXTRA_MODULES_PATH=~/opencv_build/opencv_contrib/modules \
-D WITH_GTK=OFF \
-D WITH_QT=OFF \
-D WITH_WIN32UI=OFF \
-D WITH_QUICKTIME=OFF \
-D WITH_QTKIT=OFF \
-D BUILD_EXAMPLES=OFF \
-D BUILD_JAVA=OFF \
-D BUILD_FAT_JAVA_LIB=OFF \
-D BUILD_opencv_js=OFF \
-D WITH_DIRECTX=OFF \
-D BUILD_WITH_DEBUG_INFO=OFF \
-D INSTALL_TESTS=OFF \
-D BUILD_NEW_PYTHON_SUPPORT=OFF \
-D BUILD_opencv_python2=OFF \
-D BUILD_opencv_python3=OFF \
-D ANDROID=OFF \
-D INSTALL_ANDROID_EXAMPLES=OFF \
-D INSTALL_C_EXAMPLES=OFF \
-D INSTALL_PYTHON_EXAMPLES=OFF \
-D BUILD_DOCS=OFF \
-D BUILD_PERF_TESTS=OFF \
-D BUILD_TESTS=OFF \
-D BUILD_ANDROID_SERVICE=OFF \
-D ENABLE_PRECOMPILED_HEADERS=OFF \
-D OPENCV_GENERATE_PKGCONFIG=ON ..
开始编译进程
make -j8
编译中出现缺少“boostdesc_bgm.i”的错误,执行以下命令(要翻墙)后再次编译
cd ~/opencv_build/opencv_contrib/modules/xfeatures2d/src
curl wget https://raw.githubusercontent.com/opencv/opencv_3rdparty/34e4206aef44d50e6bbcd0ab06354b52e7466d26/boostdesc_lbgm.i >boostdesc_lbgm.i
curl wget https://raw.githubusercontent.com/opencv/opencv_3rdparty/34e4206aef44d50e6bbcd0ab06354b52e7466d26/boostdesc_binboost_256.i >boostdesc_binboost_256.i
curl wget https://raw.githubusercontent.com/opencv/opencv_3rdparty/34e4206aef44d50e6bbcd0ab06354b52e7466d26/boostdesc_binboost_128.i >boostdesc_binboost_128.i
curl wget https://raw.githubusercontent.com/opencv/opencv_3rdparty/34e4206aef44d50e6bbcd0ab06354b52e7466d26/boostdesc_binboost_064.i >boostdesc_binboost_064.i
curl wget https://raw.githubusercontent.com/opencv/opencv_3rdparty/34e4206aef44d50e6bbcd0ab06354b52e7466d26/boostdesc_bgm_hd.i >boostdesc_bgm_hd.i
curl wget https://raw.githubusercontent.com/opencv/opencv_3rdparty/34e4206aef44d50e6bbcd0ab06354b52e7466d26/boostdesc_bgm_bi.i >boostdesc_bgm_bi.i
curl wget https://raw.githubusercontent.com/opencv/opencv_3rdparty/34e4206aef44d50e6bbcd0ab06354b52e7466d26/boostdesc_bgm.i >boostdesc_bgm.i
curl wget https://raw.githubusercontent.com/opencv/opencv_3rdparty/fccf7cd6a4b12079f73bbfb21745f9babcd4eb1d/vgg_generated_120.i > vgg_generated_120.i
curl wget https://raw.githubusercontent.com/opencv/opencv_3rdparty/fccf7cd6a4b12079f73bbfb21745f9babcd4eb1d/vgg_generated_64.i >vgg_generated_64.i
curl wget https://raw.githubusercontent.com/opencv/opencv_3rdparty/fccf7cd6a4b12079f73bbfb21745f9babcd4eb1d/vgg_generated_48.i >vgg_generated_48.i
curl wget https://raw.githubusercontent.com/opencv/opencv_3rdparty/fccf7cd6a4b12079f73bbfb21745f9babcd4eb1d/vgg_generated_80.i >vgg_generated_80.i
编译中出现缺少features2d/test/test_detectors_regression.impl.hpp错误
cp -r ~/opencv_build/opencv/modules/* ~/opencv_build/opencv_contrib/modules/xfeatures2d/test/
安装OpenCV
sudo make install
配置PKG_CONFIG_PATH
export PKG_CONFIG_PATH=$PKG_CONFIG_PATH:/usr/local/lib/pkgconfig:/usr/local/lib64/pkgconfig
export LD_LIBRARY_PATH=$LD_LIBRARY_PATH:/usr/local/lib:/usr/local/lib64
查看安装opencv版本
pkg-config --modversion opencv4
查看pkg-config
pkg-config --cflags --libs opencv4
c++程序
#include <opencv2/core.hpp>
#include <opencv2/imgcodecs.hpp>
#include <iostream>
using namespace cv;
int main()
{
// std::string image_path = samples::findFile("1.png");
std::string image_path = "1.png";
std::cout << "Could not read the image: " << "" << std::endl;
Mat img = imread(image_path, IMREAD_COLOR);
if(img.empty())
{
std::cout << "Could not read the image: " << "" << std::endl;
return 1;
}
imwrite("o1.png", img);
return 0;
}
运行程序
g++ -std=c++11 cv.cpp -o cv `pkg-config --cflags --libs opencv4`
./cv
安装gRPC
编译源代码:
git clone -b $(curl -L https://grpc.io/release) https://github.com/grpc/grpc
cd grpc
git submodule update --init
make
sudo make install
cd third_party/protobuf
sudo make install
运行样例:
cd examples/cpp/helloworld/
make
./greeter_server
c++生成proto类
protoc -I ./ --cpp_out=./ ./uniform_auth.proto
g++ -std=c++11 `pkg-config --cflags protobuf grpc` -c -o uniform_auth.pb.o uniform_auth.pb.cc
protoc -I ./ --grpc_out=./ --plugin=protoc-gen-grpc=/usr/local/bin/grpc_cpp_plugin ./uniform_auth.proto
g++ -std=c++11 `pkg-config --cflags protobuf grpc` -c -o uniform_auth.grpc.pb.o uniform_auth.grpc.pb.cc
g++ -std=c++11 `pkg-config --cflags protobuf grpc opencv4` -I . -c -o auth_server.o auth_server.cc
g++ -std=c++11 uniform_auth.pb.o uniform_auth.grpc.pb.o auth_server.o -L/usr/local/lib -L/usr/local/lib64 `pkg-config --libs protobuf grpc++ opencv4` -pthread -Wl,--no-as-needed -lgrpc++_reflection -Wl,--as-needed -ldl -o auth_server
其他命令
tar.gz压缩
tar cvzf grpc.tar.gz grpc
解压
tar zxvf grpc.tar.gz
删除编译grpc文件
rm -rf objs/opt/src/compiler/*
网友评论