Tuesday, 14 June 2022

How to convert onnx to TRT without any precision loss?

 https://docs.nvidia.com/deeplearning/tensorrt/polygraphy/docs/index.html

Wednesday, 8 June 2022

Monday, 30 May 2022

CMakeLists.txt of OpenCV in GStreamer Docker 3090

apt install cmake

apt install qt5-default python-dev python3-dev -y

cd /data/opencv-4.4.0/build

cmake ..

make -j32

make install 


CMakeLists.txt:-

cmake -DCMAKE_BUILD_TYPE=RELEASE \
        -DCMAKE_INSTALL_PREFIX=/data/opencv-4.4.0/distribute \
        -DINSTALL_C_EXAMPLES=ON \
        -DOPENCV_GENERATE_PKGCONFIG=ON \
        -DINSTALL_PYTHON_EXAMPLES=ON \
        -DBUILD_SHARED_LIBS=ON \
        -DWITH_TBB=ON \
        -DWITH_V4L=ON \
        -DBUILD_opencv_world=OFF \
        -DOPENCV_PYTHON3_INSTALL_PATH=/data/opencv-4.4.0/distribute/python3 \
        -DWITH_QT=ON \
        -DWITH_OPENGL=ON \
        -DWITH_FFMPEG=ON \
        -DHAVE_FFMPEG=OFF \
        -DWITH_CUDA=ON \
        -DHAVE_CUDNN=ON \
        -DCUDNN_INCLUDE_DIRS=/data/cuda/include \
        -DCUDNN_LIBRARY=/usr/lib/x86_64-linux-gnu/libcudnn.so.8.0.4 \
        -DWITH_CUFFT=ON \
        -DWITH_CUBLAS=ON \
        -DWITH_NVCUVID=OFF \
        -DHAVE_NVCUVID=OFF\
        -DWITH_NVCUVENC=ON \
        -DHAVE_NVCUVENC=ON \
        -DBUILD_CUDA_STUBS=ON \
        -DBUILD_opencv_cudalegacy=ON \
        -DBUILD_opencv_cudacodec=ON \
        -DCUDA_FAST_MATH=ON \
        -DCUDA_ARCH_BIN="8.6" \
        -DCUDA_TOOLKIT_ROOT_DIR="/usr/local/cuda-11.1" \
        -DOPENCV_EXTRA_MODULES_PATH="/data/opencv_contrib-4.4.0/modules" \
        -DBUILD_NEW_PYTHON_SUPPORT=ON \
        -DBUILD_opencv_python3=ON \
        -DHAVE_opencv_python3=ON \
        -DPYTHON3_EXECUTABLE=/usr/bin/python3 \
        -DPYTHON3_DEFAULT_EXECUTABLE=/usr/bin/python3 \
        -DPYTHON3_INCLUDE_PATH=/usr/include/python3.6 \
        -DPYTHON3_NUMPY_INCLUDE_DIRS=/usr/lib/x86_64-linux-gnu/python3.6/site-packages/numpy/core/include \
        -DPYTHON3_PACKAGES_PATH=/usr/lib/x86_64-linux-gnu/python3.6/site-packages \
        -DPYTHON3_LIBRARIES=/usr/lib/x86_64-linux-gnu/libpython3.6.so \
        -DPYTHON3_LIBRARIES_PATH=/usr/lib/x86_64-linux-gnu \
    -D OpenGL_GL_PREFERENCE=GLVND \
    -D BUILD_opencv_rgbd=OFF \
        -D WITH_QT=ON \
        -D WITH_OPENGL=ON \
        -D WITH_GTK_2_X=ON \
        -DBUILD_EXAMPLES=OFF ..

Wednesday, 27 April 2022

How to play sound or mp3 file in python?

#pip install pyaudio pydub

from pydub import AudioSegment
from pydub.playback import play

song = AudioSegment.from_mp3('speech_stranger.mp3')
play(song)

Monday, 25 April 2022

How to check the server status in ubuntu?

step: how to run it in a crontab?

10 * * * * /bin/bash /home/ninja/Documents/checkVAserverStatus.sh


code:-

---

import configparser
import socket
import json
import psutil
import subprocess
config = configparser.ConfigParser()
config.read("config.ini")
symServer = config['symphony']

data = {
"camera_name":"none",
"event_time":"none",
"event_type":"none",
"image_url":"none",
"video_url":"none",
"camera_id": symServer["camera_id"]
}

def check():
    ram_used = check_ram()
    hddfree_space = check_directory_size("/")
    gpuRun = check_vadocker()

    if not gpuRun:
        data['policy_id'] = symServer["gpu_policy_id"]
        status = sendEvent(data)

    if ram_used > 95:
        data['policy_id'] = symServer["ram_policy_id"]
        status = sendEvent(data)

    if hddfree_space < 10:
        data['policy_id'] = symServer["hddfull_policy_id"]
        status = sendEvent(data)

def check_ram():
    ram_used = psutil.virtual_memory().percent
    return ram_used

def check_directory_size(path):
    hdd = psutil.disk_usage(path)
    free_space = hdd.free / (2**30)
    return free_space

def check_vadocker():
    subprocess1 = subprocess.Popen('docker ps -a -q --filter ancestor=nvcr.io/nvidia/deepstream:6.0-triton --format="{{.ID}}"',shell=True,stdout=subprocess.PIPE)
    subprocess_return = subprocess1.stdout.read()
    if len(subprocess_return)>5:
        print("docker is running")
        return True
    else:
        print("docker is not running")
        return False

def sendEvent(data):
    try:
        strdata = json.dumps(data)
        print(data)

        # Send data
        sock = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
        server_address = (symServer["server_ip"], int(symServer["server_port"]))
        sock.connect(server_address)

        try:
            # Send data
            sock.sendall(strdata.encode())

            # Look for the response
            amount_received = 0
            amount_expected = 5
            while amount_received < amount_expected:
                data = sock.recv(100)
                amount_received += len(data)
            # print('alerting send')
            return True
        except Exception as e:
            # print("server_ip: ",e)
            return False
        finally:
            # print('-- closing socket')
            sock.close()
            return True
    except Exception as e:
        # print("server_ip: ",e)
        return False

if __name__=="__main__":
    check()

How to clean the data, image or video inside a folder in ubuntu periodically?

step: how to run it in a crontab?

0 0 * * * /usr/bin/python3 /home/ninja/Documents/cleaner.py

code:-

---

import os
import shutil
import time
from datetime import datetime,timedelta


days = 60

# main function
def main(path):

    # initializing the count
    deleted_folders_count = 0
    deleted_files_count = 0

    # specify the path
    #path = "/home/ninja/Desktop/old/"

    # converting days to seconds
    # time.time() returns current time in seconds
    seconds = time.time() - (days * 24 * 60 * 60)

    # checking whether the file is present in path or not
    if os.path.exists(path):
       
        # iterating over each and every folder and file in the path
        for root_folder, folders, files in os.walk(path):

            # comparing the days

                        # checking the current directory files
                        for file in files:

                                # file path
                                file_path = os.path.join(root_folder, file)

                                # comparing the days
                                if seconds >= get_file_or_folder_age(file_path):

                                        # invoking the remove_file function

                                        remove_file(file_path)
                                        deleted_files_count += 1 # incrementing count



    print(f"Total folders deleted: {deleted_folders_count}")
    print(f"Total files deleted: {deleted_files_count}")

    

def remove_folder(path):

    # removing the folder
    if not shutil.rmtree(path):

        # success message
        print(f"{path} is removed successfully")

    else:

        # failure message
        print(f"Unable to delete the {path}")


def remove_file(path):

    # removing the file
    if not os.remove(path):

        # success message
        print(f"{path} is removed successfully")

    else:

        # failure message
        print(f"Unable to delete the {path}")


def get_file_or_folder_age(path):

    # getting ctime of the file/folder
    # time will be in seconds
    ctime = os.stat(path).st_ctime

    # returning the time
    return ctime



if __name__ == '__main__':

    main("/media/ninja/output/videos/")

    #main("/media/ninja/output/VA_logs/")

How to backup the disk from one drive to another drive in ubuntu?

step: how to run it in a crontab?

3 0 * * * /bin/bash /home/peseyes/Documents/main_rsync.sh


code:-

rsync -avzh --delete /media/ninja/output/ /media/ninja/backup