串流相關知識

RTP/RTCP

跟TCP和UDP一樣為傳輸層協議
規範RFC3350
RTCP (RTP Control Protocol)專門用來處理服務品質(Qos)
RTP可以選擇用UDP或是TCP來進行傳輸

https://mark-lin.com/posts/20180912/(主要)
http://albert-oma.blogspot.com/2012/05/rtp.html

bps(bit Per Second)

位元率 (bps) = 採樣率(hz) x 採樣大小(bit) x 通道

編碼

將raw檔轉換壓縮

聲音編碼

例如MP3和AAC

色彩顏色編碼RGB與YUV

影像編碼H26X和VPX

主流有H264和VP8

封裝

將聲音和影像編碼後的結果放進容器的過程

容器

用來盛裝編碼,一種編碼可以放進各種容器,例如MP3編碼可以放進.mp3、.mp4、.avi容器裡面

網路協議

https://www.jianshu.com/p/9f3e879a4c9c

DTS和PTS

https://blog.csdn.net/aggie4628/article/details/130440133

2024-01-20-Elasticsearch-客製化搜尋條件

Painless Script

https://www.elastic.co/guide/en/elasticsearch/painless/current/painless-walkthrough.html

只選擇夜間的資料

https://stackoverflow.com/a/35596907

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
{
"query": {
"bool": {
"filter": [
{
"range": {
"OccurrenceTime": {
"gte": "2023-12-01",
"lt": "2024-01-20"
}
}
},
{
"script": {
"script": "doc.OccurrenceTime.value.hour >= 10 && doc.OccurrenceTime.value.hour <= 21"
}
}
]
}
}
}

2024-01-23-CMake編譯OpenCV-Python

Here is the minimal steps.
Here is my enviornment

  • Windows 10
  • Visual Studio Build Tools 2019
  • CMake 3.29.0-rc1 (use default install setting)
  • Gstreamer:(Use default install setting)
    MSVC 64-bit (VS 2019, Release CRT)
    1.22.10 runtime installer
    1.22.10 development installer
  • Python3.8.10

For example, my gstreamer is install in D disk by default.

  1. Add System Environment Variable GSTREAMER_ROOT_X86_64 value D:\gstreamer\1.0\msvc_x86_64
    gstreamer doc
  2. Add enviornment variable GST_PLUGIN_PATH value D:\gstreamer\1.0\msvc_x86_64\lib\gstreamer-1.0
  3. Add Path enviornment variable value D:\gstreamer\1.0\msvc_x86_64\bin
  4. re-login the computer
  5. create a Python venv and use it
  6. pip install --verbose --no-binary opencv-python opencv-python
  7. os.add_dll_directory() Shoud be add to code since from Python 3.8+, Python will NOT search DLL from PATH enviornment variable.ref
  8. test code
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
import os
os.add_dll_directory("D:\\gstreamer\\1.0\\msvc_x86_64\\bin")
import cv2
gst = 'rtspsrc location=rtsp://192.168.8.57/live1s3.sdp timeout= 30000 ! decodebin ! videoconvert ! video/x-raw,format=BGR ! appsink drop=1'

cap = cv2.VideoCapture(gst,cv2.CAP_GSTREAMER)
while(cap.isOpened()):
ret, frame = cap.read()
if not ret:
break
cv2.imshow('frame', frame)
if cv2.waitKey(1) & 0xFF == ord('q'):
break

cv2.destroyAllWindows()
cap.release()

步驟

<gstreamer資料夾>\1.0\msvc_x86_64

  • 直接安裝source distributions版本的opencv-python(opencv 4.3.0之後的版本)
    pip install --verbose --no-binary opencv-python opencv-python

GST_PLUGIN_PATH或是GST_PLUGIN_SYSTEM_PATH(不一定要加)

gstreamer預設尋找plugin的順序如下

  1. %HOMEDRIVE%%HOMEFOLDER%/.gstreamer-1.0/plugins
  2. C:\gstreamer\1.0\x86\lib\gstreamer-1.0
  3. ..\lib\gstreamer-1.0
  4. %GST_PLUGIN_PATH%
    <gstreamer資料夾>\1.0\msvc_x86_64\lib\gstreamer-1.0

gstreamer doc

Path變數

<gstreamer資料夾>\1.0\msvc_x86_64\bin

載入時手動加入dll路徑

os.add_dll_directory()
ref

測試

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
import os
os.add_dll_directory("D:\\gstreamer\\1.0\\msvc_x86_64\\bin")
import cv2
gst = 'rtspsrc location=rtsp://192.168.8.57/live1s3.sdp timeout= 30000 ! decodebin ! videoconvert ! video/x-raw,format=BGR ! appsink drop=1'

cap = cv2.VideoCapture(gst,cv2.CAP_GSTREAMER)
while(cap.isOpened()):
ret, frame = cap.read()
if not ret:
break
cv2.imshow('frame', frame)
if cv2.waitKey(1) & 0xFF == ord('q'):
break

cv2.destroyAllWindows()
cap.release()

gstreamer載入時錯誤檢查

  1. Dependencies 軟體檢查dll缺少哪一些東西
    1. 下載後免安裝直接打開DependenciesGui.exe,打開venv\Lib\site-packages\cv2\cv2.pyd
  2. plugin找不到的錯誤可能是找不到plugin的dll本身,或是找不到plugin所需要的dll

安裝CUDA

CUDA 設定

從4.0之後CUDA相關的功能被移到opencv_contrib,必須要編一opencv_contrib才能啟用CUDA功能

  1. set CMAKE_ARGS="-DWITH_CUDA=ON"
  2. pip install –verbose –no-binary opencv-contrib-python opencv-contrib-python

(選擇性)G-API

G-API說明
https://github.com/opencv/opencv/wiki/Graph-API

c程式找不到函示庫 ld錯誤 函示庫各種雜症

signal SIGSEGV: address not mapped to object (fault address: 0x20)

static function不需要被呼叫就有可能發生錯誤

dlopen無法載入函示庫

https://stackoverflow.com/a/2991677/22299707

  1. ldd -r 列出所以找不到的函式庫像這樣

    1
    2
    3
    4
    5
    6
            linux-vdso.so.1 (0x00007ffcfd376000)
    libjson-glib-1.0.so.0 => /lib/x86_64-linux-gnu/libjson-glib-1.0.so.0 (0x00007f210d72c000)
    .....
    undefined symbol: descriptor_table_google_2fprotobuf_2ftimestamp_2eproto (./libnvds_msgconv.so)
    undefined symbol: _ZN6google8protobuf7Message17CopyWithSizeCheckEPS1_RKS1_ (./libnvds_msgconv.so)
    .....
  2. c++filt顯示函式庫名稱,還原函數名稱

    1
    c++filt _ZN6google8protobuf7Message17CopyWithSizeCheckEPS1_RKS1_

演算法練習筆記

  1. 注意題目裡的線索
    例如題目如果出現”寫一個在伺服器長時間重複運作的程式”,你可以想看看快取是不是可以派上用場

  2. 寫出測試範例
    要特別注意自己寫出來的範例是不是特例

  3. 嘗試暴力解

  4. 優化

Check Permutation: Given two strings, write a method to decide if one is a permutation of the other. p.90

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
def check_permutation(s1, s2):
if len(s1) != len(s2):
return False
sd1 = {}
for i in s1:
if sd1.get(i):
sd1[i] = sd1[i] + 1
else:
sd1[i] = 1
for j in s2:
if sd1.get(j):
if sd1.get(j) > 0:
sd1[i] = sd1[i] - 1
else:
return False
else:
return False
return True

samples

  • dad, bda
  • abc, bca
  • sss, sss
  • sas, ssa
  • abcd, abc
  • bbba, bbbb

URLify: Write a method to replace all spaces in a string with ‘%20’. You may assume that the string has sufficient space at the end to hold the additional characters, and that you are given the “true” length of the string. (Note: If implementing in Java, please use a character array so that you can perform this operation in place.)

  • 錯誤1:
    忘記回傳值

Palindrome Permutation: Given a string, write a function to check if it is a permutation of a palin-drome. A palindrome is a word or phrase that is the same forwards and backwards. A permutation is a rearrangement of letters. The palindrome does not need to be limited to just dictionary words.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
import copy

def palindrome(input):
input = input.lower()
char_dict = {}
for c in input:
if c != " ":
if char_dict.get(c):
char_dict.pop(c)
else:
char_dict[c] = 1
if len(char_dict) > 1:
return False
return True

錯誤1: 沒有考慮到大小寫問題

One Away: There are three types of edits that can be performed on strings: insert a character, remove a character, or replace a character. Given two strings, write a function to check if they are one edit (or zero edits) away.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
def one_edit(str_a, str_b):
if len(str_a) - len(str_b) == -1:
for c in str_a:
if c not in str_b:
return False
elif len(str_a) - len(str_b) == 1:
for c in str_b:
if c not in str_a:
return False
elif len(str_a) - len(str_b) == 0:
counter = 0
for c in str_a:
if c not in str_b:
counter +=1
if counter > 1:
return False
else:
return False
return True

systemd相關

移除服務

stop [servicename]
1
2
3
4
5
6
7
systemctl disable [servicename]
sudo trash /etc/systemd/system/[servicename]
sudo trash /etc/systemd/system/[servicename] # and symlinks that might be related
sudo trash /usr/lib/systemd/system/[servicename]
sudo trash /usr/lib/systemd/system/[servicename] # and symlinks that might be related
systemctl daemon-reload
systemctl reset-failedbash

https://superuser.com/a/936976

CMake疑難雜症

Failed to detect a default CUDA architecture或是CMAKE_CUDA_ARCHITECTURES must be non-empty if set

直接告訴CMake nvcc的位置,注意舊的build資料夾要先清掉
-DCMAKE_CUDA_COMPILER=/usr/local/cuda-11.7/bin/nvcc

https://www.cnblogs.com/metaz/p/16919028.html

VS code設定cmake的環境變數

在setting.json加入"cmake.environment": {"CUDA_VER":"11.7"},說明書:https://github.com/microsoft/vscode-cmake-tools/blob/main/docs/cmake-presets.md#ignored-settings

CMake presets: https://dominikberner.ch/cmake-presets-best-practices/

CMake 系統環境變數設置

https://www.scivision.dev/cmake-environment-variable-scope/

libcuda.so.1 not found

使用find_package(CUDAToolkit)並且在target_link_libraries 加入CUDA::cuda_driver

CMake find_package() 用法

CMake有許多尋找套件的module,例如FindCUDAToolkit,下面連結條列各種find_package()能使用的module

https://cmake.org/cmake/help/latest/manual/cmake-modules.7.html#manual:cmake-modules(7)