2025-02-16 开发问题备份

c调用Python

Embedding Python in Another Application

https://docs.python.org/3/c-api/call.html#c.PyObject_CallObject
https://docs.python.org/3/search.html?q=PyObject_CallObject
https://docs.python.org/3/extending/extending.html
https://docs.python.org/3/extending/embedding.html

problem

include(PythonConfig.cmake)
set(Python_DIR ${CMAKE_CURRENT_LIST_DIR})
find_package(Python REQUIRED COMPONENTS Interpreter Development.Module NumPy HINTS /usr)

set(Python_FOUND True)
set(Python_INCLUDE_DIRS “/usr/include/python3.10”)
set(Python_Interpreter_FOUND True)
set(Python_INTERPRETER “/usr/bin/python3.10”)
set(Python_INTERPRETER “/usr/bin/python3.10”)
set(Python_NumPy_INCLUDE_DIRS “/usr/local/lib/python3.10/dist-packages/numpy/core/include”)
set(Python_LIBRARY “/usr/lib/python3.10/config-3.10-x86_64-linux-gnu”)
set(Python_LIBRARY_DIRS “/usr/lib/python3.10/config-3.10-x86_64-linux-gnu”)
set(Python_LIBRARIES “/usr/lib/python3.10/config-3.10-x86_64-linux-gnu/libpython3.10.so”)

  • 5
    undefined reference to HikLib::voiceAlarm()
target_link_libraries(hikvision PRIVATE
    HCCore
    AudioRender
    hcnetsdk
    hpr
    NPQos
    PlayCtrl
    SuperRender
    z

    analyzedata
    AudioIntercom
    HCAlarm
    HCCoreDevCfg
    HCDisplay
    HCGeneralCfgMgr
    HCIndustry
    HCPlayBack
    HCPreview
    HCVoiceTalk
    iconv2
    StreamTransClient
    SystemTransform
)

include_directories(
    /usr/local/hikvision/include
)
link_directories(
    /usr/local/hikvision/lib
    /usr/local/hikvision/lib/HCNetSDKCom
)
target_link_libraries(target 
    hikvision
)
  • 6
    ‘std::filesystem’ has not been declared

set(CMAKE_CXX_STANDARD 17) or -std=c++17

remote qt creator

https://doc.qt.io/qtcreator/creator-developing-generic-linux.html
https://doc.qt.io/qtcreator/creator-how-tos.html#remote-linux
File-Open From Device

qmake2cmake

https://www.qt.io/blog/introducing-qmake2cmake
https://wiki.qt.io/Qt_Creator_qmake_to_CMake_Workflow

OSG OpenSceneGraph

git clone https://github.com/openscenegraph/OpenSceneGraph.git
mkdir build
cd build
cmake -D CMAKE_INSTALL_PREFIX=third_party/OpenSceneGraph/install …

QT cross-compile

https://doc.qt.io/qt-6/qmake-test-function-reference.html
https://doc.qt.io/qtvstools/qtvstools-how-to-cross-compile.html
find /usr -name “qmake.conf”
https://doc.qt.io/qt-6/qmake-tutorial.html

jetson

https://github.com/dusty-nv/jetson-inference/tree/master
https://github.com/NVIDIA
https://developer.nvidia.com/embedded/twodaystoademo

problem

  • 7
    To use a cross-compiled Qt, please set the QT_HOST_PATH cache variable to
    the location of your host Qt installation.

Ubuntu Jetson Orin Nano 安装qt6, build from source

https://forums.developer.nvidia.com/t/installing-qt6-and-pyside6-on-jetson-orin-nano/274699
wget https://qt.mirror.constant.com/archive/qt/6.5/6.5.2/single/qt-everywhere-src-6.5.2.tar.xz
tar -xvf qt-everywhere-src-6.5.2.tar.xz
cd qt-everywhere-src-6.6.1

sudo apt-get install build-essential libfontconfig1-dev libdbus-1-dev libfreetype6-dev libicu-dev libinput-dev libxkbcommon-dev libsqlite3-dev libssl-dev libpng-dev libjpeg-dev libglib2.0-dev libpulse-dev libasound2-dev libcups2-dev libegl1-mesa-dev libxcb1-dev libx11-xcb-dev libglu1-mesa-dev libxrender-dev libxi-dev '^libxcb.*-dev'

./configure -platform linux-g++ -xcb -opensource -confirm-license
make
sudo make install

https://doc.qt.io/Boot2Qt/b2qt-qsg-nvidia.html
Ubuntu安装qt6
https://askubuntu.com/questions/1404353/how-to-install-qt6-on-ubuntu-21-10
https://forum.qt.io/topic/148418/how-to-install-qt6-latest-for-ubuntu-22-jammy-fish/2
https://forums.developer.nvidia.com/t/installing-qt6-and-pyside6-on-jetson-orin-nano/274699

sudo add-apt-repository ppa:okirby/qt6-backports
sudo apt update
sudo apt install qt6-base-dev [...]
sudo apt install qtcreator

shared_ptr new make_shared

jetson orin nano install cuda cudnn tensorrt opencv

  • sudo apt update
  • sudo apt dist-upgrade
  • sudo reboot
  • sudo apt install nvidia-jetpack

jtop

  • sudo apt-get install python3-pip

  • sudo pip3 install -U pip

  • sudo pip3 install -U jetson-stats

  • sudo reboot now

  • jtop

  • 7

install opencv jetson orin nano

git clone https://github.com/opencv/opencv.git
cd opencv && mkdir build && cd build
wget https://github.com/opencv/opencv_contrib/archive/refs/tags/4.8.0.zip
unzip -q 4.8.0.zip -d opencv_contrib
cmake -D WITH_CUDA=ON -D WITH_CUDNN=ON -D CUDA_ARCH_BIN="8.7" -D CUDA_ARCH_PTX="" -D OPENCV_EXTRA_MODULES_PATH=../opencv_contrib/modules -D OPENCV_GENERATE_PKGCONFIG=ON -D WITH_GSTREAMER=ON -D WITH_LIBV4L=ON -D BUILD_opencv_python3=ON -D BUILD_TESTS=OFF -D BUILD_PERF_TESTS=OFF -D BUILD_EXAMPLES=OFF -D CMAKE_BUILD_TYPE=RELEASE -D CMAKE_INSTALL_PREFIX=/usr/local ..
make -j3
sudo make install

https://github.com/JetsonHacksNano/buildOpenCV/blob/master/buildOpenCV.sh
https://github.com/AastaNV/JEP/blob/master/script/install_opencv4.9.0_Jetpack6.0.sh

确定 CUDA_ARCH_BIN

https://developer.nvidia.com/cuda-gpus
https://forums.developer.nvidia.com/t/what-should-be-the-value-of-cuda-arch-bin/47316/3

jetson orin nano tensorrt build

https://forums.developer.nvidia.com/t/build-jetson-tensorrt-oss-plugin-error-no-cmake-cuda-compiler-could-be-found/174331
https://forums.developer.nvidia.com/t/build-jetson-tensorrt-oss-plugin-error-no-cmake-cuda-compiler-could-be-found/174331

git clone https://github.com/NVIDIA/TensorRT.git
git checkout release/8.5

cd $TRT_OSSPATH
mkdir -p build && cd build
cmake .. -DTRT_LIB_DIR=$TRT_LIBPATH -DTRT_OUT_DIR=`pwd`/out -DTRT_PLATFORM_ID=aarch64 -DCUDA_VERSION=11.6 -DCMAKE_C_COMPILER=/usr/bin/gcc -DCMAKE_CUDA_COMPILER=/usr/local/cuda/bin/nvcc
CC=/usr/bin/gcc make -j$(nproc)

free qt version

a new account to free

problem

  1. fatal error: boost/version.hpp: No such file or directory

https://raspberrypi.stackexchange.com/questions/99991/c-problem-boost-asio-hpp-non-existing
sudo apt-get install libboost-dev

  1. skipping incompatible libhcnetsdk.so when searching for -lhcnetsdk /usr/bin/ld: cannot find -lhcnetsdk
    https://open.hikvision.com/download/5cda567cf47ae80dd41a54b3?type=20
    设备网络SDK_ArmLinux64 V6.1.9.45_build20
    OR
    设备网络SDK_Linux64 V6.1.9.48_build20230410

  2. chm view
    sudo apt-get install kchmviewer

  3. /usr/bin/ld: cannot find -liconv2
    remove # iconv2 library

  4. /usr/bin/ld: cannot find -lNPQos
    remove # NPQos library

  5. undefined reference to symbol ‘pthread_condattr_setclock@@GLIBC_2.17’

cmake add lib

target_link_libraries(target PRIVATE
    pthread
)
  1. undefined reference to `cv::VideoCapture::VideoCapture()’
    -lopencv_videoio

  2. jetson orin nano install pytorch torchvision
    https://forums.developer.nvidia.com/t/pytorch-for-jetson/72048

# substitute the link URL and wheel filename from the desired torch version above
wget https://nvidia.box.com/shared/static/i8pukc49h3lhak4kkn67tg9j4goqm0m7.whl -O torch-2.0.0+nv23.05-cp38-cp38-linux_aarch64.whl
sudo apt-get install python3-pip libopenblas-base libopenmpi-dev libomp-dev
pip3 install 'Cython<3'
pip3 install numpy torch-2.0.0+nv23.05-cp38-cp38-linux_aarch64.whl


$ sudo apt-get install libjpeg-dev zlib1g-dev libpython3-dev libopenblas-dev libavcodec-dev libavformat-dev libswscale-dev 
$ git clone --branch <version> https://github.com/pytorch/vision torchvision   # see below for version 【git clone --branch release/0.15 https://github.com/pytorch/vision torchvision】of torchvision to download     
$ cd torchvision
$ export BUILD_VERSION=0.x.0  # where 0.x.0 is the torchvision version  
$ python3 setup.py install --user
$ cd ../  # attempting to load torchvision from build dir will result in import error
$ pip install 'pillow<7' # always needed for Python 2.7, not needed torchvision v0.5.0+ with Python 3.6

jetson orin nano onnxruntime-gpu install

https://elinux.org/Jetson_Zoo#ONNX_Runtime

https://onnxruntime.ai/getting-started

GStreamer warning: cannot query video fps

https://forums.developer.nvidia.com/t/gstreamer-warning-and-black-screen-with-usbcamera-on-jetson/314979

rtsp opencv [hevc] Could not find ref with POC

使用线程安全的队列

  • 具体的方案是:https://github.com/ultralytics/ultralytics/pull/10201/commits

  • 方案:多线程,read改成grab不放入缓存内,read直接放入缓存,一个线程读取,另一个线程处理的,一个线程用作缓存,不使用opencv自己的缓存

  • 使用子码流,不使用主码流,main改成sub,减小图片的大小

  • rtsp://admin:admin12@192.168.101.1/h264/ch1/main/av_stream

  • 改成

  • rtsp://admin:admin12@192.168.101.1/h264/ch1/sub/av_stream

  • 使用 cap = cv2.VideoCapture(“rtsp://192.168.1.1:554/” , cv2.CAP_FFMPEG),而不是cap = cv2.VideoCapture(“rtsp://192.168.1.1:554/”)

  • 跨帧处理送入深度学习模型处理,不处理每一帧,隔几帧处理一帧

参考:
https://blog.csdn.net/qq_41950533/article/details/125216412
https://blog.csdn.net/darkeyers/article/details/84865363
https://blog.csdn.net/qq_33764934/article/details/103482121
https://github.com/ZLMediaKit/ZLMediaKit/issues/2018
https://blog.csdn.net/submarineas/article/details/110083906
https://blog.csdn.net/David_jiahuan/article/details/103693582
https://blog.csdn.net/qq_43348528/article/details/109337221
https://blog.csdn.net/qq_29414731/article/details/120284387

cv2.CAP_PROP_FRAME_COUNT 指定视频帧的位置
cap.set(cv2.CAP_PROP_FRAME_COUNT, location)

rtsp://admin:admin12@192.168.101.1/h264/ch1/main/av_stream 主码流
rtsp://admin:admin12@192.168.101.1/h264/ch1/sub/av_stream 子码流

修改海康视频流的配置

Logo

火山引擎开发者社区是火山引擎打造的AI技术生态平台,聚焦Agent与大模型开发,提供豆包系列模型(图像/视频/视觉)、智能分析与会话工具,并配套评测集、动手实验室及行业案例库。社区通过技术沙龙、挑战赛等活动促进开发者成长,新用户可领50万Tokens权益,助力构建智能应用。

更多推荐