Sunday, 20 February 2022

How to mount the new drive automatically in ubuntu?

# /media/pensees was on /dev/sda1 during installation
UUID=960494c1-90c9-482a-8a9e-4a793d5e9ee2 /media/data  ext4    defaults        0       2

---

How to get the UUID?

sudo blkid

Monday, 14 February 2022

How to do the resizing / letterbox by keeping the aspect ratio?

 def letterbox(img, new_shape=(640, 640), color=(0, 0, 0)):
    # Resize and pad image while meeting stride-multiple constraints
    h,w = img.shape[:2]  # current shape [height, width]

    l = h if h > w else w

    scale = new_shape[0]/l

    h,w = np.array(img.shape[:2])*scale

    resized = cv2.resize(img,(int(w),int(h)))

    dh = max(new_shape[0]-resized.shape[0],0)
    dw = max(new_shape[1]-resized.shape[1],0)

    img = cv2.copyMakeBorder(resized, 0, dh, 0, dw, cv2.BORDER_CONSTANT, value=color)  # add border

    return img #, scale

Sunday, 13 February 2022

How to get list of files or images in a folder using OpenCV?

vector<cv::String> fn;
glob("/home/images/*.png", fn, false);

vector<Mat> images;
size_t count = fn.size(); //number of png files in images folder
for (size_t i=0; i<count; i++)
    images.push_back(imread(fn[i]));

 

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;

}