分类 Ubuntu 下的文章

“Ubuntu是以桌面应用为主的Linux发行版,基于Debian。Ubuntu有三个正式版本,包括桌面版、服务器版及用于物联网设备和机器人的Core版。从17.10版本开始,Ubuntu以GNOME为默认桌面环境。 Ubuntu是著名的Linux发行版之一,也是目前最多用户的Linux版本。 ”

#include <chrono>
#include <ctime>
using namespace std::chrono;

system_clock::time_point time_point_now = system_clock::now(); // 获取当前时间点
system_clock::duration duration_since_epoch 
        = time_point_now.time_since_epoch(); // 从1970-01-01 00:00:00到当前时间点的时长
time_t microseconds_since_epoch 
        = duration_cast<microseconds>(duration_since_epoch).count(); // 将时长转换为微秒数
time_t seconds_since_epoch = microseconds_since_epoch / 1000000; // 将时长转换为秒数
std::tm current_time = *std::localtime(&seconds_since_epoch); // 获取当前时间(精确到秒)
time_t tm_microsec = microseconds_since_epoch % 1000; // 当前时间的微妙数
time_t tm_millisec = microseconds_since_epoch / 1000 % 1000; // 当前时间的毫秒数

下载
https://github.com/opencv/opencv/archive/refs/tags/4.5.3.zip

解压

unzip 4.5.3.zip

建目录

cd opencv4.5.3 && mkdir build && cd build

配置

cmake -D CMAKE_BUILD_TYPE=RELEASE -D CMAKE_INSTALL_PREFIX=/usr/local/opencv4.5.3 ..

编译

make -j8

安装

sudo make install

配置lib

sudo vi /etc/ld.so.conf.d/opencv4.5.3.conf

/usr/local/opencv4.5.3/lib

更新lib

sudo ldconfig

另外,如果要编译opencv_world选项的话,在cmake的时候加个参数就好。

cmake -D CMAKE_BUILD_TYPE=RELEASE -D BUILD_opencv_world=ON -D CMAKE_INSTALL_PREFIX=/usr/local/opencv4.5.3 ..

其它的一些参数示例:

     -D WITH_CUDA=ON \

    -D CUDA_ARCH_BIN="5.3" \
    -D CUDA_ARCH_PTX="5.3" \
    -D WITH_CUBLAS=ON \
    -D ENABLE_FAST_MATH=ON \
    -D CUDA_FAST_MATH=ON \
    -D ENABLE_NEON=ON \
    -D WITH_GSTREAMER=ON \
    -D WITH_LIBV4L=ON \
    -D BUILD_opencv_python2=OFF \
    -D BUILD_opencv_python3=ON \
    -D BUILD_TESTS=OFF \
    -D BUILD_PERF_TESTS=OFF \
    -D BUILD_EXAMPLES=OFF  \
    -D WITH_TBB=ON \
    -D BUILD_opencv_world=OFF \
    -D WITH_OPENGL=ON \
    -D WITH_GTK_2_X=ON \
    -D OPENCV_ENABLE_NONFREE=ON \
    -D EIGEN_INCLUDE_PATH="/usr/include/eigen3" \
    -D WITH_XINE=ON \
    -D WITH_GDAL=ON \
    -D WITH_QT=ON \

cmake编译选项(ON是开(机)的意思; OFF是关(机)的意思)

-D CMAKE_BUILD_TYPE=RELEASE

编译模式,release/debug, 默认为release
-D CMAKE_INSTALL_PREFIX=/usr/local

安装路径
-D WITH_TBB=ON #Include Intel TBB support

(Intel开发的并行编程开发工具),默认为off
-D BUILD_TIFF=ON

Build libtiff from source(一种灵活的位图格式),默认为ON
-D WITH_V4L=ON 支持Vedio4Linux(是Linux中关于视频设备的内核驱动,为针对视频设备的应用视频设备的应用程序提供一系列接口函数,这些视频设备包括TV卡、视频捕捉卡和USB摄像头等,对于USB摄像头,其驱动程序中需要提供基本的I/O操作用于open、read、write、close函数的实现),默认为ON
-D INSTALL_C_EXAMPLES=ON Install C examples, 默认为off
-D INSTALL_PYTHON_EXAMPLES=ON Install Python examples, 默认为off
-D BUILD_EXAMPLES=ON Build all examples, 默认为off
-D WITH_QT=ON / #支持QT(c++图像用户界面开发框架,多用于开发GUI),默认为off

-D WITH_GTK=ON 支持跨平台通用图形工具包GTK, 默认为on
-D WITH_OPENGL=ON 支持开放图形库OpenGL,默认为off …
-D OPENCV_GENERATE_PKGCONFIG=ON Linux下我们使用opencv,需要使用pkg-config来进行环境变量的管理,这个软件需要.pc类型的文件作为软件配置信息
生成opencv.pc文件的配置(注意,opencv4生成的文件叫做opencv4.pc)

Referenced from:https://blog.csdn.net/zhizhengguan/article/details/107540971

cmake -D CMAKE_BUILD_TYPE=RELEASE -D CMAKE_INSTALL_PREFIX=/usr/local/opencv4.5.3 -D OPENCV_EXTRA_MODULES=../opencv_contrib/modules -D BUILD_EXAMPLES=ON -D WITH_VA=ON ..

下载

wget https://imagemagick.org/download/ImageMagick.tar.gz
tar xvf ImageMagick.tar.gz
cd ImageMagick-7.1.0-8/
./configure
ImageMagick 7.1.0-8 is configured as follows. Please verify that this
configuration matches your expectations.

Host system type: x86_64-pc-linux-gnu
Build system type: x86_64-pc-linux-gnu

                  Option                        Value
------------------------------------------------------------------------------
Shared libraries  --enable-shared=yes        yes
Static libraries  --enable-static=yes        yes
Build utilities   --with-utilities=yes        yes
Module support    --with-modules=no        no
GNU ld            --with-gnu-ld=yes        yes
Quantum depth     --with-quantum-depth=16    16
High Dynamic Range Imagery
                  --enable-hdri=yes        yes

Install documentation:                yes

Memory allocation library:
  JEMalloc          --with-jemalloc=no        no
  TCMalloc          --with-tcmalloc=no        no
  UMem              --with-umem=no        no

Delegate library configuration:
  BZLIB             --with-bzlib=yes        yes
  Autotrace         --with-autotrace=no        no
  DJVU              --with-djvu=yes        no
  DPS               --with-dps=yes        no
  FFTW              --with-fftw=no        no
  FLIF              --with-flif=yes        no
  FlashPIX          --with-fpx=yes        no
  FontConfig        --with-fontconfig=yes    yes
  FreeType          --with-freetype=yes        yes
  Ghostscript lib   --with-gslib=no        no
  Graphviz          --with-gvc=yes        no
  HEIC              --with-heic=yes        no
  JBIG              --with-jbig=yes        yes
  JPEG v1           --with-jpeg=yes        yes
  JPEG XL           --with-jxl=no        no
  LCMS              --with-lcms=yes        no
  LQR               --with-lqr=yes        no
  LTDL              --with-ltdl=no        no
  LZMA              --with-lzma=yes        yes
  Magick++          --with-magick-plus-plus=yes    yes
  OpenEXR           --with-openexr=yes        no
  OpenJP2           --with-openjp2=yes        no
  PANGO             --with-pango=yes        yes
  PERL              --with-perl=no        no
  PNG               --with-png=yes        yes
  RAQM              --with-raqm=yes        no
  RAW               --with-raw=yes        no
  RSVG              --with-rsvg=no        no
  TIFF              --with-tiff=yes        yes
  WEBP              --with-webp=yes        no
  WMF               --with-wmf=no        no
  X11               --with-x=            yes
  XML               --with-xml=yes        yes
  ZIP               --with-zip=yes        no
  ZLIB              --with-zlib=yes        yes
  ZSTD              --with-zstd=yes        no

可选
sudo apt-get install libpng-dev libjpeg-dev

make && sudo make install
convert --version

Version: ImageMagick 7.1.0-8 Q16-HDRI x86_64 2021-09-18 https://imagemagick.org
Copyright: (C) 1999-2021 ImageMagick Studio LLC
License: https://imagemagick.org/script/license.php
Features: Cipher DPC HDRI OpenMP(4.5) 
Delegates (built-in): bzlib fontconfig freetype jbig jng jpeg lzma pangocairo png tiff x xml zlib
Compiler: gcc (9.3)

查看支持的文件格式
convert -list format

   Format  Mode  Description
-------------------------------------------------------------------------------
      3FR  r--   Hasselblad CFV/H3D39II
      3G2  r--   Media Container
      3GP  r--   Media Container
        A* rw+   Raw alpha samples
      AAI* rw+   AAI Dune image
       AI  rw-   Adobe Illustrator CS2
     APNG  rw+   Animated Portable Network Graphics
      ART* rw-   PFS: 1st Publisher Clip Art
      ARW  r--   Sony Alpha Raw Image Format
   ASHLAR* -w+   Image sequence laid out in continuous irregular courses
      AVI  r--   Microsoft Audio/Visual Interleaved
      AVS* rw+   AVS X image
        B* rw+   Raw blue samples
      BGR* rw+   Raw blue, green, and red samples
     BGRA* rw+   Raw blue, green, red, and alpha samples
     BGRO* rw+   Raw blue, green, red, and opacity samples
      BIE* rw-   Joint Bi-level Image experts Group interchange format (2.1)
      BMP* rw-   Microsoft Windows bitmap image

。。。

转换图片格式
将文件QRcode.png转换成jpeg格式

convert QRcode.png QRcode.jpeg

ldconfig
ldconfig: /home/const/arm/libprotobuf.so.28 is not a symbolic link

ldconfig: /home/const/arm/libcjson.so.1 is not a symbolic link

ldconfig: /home/const/arm/libz.so.1 is not a symbolic link

ldconfig: /home/const/arm/libcjson_utils.so.1 is not a symbolic link

ldconfig: /home/const/arm/libcurl.so.4 is not a symbolic link

ldconfig: /home/const/arm/libprotoc.so.28 is not a symbolic link

ldconfig: /home/const/arm/libcares.so.2 is not a symbolic link

解决办法:

rm libprotobuf.so.28 && ln -s  libprotobuf.so.28.0.3 libprotobuf.so.28
rm libcjson.so.1 && ln -s libcjson.so.1.7.14 libcjson.so.1
rm libz.so.1 && ln -s libz.so.1.2.11 libz.so.1
rm libcjson_utils.so.1 && ln -s libcjson_utils.so.1.7.14 libcjson_utils.so.1
rm libcurl.so.4 && ln -s libcurl.so.4.7.0 libcurl.so.4
rm libprotoc.so.28 && ln -s libprotoc.so.28.0.3 libprotoc.so.28
rm libcares.so.2 && ln -s libcares.so.2.3.0 libcares.so.2

下载

wget https://github.com/ARMmbed/mbedtls/archive/refs/tags/v3.0.0.tar.gz

mv v3.0.0.tar.gz mbedtls-3.0.0.tar.gz
tar xvf mbedtls-3.0.0.tar.gz

cd mbedtls-3.0.0/
mkdir build && cd build

CC=arm-linux-gnueabihf-gcc cmake -D CMAKE_INSTALL_PREFIX=$(pwd)/../../install ..
-- The C compiler identification is GNU 5.5.0
-- Check for working C compiler: /opt/arm/bin/arm-linux-gnueabihf-gcc
-- Check for working C compiler: /opt/arm/bin/arm-linux-gnueabihf-gcc -- works
-- Detecting C compiler ABI info
-- Detecting C compiler ABI info - done
-- Detecting C compile features
-- Detecting C compile features - done
-- Found Python3: /usr/bin/python3.8 (found version "3.8.10") found components: Interpreter 
-- Performing Test C_COMPILER_SUPPORTS_WFORMAT_SIGNEDNESS
-- Performing Test C_COMPILER_SUPPORTS_WFORMAT_SIGNEDNESS - Success
-- Looking for pthread.h
-- Looking for pthread.h - found
-- Performing Test CMAKE_HAVE_LIBC_PTHREAD
-- Performing Test CMAKE_HAVE_LIBC_PTHREAD - Failed
-- Looking for pthread_create in pthreads
-- Looking for pthread_create in pthreads - not found
-- Looking for pthread_create in pthread
-- Looking for pthread_create in pthread - found
-- Found Threads: TRUE  
-- Configuring done
-- Generating done
make -j8
make install