Thursday, 10 February 2022

How to upgrade pip of python35 in ubuntu?

curl https://bootstrap.pypa.io/pip/3.5/get-pip.py -o get-pip.py
python get-pip.py

Wednesday, 2 February 2022

This tutorial details the installation of deepstream6.0 on Ubuntu18

Reference: Copied from https://developpaper.com/experience-sharing-ubuntu-installs-deepstream6-0/

---

This tutorial details the installation of deepstream6.0 on Ubuntu Method for 0.

Some versions require:

  • Ubuntu 18.04
  • GStreamer 1.14.5
  • NVIDIA driver 470.63.01
  • CUDA 11.4
  • TensorRT 8.0.1

1. Installation dependency

Installation dependency

sudo apt install libssl1.0.0 libgstreamer1.0-0 gstreamer1.0-tools gstreamer1.0-plugins-good gstreamer1.0-plugins-bad gstreamer1.0-plugins-ugly gstreamer1.0-libav libgstrtspserver-1.0-0 libjansson4 gcc make git python3

  install NVIDIA driver 470.63.01, download and transfer:https://www.nvidia.com/Downlo…

chmod 755 NVIDIA-Linux-x86_64-470.63.01.run
sudo ./NVIDIA-Linux-x86_64-470.63.01.run

  install CUDA toolkit 11.4.1 (CUDA 11.4 update 1), download and transfer:https://developer.nvidia.com/…

2. Install tensorrt 8.0.1

Execute the following command:

echo "deb https://developer.download.nvidia.com/compute/cuda/repos/ubuntu1804/x86_64 /" | sudo tee /etc/apt/sources.list.d/cuda-repo.list
wget https://developer.download.nvidia.com/compute/cuda/repos/ubuntu1804/x86_64/7fa2af80.pub
sudo apt-key add 7fa2af80.pub
sudo apt-get update

  DownloadTensorRT 8.0.1 GA for Ubuntu 18.04 and CUDA 11.3 DEB local repo package, download and transfer:https://developer.nvidia.com/…

Execute the following command to install tensorrt 8.0.1:

sudo dpkg -i nv-tensorrt-repo-ubuntu1804-cuda11.3-trt8.0.1.6-ga-20210626_1-1_amd64.deb
sudo apt-key add /var/nv-tensorrt-repo-ubuntu1804-cuda11.3-trt8.0.1.6-ga-20210626/7fa2af80.pub
sudo apt-get update
sudo apt-get install libnvinfer8=8.0.1-1+cuda11.3 libnvinfer-plugin8=8.0.1-1+cuda11.3 libnvparsers8=8.0.1-1+cuda11.3 libnvonnxparsers8=8.0.1-1+cuda11.3 libnvinfer-bin=8.0.1-1+cuda11.3 libnvinfer-dev=8.0.1-1+cuda11.3 libnvinfer-plugin-dev=8.0.1-1+cuda11.3 libnvparsers-dev=8.0.1-1+cuda11.3 libnvonnxparsers-dev=8.0.1-1+cuda11.3 libnvinfer-samples=8.0.1-1+cuda11.3 libnvinfer-doc=8.0.1-1+cuda11.3

3. Install librdkafka

Clone librdkafka Code:

git clone https://github.com/edenhill/librdkafka.git

Configuration and compilation Library:

cd librdkafka
git reset --hard 7101c2310341ab3f4675fc565f64f0967e135a6a

./configure
sudo make -j32
sudo make install

Copy the generated library to the deepstream folder:

sudo mkdir -p /opt/nvidia/deepstream/deepstream-6.0/lib
sudo cp /usr/local/lib/librdkafka* /opt/nvidia/deepstream/deepstream-6.0/lib

4. Install deepstream SDK

4.1 method 1: use Debian to install

  Downloaddeepstream-6.0_6.0.0-1_amd64.debDebian package, download and transfer:https://developer.nvidia.com/…

Execute the following command to install:

sudo apt-get install ./deepstream-6.0_6.0.0-1_amd64.deb

4.2 method 2: install with source code

  download the deepstream source code package, download and transfer:https://developer.nvidia.com/…

Unzip the package and compile and install it:

sudo tar -xvf deepstream_sdk_v6.0.0_x86_64.tbz2 -C /
cd /opt/nvidia/deepstream/deepstream-6.0/
sudo ./install.sh
sudo ldconfig

4.3 method 3: install with docker

This is the simplest:

docker pull nvcr.io/nvidia/deepstream:6.0-samples

5. Verify that the installation was successful

which deepstream-app

It is generally successful to locate deepstream app. Then you can use deepstream app to execute some samples. The basic commands are as follows:

deepstream-app -c <path_to_config_file>

The above shares the experience of installing deepstream6.0 on Ubuntu 0 method, I hope my sharing will be a little helpful to you.

Saturday, 29 January 2022

Ubuntu18 cannot play h264 video using Videos?

sudo apt install x264 x265 libx264-dev libx265-dev 

sudo apt-get install ubuntu-restricted-extras

sudo apt-get install libavcodec54 libav-tools ffmpeg

Tuesday, 25 January 2022

How to use the rotatedRect in opencv c++?

#include <iostream>
#include <opencv2/core/core.hpp>
#include <opencv2/imgproc/imgproc.hpp>
#include <opencv2/highgui/highgui.hpp>

int main(int argc, char* argv){

    cv::Mat src = cv::imread("../tony.jpg");
    // rect is the RotatedRect (I got it from a contour...)
    cv::RotatedRect rect(cv::Point2f(453, 127), cv::Size(230,140), 45);
        // matrices we'll use
    cv::Mat M, rotated, cropped;
        // get angle and size from the bounding box
        float angle = rect.angle;
    cv::Size rect_size = rect.size;
        if (rect.angle < -45.) {
            angle += 90.0;
        cv::swap(rect_size.width, rect_size.height);
        }
        // get the rotation matrix
        M = cv::getRotationMatrix2D(rect.center, angle, 1.0);
        // perform the affine transformation
    cv::warpAffine(src, rotated, M, src.size(), cv::INTER_CUBIC);
        // crop the resulting image
    cv::getRectSubPix(rotated, rect_size, rect.center, cropped);

    cv::imshow("cropped", cropped);
    cv::waitKey(0);
    return 0;

}

ref: https://gist.github.com/steven2358/ba153c642fe2bb1e47485962df07c730
https://ffmpeg.org/ffmpeg-all.html#Video-Options

FFmpeg cheat sheet

A list of useful commands for the ffmpeg command line tool.

Download FFmpeg: https://www.ffmpeg.org/download.html

Full documentation: https://www.ffmpeg.org/ffmpeg.html

Basic conversion

ffmpeg -i in.mp4 out.avi

Remux an MKV file into MP4

ffmpeg -i in.mkv -c:v copy -c:a copy out.mp4

High-quality encoding

Use the crf (Constant Rate Factor) parameter to control the output quality. The lower crf, the higher the quality (range: 0-51). The default value is 23, and visually lossless compression corresponds to -crf 18. Use the preset parameter to control the speed of the compression process. Additional info: https://trac.ffmpeg.org/wiki/Encode/H.264

ffmpeg -i in.mp4 -preset slower -crf 18 out.mp4

Trimming

Without re-encoding:

ffmpeg -ss [start] -i in.mp4 -t [duration] -c copy out.mp4
  • -ss specifies the start time, e.g. 00:01:23.000 or 83 (in seconds)
  • -t specifies the duration of the clip (same format).
  • Recent ffmpeg also has a flag to supply the end time with -to.
  • -c copy copies the first video, audio, and subtitle bitstream from the input to the output file without re-encoding them. This won't harm the quality and make the command run within seconds.

With re-encoding:

If you leave out the -c copy option, ffmpeg will automatically re-encode the output video and audio according to the format you chose. For high quality video and audio, read the x264 Encoding Guide and the AAC Encoding Guide, respectively.

For example:

ffmpeg -ss [start] -i in.mp4 -t [duration] -c:v libx264 -c:a aac -strict experimental -b:a 128k out.mp4

Mux video and audio from another video

To copy the video from in0.mp4 and audio from in1.mp4:

ffmpeg -i in0.mp4 -i in1.mp4 -c copy -map 0:0 -map 1:1 -shortest out.mp4

Concat demuxer

First, make a text file.

file 'in1.mp4'
file 'in2.mp4'
file 'in3.mp4'
file 'in4.mp4'

Then, run ffmpeg:

ffmpeg -f concat -i list.txt -c copy out.mp4

Delay audio/video

Delay video by 3.84 seconds:

ffmpeg -i in.mp4 -itsoffset 3.84 -i in.mp4 -map 1:v -map 0:a -vcodec copy -acodec copy out.mp4

Delay audio by 3.84 seconds:

ffmpeg -i in.mp4 -itsoffset 3.84 -i in.mp4 -map 0:v -map 1:a -vcodec copy -acodec copy out.mp4

Burn subtitles

Use the libass library (make sure your ffmpeg install has the library in the configuration --enable-libass).

First convert the subtitles to .ass format:

ffmpeg -i sub.srt sub.ass

Then add them using a video filter:

ffmpeg -i in.mp4 -vf ass=sub.ass out.mp4

Extract the frames from a video

To extract all frames from between 1 and 5 seconds, and also between 11 and 15 seconds:

ffmpeg -i in.mp4 -vf select='between(t,1,5)+between(t,11,15)' -vsync 0 out%d.png

To extract one frame per second only:

ffmpeg -i in.mp4 -fps=1 -vsync 0 out%d.png

Rotate a video

Rotate 90 clockwise:

ffmpeg -i in.mov -vf "transpose=1" out.mov

For the transpose parameter you can pass:

0 = 90CounterCLockwise and Vertical Flip (default)
1 = 90Clockwise
2 = 90CounterClockwise
3 = 90Clockwise and Vertical Flip

Use -vf "transpose=2,transpose=2" for 180 degrees.

Download "Transport Stream" video streams

  1. Locate the playlist file, e.g. using Chrome > F12 > Network > Filter: m3u8
  2. Download and concatenate the video fragments:
ffmpeg -i "path_to_playlist.m3u8" -c copy -bsf:a aac_adtstoasc out.mp4

If you get a "Protocol 'https not on whitelist 'file,crypto'!" error, add the protocol_whitelist option:

ffmpeg -protocol_whitelist "file,http,https,tcp,tls" -i "path_to_playlist.m3u8" -c copy -bsf:a aac_adtstoasc out.mp4

Mute some of the audio

To replace the first 90 seconds of audio with silence:

ffmpeg -i in.mp4 -vcodec copy -af "volume=enable='lte(t,90)':volume=0" out.mp4

To replace all audio between 1'20" and 1'30" with silence:

ffmpeg -i in.mp4 -vcodec copy -af "volume=enable='between(t,80,90)':volume=0" out.mp4

Deinterlace

Deinterlacing using "yet another deinterlacing filter".

ffmpeg -i in.mp4 -vf yadif out.mp4

Create a video slideshow from images

Parameters: -r marks the image framerate (inverse time of each image); -vf fps=25 marks the true framerate of the output.

ffmpeg -r 1/5 -i img%03d.png -c:v libx264 -vf fps=25 -pix_fmt yuv420p out.mp4

Extract images from a video

  • Extract all frames: ffmpeg -i input.mp4 thumb%04d.jpg -hide_banner
  • Extract a frame each second: ffmpeg -i input.mp4 -vf fps=1 thumb%04d.jpg -hide_banner
  • Extract only one frame: ffmpeg -i input.mp4 -ss 00:00:10.000 -vframes 1 thumb.jpg

Metadata: Change the title

ffmpeg -i in.mp4 -map_metadata -1 -metadata title="My Title" -c:v copy -c:a copy out.mp4

Wednesday, 19 January 2022

How to make a simple OpenCV C++ program CMakeLists.txt?

cmake_minimum_required(VERSION 3.10)
project(main)
set(CMAKE_PREFIX_PATH /data/opencv-4.4.0/distribute/)
find_package(OpenCV REQUIRED)
include_directories(/data/opencv-4.4.0/distribute/include)
link_directories(/data/opencv-4.4.0/distribute/lib)
add_executable(main main.cpp)
target_link_libraries(main opencv_core opencv_imgproc opencv_highgui opencv_videoio)